@@ -0,0 +1,52 @@
|
||||
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,
|
||||
)
|
||||
Reference in New Issue
Block a user