Files
wehub-resource-sync 7a0da7932b
Backwards Compatibility / Verify Encryption Constants (push) Waiting to run
Backwards Compatibility / PyPI Version Compatibility (push) Waiting to run
Backwards Compatibility / Database Migration Tests (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (python) (push) Waiting to run
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Blocked by required conditions
Docker Tests (Consolidated) / detect-changes (push) Waiting to run
Docker Tests (Consolidated) / Build Test Image (push) Waiting to run
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Blocked by required conditions
Docker Tests (Consolidated) / Accessibility Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Unit Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Example Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / Production Image Smoke Test (push) Blocked by required conditions
Docker Tests (Consolidated) / Infrastructure Tests (push) Blocked by required conditions
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Waiting to run
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

133 lines
4.8 KiB
Python

"""Test URL utility functions."""
import pytest
from local_deep_research.utilities.url_utils import is_private_ip, normalize_url
class TestNormalizeUrl:
"""Test cases for the normalize_url function."""
def test_localhost_without_scheme(self):
"""Test that localhost addresses get http:// prefix."""
assert normalize_url("localhost:11434") == "http://localhost:11434"
assert normalize_url("127.0.0.1:11434") == "http://127.0.0.1:11434"
assert normalize_url("[::1]:11434") == "http://[::1]:11434"
assert normalize_url("0.0.0.0:11434") == "http://0.0.0.0:11434"
def test_external_host_without_scheme(self):
"""Test that external hosts get https:// prefix."""
assert normalize_url("example.com:11434") == "https://example.com:11434"
assert normalize_url("api.example.com") == "https://api.example.com"
def test_private_ip_without_scheme(self):
"""Test that private network IPs get http:// prefix."""
# 10.0.0.0/8 range
assert normalize_url("10.0.0.1:8000") == "http://10.0.0.1:8000"
assert (
normalize_url("10.255.255.255:8000") == "http://10.255.255.255:8000"
)
# 172.16.0.0/12 range
assert normalize_url("172.16.0.50:8000") == "http://172.16.0.50:8000"
assert (
normalize_url("172.31.255.255:8000") == "http://172.31.255.255:8000"
)
# 192.168.0.0/16 range
assert (
normalize_url("192.168.1.100:8000") == "http://192.168.1.100:8000"
)
assert (
normalize_url("192.168.0.1:11434/v1")
== "http://192.168.0.1:11434/v1"
)
# .local domain (mDNS)
assert (
normalize_url("myserver.local:8000") == "http://myserver.local:8000"
)
def test_malformed_url_with_scheme(self):
"""Test correction of malformed URLs like 'http:hostname'."""
assert normalize_url("http:localhost:11434") == "http://localhost:11434"
assert (
normalize_url("https:example.com:11434")
== "https://example.com:11434"
)
def test_well_formed_urls(self):
"""Test that well-formed URLs are unchanged."""
assert (
normalize_url("http://localhost:11434") == "http://localhost:11434"
)
assert (
normalize_url("https://example.com:11434")
== "https://example.com:11434"
)
assert (
normalize_url("http://192.168.1.100:11434")
== "http://192.168.1.100:11434"
)
def test_urls_with_double_slash_prefix(self):
"""Test URLs that start with //."""
assert normalize_url("//localhost:11434") == "http://localhost:11434"
assert (
normalize_url("//example.com:11434") == "https://example.com:11434"
)
def test_empty_or_none_url(self):
"""Test handling of empty or None URLs."""
with pytest.raises(ValueError):
normalize_url("")
with pytest.raises(ValueError):
normalize_url(None)
def test_url_with_path(self):
"""Test URLs with paths."""
assert (
normalize_url("localhost:11434/api") == "http://localhost:11434/api"
)
assert (
normalize_url("example.com/api/v1") == "https://example.com/api/v1"
)
class TestIsPrivateIp:
"""Test cases for the is_private_ip function."""
def test_localhost_values(self):
"""Test that localhost values are recognized as private."""
assert is_private_ip("localhost") is True
assert is_private_ip("127.0.0.1") is True
assert is_private_ip("[::1]") is True
assert is_private_ip("0.0.0.0") is True
def test_private_ipv4_ranges(self):
"""Test that private IPv4 ranges are recognized."""
# 10.0.0.0/8
assert is_private_ip("10.0.0.1") is True
assert is_private_ip("10.255.255.255") is True
# 172.16.0.0/12
assert is_private_ip("172.16.0.1") is True
assert is_private_ip("172.31.255.255") is True
# 192.168.0.0/16
assert is_private_ip("192.168.0.1") is True
assert is_private_ip("192.168.255.255") is True
def test_public_ipv4(self):
"""Test that public IPv4 addresses are not recognized as private."""
assert is_private_ip("8.8.8.8") is False
assert is_private_ip("1.1.1.1") is False
assert (
is_private_ip("172.32.0.1") is False
) # Just outside 172.16.0.0/12
def test_hostnames(self):
"""Test hostname handling."""
assert is_private_ip("api.openai.com") is False
assert is_private_ip("example.com") is False
assert is_private_ip("myserver.local") is True # mDNS domain
if __name__ == "__main__":
pytest.main([__file__, "-v"])