Files
wehub-resource-sync 6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:33:44 +08:00

125 lines
4.7 KiB
Python

"""Unit tests for the Phase 3e stealth kwargs builder (proprietary boundary)."""
import pytest
from app.config import config
from app.proprietary.web_crawler import stealth
from app.proprietary.web_crawler.stealth import (
build_stealthy_kwargs,
get_stealth_config,
location_to_locale_timezone,
)
pytestmark = pytest.mark.unit
def _set_proxy_location(monkeypatch: pytest.MonkeyPatch, location: str) -> None:
"""Point get_stealth_config at a stub provider with the given exit region."""
class _StubProvider:
def get_location(self) -> str:
return location
monkeypatch.setattr(stealth, "get_active_provider", lambda: _StubProvider())
class TestLocationToLocaleTimezone:
def test_alpha2_code(self):
assert location_to_locale_timezone("us") == ("en-US", "America/New_York")
assert location_to_locale_timezone("de") == ("de-DE", "Europe/Berlin")
def test_case_and_whitespace_insensitive(self):
assert location_to_locale_timezone(" US ") == (
"en-US",
"America/New_York",
)
def test_full_country_name_alias(self):
assert location_to_locale_timezone("Germany") == (
"de-DE",
"Europe/Berlin",
)
assert location_to_locale_timezone("united kingdom") == (
"en-GB",
"Europe/London",
)
def test_leading_token_of_vendor_string(self):
# Vendor strings like "us:nyc" / "de-rotating" still resolve on the head.
assert location_to_locale_timezone("us:nyc") == (
"en-US",
"America/New_York",
)
assert location_to_locale_timezone("de-rotating") == (
"de-DE",
"Europe/Berlin",
)
def test_empty_and_unknown_return_none(self):
assert location_to_locale_timezone("") == (None, None)
assert location_to_locale_timezone(None) == (None, None)
assert location_to_locale_timezone("atlantis") == (None, None)
class TestBuildStealthyKwargs:
def test_defaults_have_no_geoip_keys(self, monkeypatch):
# geoip off => locale/timezone_id absent (browser keeps system default).
monkeypatch.setattr(config, "CRAWL_GEOIP_MATCH_ENABLED", False)
monkeypatch.setattr(config, "CRAWL_BLOCK_WEBRTC", True)
monkeypatch.setattr(config, "CRAWL_HIDE_CANVAS", False)
monkeypatch.setattr(config, "CRAWL_GOOGLE_SEARCH_REFERER", True)
monkeypatch.setattr(config, "CRAWL_DNS_OVER_HTTPS", False)
_set_proxy_location(monkeypatch, "us")
kwargs = build_stealthy_kwargs(get_stealth_config())
assert kwargs == {
"block_webrtc": True,
"hide_canvas": False,
"google_search": True,
"dns_over_https": False,
}
assert "locale" not in kwargs
assert "timezone_id" not in kwargs
def test_flags_reflect_config(self, monkeypatch):
monkeypatch.setattr(config, "CRAWL_GEOIP_MATCH_ENABLED", False)
monkeypatch.setattr(config, "CRAWL_BLOCK_WEBRTC", False)
monkeypatch.setattr(config, "CRAWL_HIDE_CANVAS", True)
monkeypatch.setattr(config, "CRAWL_GOOGLE_SEARCH_REFERER", False)
monkeypatch.setattr(config, "CRAWL_DNS_OVER_HTTPS", True)
_set_proxy_location(monkeypatch, "")
kwargs = build_stealthy_kwargs(get_stealth_config())
assert kwargs["block_webrtc"] is False
assert kwargs["hide_canvas"] is True
assert kwargs["google_search"] is False
assert kwargs["dns_over_https"] is True
def test_geoip_on_adds_locale_timezone(self, monkeypatch):
monkeypatch.setattr(config, "CRAWL_GEOIP_MATCH_ENABLED", True)
monkeypatch.setattr(config, "CRAWL_BLOCK_WEBRTC", True)
monkeypatch.setattr(config, "CRAWL_HIDE_CANVAS", False)
monkeypatch.setattr(config, "CRAWL_GOOGLE_SEARCH_REFERER", True)
monkeypatch.setattr(config, "CRAWL_DNS_OVER_HTTPS", False)
_set_proxy_location(monkeypatch, "de")
kwargs = build_stealthy_kwargs(get_stealth_config())
assert kwargs["locale"] == "de-DE"
assert kwargs["timezone_id"] == "Europe/Berlin"
def test_geoip_on_but_unknown_location_skips(self, monkeypatch):
monkeypatch.setattr(config, "CRAWL_GEOIP_MATCH_ENABLED", True)
monkeypatch.setattr(config, "CRAWL_BLOCK_WEBRTC", True)
monkeypatch.setattr(config, "CRAWL_HIDE_CANVAS", False)
monkeypatch.setattr(config, "CRAWL_GOOGLE_SEARCH_REFERER", True)
monkeypatch.setattr(config, "CRAWL_DNS_OVER_HTTPS", False)
_set_proxy_location(monkeypatch, "atlantis")
kwargs = build_stealthy_kwargs(get_stealth_config())
assert "locale" not in kwargs
assert "timezone_id" not in kwargs