Files
VacatureRadar/tests/unit/test_settings_security.py
T
Jens a4eced8be5
deploy / deploy (push) Canceled after 0s
Fix release blockers and deployment build
2026-07-21 21:22:29 +02:00

60 lines
2.0 KiB
Python

from __future__ import annotations
import pytest
from django.core.exceptions import ImproperlyConfigured
from config.settings import _validate_production_security
def test_validate_production_security_skips_when_debug_mode_is_enabled():
_validate_production_security(
debug=True,
secret_key="dev-only-change-me",
allowed_hosts=[],
csrf_trusted_origins=[],
session_cookie_secure=False,
csrf_cookie_secure=False,
secure_ssl_redirect=False,
)
@pytest.mark.parametrize(
(
"secret_key",
"allowed_hosts",
"csrf_trusted_origins",
"session_cookie_secure",
"csrf_cookie_secure",
"secure_ssl_redirect",
),
[
("", ["example.org"], ["https://example.org"], True, True, True),
("change-me", ["example.org"], ["https://example.org"], True, True, True),
("too-short", ["example.org"], ["https://example.org"], True, True, True),
("a" * 64, [], ["https://example.org"], True, True, True),
("a" * 64, ["example.org"], [], True, True, True),
("a" * 64, ["example.org"], ["http://example.org"], True, True, True),
("a" * 64, ["example.org"], ["https://example.org"], False, True, True),
("a" * 64, ["example.org"], ["https://example.org"], True, False, True),
("a" * 64, ["example.org"], ["https://example.org"], True, True, False),
],
)
def test_validate_production_security_requires_secure_settings_for_prod(
secret_key,
allowed_hosts,
csrf_trusted_origins,
session_cookie_secure,
csrf_cookie_secure,
secure_ssl_redirect,
):
with pytest.raises(ImproperlyConfigured):
_validate_production_security(
debug=False,
secret_key=secret_key,
allowed_hosts=allowed_hosts,
csrf_trusted_origins=csrf_trusted_origins,
session_cookie_secure=session_cookie_secure,
csrf_cookie_secure=csrf_cookie_secure,
secure_ssl_redirect=secure_ssl_redirect,
)