diff options
| author | Dennis Fink | 2026-10-30 08:35:46 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-10-30 08:41:42 +0100 |
| commit | 4485aeb573ceb37237ea1fbc80665ed6c4136116 (patch) | |
| tree | bce18a2c7fadd657d9f9809ebbc65d06c6cc4dc4 /tests/test_config.py | |
| parent | 9f093cf07a3531ee4b7d02c20151e21c141a93de (diff) | |
| download | webmentions-ssg-4485aeb573ceb37237ea1fbc80665ed6c4136116.tar.gz webmentions-ssg-4485aeb573ceb37237ea1fbc80665ed6c4136116.zip | |
fix(core): harden application configuration
Fail production startup when required configuration is missing,
normalize allowed hostnames before validation, and move shared request
limits into the default configuration so production does not depend on
testing-only values.
Set secure session cookie defaults while preserving explicit overrides
and document the new rate-limit and notification settings in the example
config.
Diffstat (limited to 'tests/test_config.py')
| -rw-r--r-- | tests/test_config.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..8d5aa5b --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,45 @@ +# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me> +# +# SPDX-License-Identifier: BSD-3-Clause + +"""Test built-in session cookie defaults and explicit overrides.""" + +import pytest + +from webmentions_ssg import create_app +from webmentions_ssg.config import ( + DefaultConfig, + DevelopmentConfig, + ProductionConfig, + TestingConfig, +) + + +@pytest.mark.parametrize( + ("config_class", "expected_secure"), + [ + (DefaultConfig, True), + (ProductionConfig, True), + (DevelopmentConfig, False), + (TestingConfig, False), + ], +) +def test_session_cookie_defaults( + config_class: type[DefaultConfig], expected_secure: bool +) -> None: + assert config_class.SESSION_COOKIE_SECURE is expected_secure + assert config_class.SESSION_COOKIE_HTTPONLY is True + assert config_class.SESSION_COOKIE_SAMESITE == "Lax" + + +def test_explicit_config_overrides_session_cookie_defaults() -> None: + class CookieOverrideConfig(TestingConfig): + SESSION_COOKIE_SECURE = True + SESSION_COOKIE_HTTPONLY = False + SESSION_COOKIE_SAMESITE = "Strict" + + app = create_app(CookieOverrideConfig) + + assert app.config["SESSION_COOKIE_SECURE"] is True + assert app.config["SESSION_COOKIE_HTTPONLY"] is False + assert app.config["SESSION_COOKIE_SAMESITE"] == "Strict" |
