diff options
| author | Dennis Fink | 2026-11-19 21:18:37 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-19 21:18:37 +0100 |
| commit | eb11fb64e9cad6fbda2065362189653416d98577 (patch) | |
| tree | 0bc5737b1c273ea6f04adc015154565c385dc719 /tests/tasks/test_source_parser.py | |
| parent | 88f54d9a7699944b7d56f978e724b1c0b54dde98 (diff) | |
| download | webmentions-ssg-eb11fb64e9cad6fbda2065362189653416d98577.tar.gz webmentions-ssg-eb11fb64e9cad6fbda2065362189653416d98577.zip | |
test: expand failure and migration coverage
Add regression coverage for malformed input, lost task claims,
moderation races, network failures, serializer validation, and
production configuration guards.
Exercise migration downgrade, backfill, and autogeneration paths plus
additional receiver and sender edge cases.
Diffstat (limited to 'tests/tasks/test_source_parser.py')
| -rw-r--r-- | tests/tasks/test_source_parser.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/tasks/test_source_parser.py b/tests/tasks/test_source_parser.py index 38752b0..38a5dc1 100644 --- a/tests/tasks/test_source_parser.py +++ b/tests/tasks/test_source_parser.py @@ -1014,3 +1014,44 @@ def test_normalize_target_url_ignores_url_rejected_by_validator( ) is None ) + + +def test_outgoing_targets_skip_urls_with_unparseable_hostname( + source_parser_module: ModuleType, monkeypatch: MonkeyPatch +) -> None: + document = parse_html( + '<div><a href="https://bad.example/post">bad</a>' + '<a href="https://good.example/post">good</a></div>' + ) + content = document.find("div") + assert content is not None + original = source_parser_module.normalize_hostname + + def invalid_hostname(url: str, *, from_url: bool = False) -> str: + if "bad.example" in url: + raise ValueError("Malformed URL hostname") + return original(url, from_url=from_url) + + monkeypatch.setattr(source_parser_module, "normalize_hostname", invalid_hostname) + assert list( + source_parser_module.iter_outgoing_targets( + content, + {}, + base_url=SOURCE_URL, + source_url=SOURCE_URL, + ) + ) == ["https://good.example/post"] + + +def test_stable_content_text_excludes_hidden_markup( + source_parser_module: ModuleType, +) -> None: + document = parse_html( + "<div>Hello<script>secret-script</script>" + "<style>secret-style</style><template>secret-template</template>world</div>" + ) + content = document.find("div") + assert content is not None + normalized = source_parser_module.stable_content_text(content) + assert "Hello" in normalized and "world" in normalized + assert "secret-" not in normalized |
