chore: remove placeholder update message from repository root
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
import ipaddress
|
||||
import pytest
|
||||
from devplacepy import net_guard
|
||||
from devplacepy.net_guard import BlockedAddressError
|
||||
from tests.conftest import run_async
|
||||
|
||||
|
||||
def test_loopback_is_blocked():
|
||||
assert net_guard.is_blocked_address(ipaddress.ip_address("127.0.0.1"))
|
||||
|
||||
|
||||
def test_private_ranges_are_blocked():
|
||||
assert net_guard.is_blocked_address(ipaddress.ip_address("10.0.0.1"))
|
||||
assert net_guard.is_blocked_address(ipaddress.ip_address("192.168.1.1"))
|
||||
assert net_guard.is_blocked_address(ipaddress.ip_address("172.16.0.1"))
|
||||
|
||||
|
||||
def test_link_local_and_unspecified_blocked():
|
||||
assert net_guard.is_blocked_address(ipaddress.ip_address("169.254.1.1"))
|
||||
assert net_guard.is_blocked_address(ipaddress.ip_address("0.0.0.0"))
|
||||
|
||||
|
||||
def test_public_address_allowed():
|
||||
assert not net_guard.is_blocked_address(ipaddress.ip_address("1.1.1.1"))
|
||||
assert not net_guard.is_blocked_address(ipaddress.ip_address("8.8.8.8"))
|
||||
|
||||
|
||||
def test_ipv4_mapped_ipv6_unwrapped_and_blocked():
|
||||
mapped = ipaddress.ip_address("::ffff:127.0.0.1")
|
||||
assert isinstance(net_guard.effective_address(mapped), ipaddress.IPv4Address)
|
||||
assert net_guard.is_blocked_address(mapped)
|
||||
|
||||
|
||||
def test_nat64_prefix_unwrapped_to_ipv4():
|
||||
nat64 = ipaddress.ip_address("64:ff9b::7f00:1")
|
||||
resolved = net_guard.effective_address(nat64)
|
||||
assert isinstance(resolved, ipaddress.IPv4Address)
|
||||
assert net_guard.is_blocked_address(nat64)
|
||||
|
||||
|
||||
def test_guard_rejects_non_http_scheme():
|
||||
with pytest.raises(BlockedAddressError):
|
||||
run_async(net_guard.guard_public_url("ftp://example.com/x"))
|
||||
with pytest.raises(BlockedAddressError):
|
||||
run_async(net_guard.guard_public_url("file:///etc/passwd"))
|
||||
|
||||
|
||||
def test_guard_rejects_missing_host():
|
||||
with pytest.raises(BlockedAddressError):
|
||||
run_async(net_guard.guard_public_url("http://"))
|
||||
|
||||
|
||||
def test_guard_rejects_loopback_literal():
|
||||
with pytest.raises(BlockedAddressError):
|
||||
run_async(net_guard.guard_public_url("http://127.0.0.1:8080/admin"))
|
||||
|
||||
|
||||
def test_guard_rejects_private_literal():
|
||||
with pytest.raises(BlockedAddressError):
|
||||
run_async(net_guard.guard_public_url("http://10.0.0.5/internal"))
|
||||
|
||||
|
||||
def test_guard_allow_private_skips_resolution():
|
||||
host = run_async(
|
||||
net_guard.guard_public_url("http://127.0.0.1:9000/x", allow_private=True)
|
||||
)
|
||||
assert host == "127.0.0.1"
|
||||
@@ -0,0 +1,125 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from devplacepy.services.jobs.seo.checks import registry
|
||||
from devplacepy.services.jobs.seo.checks.base import (
|
||||
Check,
|
||||
PageContext,
|
||||
SiteContext,
|
||||
PASS,
|
||||
WARN,
|
||||
FAIL,
|
||||
INFO,
|
||||
SKIP,
|
||||
CRITICAL,
|
||||
HIGH,
|
||||
LOW,
|
||||
)
|
||||
|
||||
|
||||
def _check(status, severity, category="meta"):
|
||||
return Check(
|
||||
id=f"{category}.{status}",
|
||||
category=category,
|
||||
title="t",
|
||||
status=status,
|
||||
severity=severity,
|
||||
)
|
||||
|
||||
|
||||
def test_all_pass_scores_100_grade_a():
|
||||
checks = [_check(PASS, HIGH), _check(PASS, CRITICAL)]
|
||||
result = registry.compute_score(checks)
|
||||
assert result["score"] == 100
|
||||
assert result["grade"] == "A"
|
||||
|
||||
|
||||
def test_all_fail_scores_0_grade_f():
|
||||
checks = [_check(FAIL, HIGH), _check(FAIL, CRITICAL)]
|
||||
result = registry.compute_score(checks)
|
||||
assert result["score"] == 0
|
||||
assert result["grade"] == "F"
|
||||
|
||||
|
||||
def test_warn_gives_half_credit():
|
||||
result = registry.compute_score([_check(WARN, HIGH)])
|
||||
assert result["score"] == 50
|
||||
|
||||
|
||||
def test_info_and_skip_excluded_from_weight():
|
||||
checks = [_check(INFO, LOW), _check(SKIP, LOW), _check(PASS, HIGH)]
|
||||
result = registry.compute_score(checks)
|
||||
assert result["score"] == 100
|
||||
assert result["counts"]["info"] == 1
|
||||
assert result["counts"]["skip"] == 1
|
||||
assert result["counts"]["pass"] == 1
|
||||
|
||||
|
||||
def test_informational_severity_zero_weight_ignored():
|
||||
checks = [_check(FAIL, "info"), _check(PASS, HIGH)]
|
||||
result = registry.compute_score(checks)
|
||||
assert result["score"] == 100
|
||||
|
||||
|
||||
def test_severity_weighting_favours_critical():
|
||||
checks = [_check(FAIL, CRITICAL), _check(PASS, LOW)]
|
||||
result = registry.compute_score(checks)
|
||||
assert result["score"] < 50
|
||||
|
||||
|
||||
def test_grade_boundaries():
|
||||
assert registry._grade(90) == "A"
|
||||
assert registry._grade(89) == "B"
|
||||
assert registry._grade(80) == "B"
|
||||
assert registry._grade(70) == "C"
|
||||
assert registry._grade(55) == "D"
|
||||
assert registry._grade(54) == "F"
|
||||
|
||||
|
||||
def test_categories_reported_per_bucket():
|
||||
checks = [
|
||||
_check(PASS, HIGH, category="meta"),
|
||||
_check(FAIL, HIGH, category="links"),
|
||||
]
|
||||
result = registry.compute_score(checks)
|
||||
assert result["categories"]["meta"]["score"] == 100
|
||||
assert result["categories"]["links"]["score"] == 0
|
||||
|
||||
|
||||
def test_empty_checks_scores_zero():
|
||||
result = registry.compute_score([])
|
||||
assert result["score"] == 0
|
||||
assert result["grade"] == "F"
|
||||
|
||||
|
||||
def test_run_page_checks_returns_checks():
|
||||
page = PageContext(
|
||||
requested_url="https://example.com",
|
||||
url="https://example.com",
|
||||
status=200,
|
||||
ok=True,
|
||||
rendered_html="<html><head><title>Hi</title></head><body></body></html>",
|
||||
)
|
||||
site = SiteContext(target_url="https://example.com", base_host="example.com")
|
||||
checks = registry.run_page_checks(page, site)
|
||||
assert isinstance(checks, list)
|
||||
assert all(isinstance(c, Check) for c in checks)
|
||||
|
||||
|
||||
def test_run_site_checks_returns_checks():
|
||||
site = SiteContext(target_url="https://example.com", base_host="example.com")
|
||||
checks = registry.run_site_checks(site)
|
||||
assert isinstance(checks, list)
|
||||
assert all(isinstance(c, Check) for c in checks)
|
||||
|
||||
|
||||
def test_bad_page_check_does_not_abort(monkeypatch):
|
||||
def explode(page, site):
|
||||
raise RuntimeError("boom")
|
||||
|
||||
monkeypatch.setattr(registry, "PAGE_CHECKS", [explode])
|
||||
page = PageContext(url="https://example.com", ok=True)
|
||||
site = SiteContext(target_url="https://example.com")
|
||||
checks = registry.run_page_checks(page, site)
|
||||
assert len(checks) == 1
|
||||
assert checks[0].status == INFO
|
||||
assert "explode" in checks[0].id
|
||||
Reference in New Issue
Block a user