aboutsummaryrefslogtreecommitdiff
path: root/tests/test_config.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-17 14:44:00 +0100
committerDennis Fink2026-11-17 14:44:00 +0100
commit227092b57acc886469e16bcc4c0d3256e86d3d1e (patch)
treec1de8d5f8f3a37562e482f84e8017213c08a05d6 /tests/test_config.py
parentf98b0e446b41325c494bd97900b7bbf730a7d67e (diff)
downloadwebmentions-ssg-227092b57acc886469e16bcc4c0d3256e86d3d1e.tar.gz
webmentions-ssg-227092b57acc886469e16bcc4c0d3256e86d3d1e.zip
feat(receiver): add source domain access rules
Add persistent source block and allow lists with authenticated management, single-row and bulk blocking actions, and optional fail-closed allowlist mode. Reject disallowed sources before enqueueing and recheck policy in verification workers, while sharing canonical hostname normalization across receiver, sender, and configuration paths.
Diffstat (limited to '')
-rw-r--r--tests/test_config.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index d075e7d..4a5f4cb 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -39,6 +39,15 @@ def test_session_cookie_defaults(
assert config_class.SESSION_COOKIE_SAMESITE == "Lax"
+def test_source_allowlist_mode_requires_boolean_configuration(tmp_path: Path) -> None:
+ class BadSourceModeConfig(TestingConfig):
+ LOG_FILE = str(tmp_path / "mode-test.log")
+ SOURCE_ALLOWLIST_ENABLED = "yes"
+
+ with pytest.raises(ValueError, match="SOURCE_ALLOWLIST_ENABLED"):
+ create_app(BadSourceModeConfig)
+
+
def test_explicit_config_overrides_session_cookie_defaults() -> None:
class CookieOverrideConfig(TestingConfig):
SESSION_COOKIE_SECURE = True
@@ -141,6 +150,7 @@ def test_allowed_hostnames_are_normalized_at_startup(tmp_path: Path) -> None:
(["example.com", None], ValueError),
(["example.com", ""], ValueError),
(["example.com", " "], ValueError),
+ (["*.example.com"], ValueError),
],
)
def test_invalid_allowed_hostnames_fail_at_startup(
@@ -154,6 +164,23 @@ def test_invalid_allowed_hostnames_fail_at_startup(
create_app(InvalidHostnameConfig)
+def test_hostname_config_shares_admin_canonicalization(tmp_path: Path) -> None:
+ class InternationalizedHosts(TestingConfig):
+ LOG_FILE = str(tmp_path / "idn.log")
+ ALLOWED_TARGET_HOSTNAMES = {"BÜCHER.example.", "EXAMPLE.COM"}
+ IGNORED_TARGET_HOSTNAMES = {"*.BÜCHER.example.", "EXAMPLE.COM."}
+
+ app = create_app(InternationalizedHosts)
+ assert app.config["ALLOWED_TARGET_HOSTNAMES"] == {
+ "xn--bcher-kva.example",
+ "example.com",
+ }
+ assert app.config["IGNORED_TARGET_HOSTNAMES"] == {
+ "*.xn--bcher-kva.example",
+ "example.com",
+ }
+
+
def test_ignored_hostnames_are_normalized_at_startup(tmp_path: Path) -> None:
class MixedCaseConfig(TestingConfig):
LOG_FILE = str(tmp_path / "test.log")