Nine modules that only aliased invisible_core (_geo, _headless, _proxy, _webgl_personas, config, constants, download, prefs, _fpforge) and _reaper are gone, with the tests that existed for them (test_backcompat, test_suite_boundaries); the callers and the tests import invisible_core.<module> (invisible_core.process for the reaper). The cursor has one generator, CursorMotion(seed, *, style=), and two engines, python and off: INVPW_CURSOR_ENGINE=binary, the fallback to the browser's own motion, the alternative generator names, the max_seconds introspection and the MIN_EVENT_INTERVAL_MS re-export are removed. INVPW_TRANSPORT=driver and its guard are removed, with the driver arm of scripts/capture_protocol.py. preload_newtab is always handed to the core. resolve_session_timezone is no longer re-exported; the tests use cache_dir_for_seal, and ensure_geoip_mmdb comes from the package root. The documentation no longer presents INVPW_BINARY_PATH as a variable of the library (nothing reads it); binary_path= is the way. A new test fails if any of the removed modules or names comes back. The unit rows of ci/required-suites.json follow the files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110 lines
3.9 KiB
Python
110 lines
3.9 KiB
Python
"""scripts/ci_real_geoip_check.py, the three checks on the REAL database that only the release runs: here against databases made on the spot."""
|
|
import importlib.util
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
pytestmark = pytest.mark.unit
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def _load(name):
|
|
spec = importlib.util.spec_from_file_location(name + "_under_test", ROOT / "scripts" / (name + ".py"))
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
check = _load("ci_real_geoip_check")
|
|
lab = check.lab
|
|
|
|
|
|
def _database(tmp_path, name, networks=None):
|
|
"""A database made like the lab one, from `networks` (the table of the script when None)."""
|
|
old = dict(lab.NETWORKS)
|
|
try:
|
|
if networks is not None:
|
|
lab.NETWORKS.clear()
|
|
lab.NETWORKS.update(networks)
|
|
path = tmp_path / name
|
|
path.write_bytes(lab.build_bytes())
|
|
return path
|
|
finally:
|
|
lab.NETWORKS.clear()
|
|
lab.NETWORKS.update(old)
|
|
|
|
|
|
def _database_without_fallback(tmp_path, name):
|
|
"""The lab table alone, with no record for the other public addresses: a database that has no answer for 8.8.8.8."""
|
|
old = lab.FALLBACK
|
|
lab.FALLBACK = None
|
|
try:
|
|
return _database(tmp_path, name)
|
|
finally:
|
|
lab.FALLBACK = old
|
|
|
|
|
|
def test_the_exit_of_a_network_is_the_dot_five_of_its_slash_24():
|
|
assert check.exit_of(lab.net(1, 178, 10)) == lab.addr(1, 178, 10, 5)
|
|
|
|
|
|
def test_a_database_that_agrees_passes_the_comparison_and_the_zones(tmp_path, capsys):
|
|
real = _database(tmp_path, "real.mmdb")
|
|
ours = _database(tmp_path, "lab.mmdb")
|
|
assert check.check_lab_agrees(real, ours) == []
|
|
assert check.check_zones(real) == []
|
|
assert "distinct zones" in capsys.readouterr().out
|
|
|
|
|
|
def test_a_zone_that_differs_is_said_with_the_network(tmp_path):
|
|
changed = dict(lab.NETWORKS)
|
|
changed[lab.net(1, 0, 16)] = ("JP", "Asia/Seoul", 35.0, 139.0)
|
|
real = _database(tmp_path, "real.mmdb", changed)
|
|
ours = _database(tmp_path, "lab.mmdb")
|
|
problems = check.check_lab_agrees(real, ours)
|
|
assert len(problems) == 1 and lab.net(1, 0, 16) in problems[0] and "Asia/Seoul" in problems[0]
|
|
|
|
|
|
def test_a_network_the_real_database_does_not_have_is_said(tmp_path):
|
|
real = _database(tmp_path, "real.mmdb", {lab.net(1, 178, 10): lab.NETWORKS[lab.net(1, 178, 10)]})
|
|
ours = _database(tmp_path, "lab.mmdb")
|
|
problems = check.check_lab_agrees(real, ours)
|
|
assert len(problems) == len(lab.NETWORKS) - 1
|
|
|
|
|
|
def test_a_zone_the_runner_does_not_know_is_a_finding(tmp_path):
|
|
odd = dict(lab.NETWORKS)
|
|
odd[lab.net(1, 6, 0)] = ("IN", "Mars/Olympus_Mons", 1.0, 1.0)
|
|
real = _database(tmp_path, "real.mmdb", odd)
|
|
problems = check.check_zones(real)
|
|
assert len(problems) == 1 and "Mars/Olympus_Mons" in problems[0]
|
|
|
|
|
|
def test_a_database_that_does_not_open_or_has_no_country_is_a_finding(tmp_path):
|
|
broken = tmp_path / "broken.mmdb"
|
|
broken.write_bytes(b"not a database")
|
|
assert check.check_open_and_answer(broken)
|
|
assert check.check_open_and_answer(_database_without_fallback(tmp_path, "lab.mmdb")) # no 8.8.8.8 in it: no country
|
|
|
|
|
|
def test_the_command_takes_no_argument():
|
|
assert check.main(["--something"]) == 2
|
|
|
|
|
|
def test_the_product_road_is_the_one_without_the_variable_and_with_a_cold_cache(tmp_path, monkeypatch):
|
|
seen = {}
|
|
|
|
def fake():
|
|
seen["variable"] = os.environ.get("STEALTHFOX_GEOIP_MMDB")
|
|
seen["cache"] = os.environ.get("INVISIBLE_PLAYWRIGHT_CACHE_DIR")
|
|
return tmp_path / "x.mmdb"
|
|
|
|
monkeypatch.setenv("STEALTHFOX_GEOIP_MMDB", "/somewhere")
|
|
monkeypatch.setenv("INVISIBLE_PLAYWRIGHT_CACHE_DIR", "/before")
|
|
import invisible_core
|
|
monkeypatch.setattr(invisible_core, "ensure_geoip_mmdb", fake)
|
|
assert check.product_download(tmp_path / "cold") == tmp_path / "x.mmdb"
|
|
assert seen == {"variable": None, "cache": str(tmp_path / "cold")}
|