aboutsummaryrefslogtreecommitdiff
path: root/tests/test_url_security.py
diff options
context:
space:
mode:
authorDennis Fink2026-08-21 10:37:56 +0200
committerDennis Fink2026-08-21 10:37:56 +0200
commitc5492398f100ccb154fa557d657bae2322f95cf7 (patch)
tree21efa67e00c26ab0733a931e6a5810b4c933388b /tests/test_url_security.py
parent5bfcc3c06ebe6d6694221c25f07a4901572f97f5 (diff)
downloadwebmentions-ssg-c5492398f100ccb154fa557d657bae2322f95cf7.tar.gz
webmentions-ssg-c5492398f100ccb154fa557d657bae2322f95cf7.zip
test(core): align tests with module ownership
Move direct validator, model, and Huey extension coverage into dedicated test modules and mock dependencies where behavior belongs to another module. Expand Huey extension typing and coverage while removing duplicate assertions from scanner, sender, form, and view tests.
Diffstat (limited to '')
-rw-r--r--tests/test_url_security.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/tests/test_url_security.py b/tests/test_url_security.py
index db513f9..dee38dd 100644
--- a/tests/test_url_security.py
+++ b/tests/test_url_security.py
@@ -14,6 +14,27 @@ from webmentions_ssg.url_security import (
)
+@pytest.mark.parametrize(
+ ("url", "expected"),
+ [
+ pytest.param("http://example.com/", True, id="http"),
+ pytest.param("https://example.com/path", True, id="https"),
+ pytest.param("HTTP://EXAMPLE.COM/", True, id="scheme-case-insensitive"),
+ pytest.param("https://example.com:8443/path", True, id="port"),
+ pytest.param("http://[2001:db8::1]/", True, id="ipv6"),
+ pytest.param("ftp://example.com/", False, id="ftp"),
+ pytest.param("mailto:example@example.com", False, id="mailto"),
+ pytest.param("/relative/url", False, id="relative"),
+ pytest.param("//example.com/path", False, id="scheme-relative"),
+ pytest.param("https:///missing-host", False, id="missing-host"),
+ pytest.param("", False, id="empty"),
+ pytest.param("http://[::1", False, id="malformed"),
+ ],
+)
+def test_is_http_url(url: str, expected: bool) -> None:
+ assert is_http_url(url) is expected
+
+
@patch("webmentions_ssg.url_security.dns.resolver.resolve_name")
@pytest.mark.parametrize(
("url", "resolved_addresses"),
@@ -34,7 +55,6 @@ def test_is_public_url_returns_false_for_non_public_addresses(
resolve_name: Mock, url: str, resolved_addresses: list[str]
) -> None:
resolve_name.return_value.addresses.return_value = resolved_addresses
-
assert not is_public_url(url)
@@ -53,7 +73,6 @@ def test_is_public_url_returns_true_for_public_addresses(
resolve_name: Mock, url: str, resolved_addresses: list[str]
) -> None:
resolve_name.return_value.addresses.return_value = resolved_addresses
-
assert is_public_url(url)
@@ -64,7 +83,6 @@ def test_is_public_url_returns_true_for_public_addresses(
def test_is_public_url_raises_for_resolution_failure(resolve_name: Mock) -> None:
with pytest.raises(AddressResolutionError, match="Could not resolve hostname"):
is_public_url("https://nonexistent.example/")
-
resolve_name.assert_called_once_with("nonexistent.example")
@@ -72,9 +90,4 @@ def test_is_public_url_raises_for_resolution_failure(resolve_name: Mock) -> None
def test_is_public_url_raises_when_url_has_no_hostname(resolve_name: Mock) -> None:
with pytest.raises(ValueError, match="No hostname was specified"):
is_public_url("/relative/url")
-
resolve_name.assert_not_called()
-
-
-def test_is_http_url_rejects_malformed_url() -> None:
- assert not is_http_url("http://[::1")