Files
wehub-resource-sync 7a0da7932b
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
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

127 lines
4.9 KiB
Python

"""Extended tests for url_utils.py - covering IPv6, fragments, and edge cases."""
import pytest
from unittest.mock import patch
class TestNormalizeUrlIPv6:
"""Tests for IPv6 address handling in normalize_url."""
def test_ipv6_loopback_gets_http(self):
"""IPv6 loopback [::1] should get http:// scheme."""
from local_deep_research.utilities.url_utils import normalize_url
with patch(
"local_deep_research.utilities.url_utils.is_private_ip",
return_value=True,
):
result = normalize_url("[::1]:8080")
assert result == "http://[::1]:8080"
def test_ipv6_address_with_brackets(self):
"""IPv6 address with brackets should be handled correctly."""
from local_deep_research.utilities.url_utils import normalize_url
with patch(
"local_deep_research.utilities.url_utils.is_private_ip",
return_value=False,
):
result = normalize_url("[2001:db8::1]:443")
assert result == "https://[2001:db8::1]:443"
def test_ipv6_address_already_has_scheme(self):
"""IPv6 URL with existing scheme should be returned unchanged."""
from local_deep_research.utilities.url_utils import normalize_url
result = normalize_url("http://[::1]:11434")
assert result == "http://[::1]:11434"
class TestNormalizeUrlFragments:
"""Tests for URL fragment/anchor handling."""
def test_preserves_fragment(self):
"""URL with # fragment should be preserved."""
from local_deep_research.utilities.url_utils import normalize_url
result = normalize_url("http://example.com/page#section")
assert result == "http://example.com/page#section"
def test_preserves_query_and_fragment(self):
"""URL with both query string and fragment should be preserved."""
from local_deep_research.utilities.url_utils import normalize_url
result = normalize_url("http://example.com/page?q=test#section")
assert result == "http://example.com/page?q=test#section"
class TestNormalizeUrlEdgeCases:
"""Additional edge cases for normalize_url."""
def test_url_with_path_and_no_scheme(self):
"""URL with path but no scheme should get appropriate scheme."""
from local_deep_research.utilities.url_utils import normalize_url
with patch(
"local_deep_research.utilities.url_utils.is_private_ip",
return_value=False,
):
result = normalize_url("example.com/api/v1/search")
assert result == "https://example.com/api/v1/search"
def test_url_with_encoded_characters(self):
"""URL with percent-encoded characters should be preserved."""
from local_deep_research.utilities.url_utils import normalize_url
result = normalize_url("http://example.com/path%20with%20spaces")
assert result == "http://example.com/path%20with%20spaces"
def test_none_url_raises_error(self):
"""None URL should raise a TypeError or ValueError."""
from local_deep_research.utilities.url_utils import normalize_url
with pytest.raises((ValueError, TypeError)):
normalize_url(None)
def test_whitespace_only_url_raises_error(self):
"""Whitespace-only URL should raise ValueError after strip."""
from local_deep_research.utilities.url_utils import normalize_url
# After stripping whitespace, the URL becomes empty which should raise
# However, the function may handle this differently
try:
result = normalize_url(" ")
# If it doesn't raise, it should at least produce some output
assert isinstance(result, str)
except (ValueError, TypeError):
pass # Expected behavior
def test_url_with_port_no_scheme_external(self):
"""External hostname with port and no scheme should get https."""
from local_deep_research.utilities.url_utils import normalize_url
with patch(
"local_deep_research.utilities.url_utils.is_private_ip",
return_value=False,
):
result = normalize_url("api.example.com:8443")
assert result == "https://api.example.com:8443"
def test_double_slash_with_private_ip(self):
"""// prefix with private IP should resolve to http."""
from local_deep_research.utilities.url_utils import normalize_url
with patch(
"local_deep_research.utilities.url_utils.is_private_ip",
return_value=True,
):
result = normalize_url("//192.168.1.1:8080")
assert result == "http://192.168.1.1:8080"
def test_url_with_userinfo(self):
"""URL with user info (user:pass@host) should be preserved."""
from local_deep_research.utilities.url_utils import normalize_url
result = normalize_url("http://user:pass@example.com:8080/path")
assert result == "http://user:pass@example.com:8080/path"