Files
gh-christianlouis-inboxconv…/backend/tests/unit/test_config.py
T
copilot-swe-agent[bot] e64f0f2705 feat: Add security hardening, agentic coding infrastructure, and test framework
- Add SECRET_KEY and ENCRYPTION_KEY validation on startup
- Implement security headers middleware (X-Frame-Options, CSP, HSTS)
- Add CSRF protection middleware
- Create comprehensive GitHub issue templates and PR template
- Add Makefile with common development tasks
- Configure pre-commit hooks (black, ruff, mypy, bandit, detect-secrets)
- Create docs/CODING_PATTERNS.md with best practices
- Create docs/ERRORS.md documenting all error codes
- Add Architecture Decision Records (ADR) for Celery and Fernet encryption
- Create CHANGELOG.md for version tracking
- Set up pytest test infrastructure with fixtures and factories
- Add sample unit tests for security and config validation
- Create CI/CD workflows (test, lint, security)
- Add comprehensive TODO.md with milestones and progress tracking

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-06 22:01:11 +00:00

61 lines
2.3 KiB
Python

"""
Unit tests for configuration module.
"""
import pytest
from pydantic import ValidationError
from app.core.config import Settings
class TestConfigValidation:
"""Test configuration validation"""
def test_default_secret_key_rejected(self):
"""Test that default SECRET_KEY is rejected"""
with pytest.raises(ValidationError) as exc_info:
Settings(
SECRET_KEY="change-this-to-a-secure-random-secret-key-in-production",
ENCRYPTION_KEY="this-is-a-secure-32-character-key-for-testing",
)
assert "SECRET_KEY must be changed from default" in str(exc_info.value)
def test_short_secret_key_rejected(self):
"""Test that short SECRET_KEY is rejected"""
with pytest.raises(ValidationError) as exc_info:
Settings(
SECRET_KEY="short",
ENCRYPTION_KEY="this-is-a-secure-32-character-key-for-testing",
)
assert "at least 32 characters" in str(exc_info.value)
def test_default_encryption_key_rejected(self):
"""Test that default ENCRYPTION_KEY is rejected"""
with pytest.raises(ValidationError) as exc_info:
Settings(
SECRET_KEY="this-is-a-secure-32-character-key-for-testing",
ENCRYPTION_KEY="change-this-to-a-secure-encryption-key",
)
assert "ENCRYPTION_KEY must be changed from default" in str(exc_info.value)
def test_short_encryption_key_rejected(self):
"""Test that short ENCRYPTION_KEY is rejected"""
with pytest.raises(ValidationError) as exc_info:
Settings(
SECRET_KEY="this-is-a-secure-32-character-key-for-testing",
ENCRYPTION_KEY="short",
)
assert "at least 32 characters" in str(exc_info.value)
def test_valid_keys_accepted(self):
"""Test that valid keys are accepted"""
settings = Settings(
SECRET_KEY="this-is-a-secure-32-character-key-for-testing-secret",
ENCRYPTION_KEY="this-is-a-secure-32-character-key-for-encryption",
)
assert settings.SECRET_KEY == "this-is-a-secure-32-character-key-for-testing-secret"
assert settings.ENCRYPTION_KEY == "this-is-a-secure-32-character-key-for-encryption"