Live reads go through an operator proxy pool (round-robin over the newest 100 entries, cooling on connect failures, no direct fallback); stored clearances are replayed only on the exit that earned them. Identity, clearance, solver and Turnstile rungs escalate automatically. fetch_pages reads up to 12 URLs four at a time with per-item isolation. report/reports/reports_update keep a durable queue of unreadable pages for the operator. Ships a pinned multi-stage image (non-root 10001, data in /data), an ordered CI with static gates, tests on 3.12 and 3.13 at 85% coverage, an offline image smoke, and sha/latest publishing gated on main.
70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
import time
|
|
|
|
import clearance
|
|
|
|
|
|
def test_put_and_lookup(clearance_file):
|
|
store = clearance.Store(clearance_file)
|
|
store.put("example.com", "http://p:1", {"cf_clearance": "v"})
|
|
pin, cookie = store.lookup("example.com")
|
|
assert pin == "http://p:1"
|
|
assert cookie == "cf_clearance=v"
|
|
assert clearance_file.exists()
|
|
|
|
|
|
def test_lookup_missing(clearance_file):
|
|
store = clearance.Store(clearance_file)
|
|
assert store.lookup("absent") == (None, None)
|
|
|
|
|
|
def test_empty_cookies_are_not_stored(clearance_file):
|
|
store = clearance.Store(clearance_file)
|
|
store.put("example.com", None, {})
|
|
assert len(store) == 0
|
|
|
|
|
|
def test_expired_entry_is_ignored(clearance_file, monkeypatch):
|
|
monkeypatch.setattr(clearance, "_TTL", -1.0)
|
|
store = clearance.Store(clearance_file)
|
|
store.put("example.com", None, {"cf_clearance": "v"})
|
|
assert store.lookup("example.com") == (None, None)
|
|
|
|
|
|
def test_drop_and_reload(clearance_file):
|
|
store = clearance.Store(clearance_file)
|
|
store.put("example.com", None, {"cf_clearance": "v"})
|
|
store.drop("example.com")
|
|
assert len(store) == 0
|
|
store.put("a.com", None, {"cf_clearance": "x"})
|
|
assert clearance.Store(clearance_file).lookup("a.com")[1] == "cf_clearance=x"
|
|
|
|
|
|
def test_broken_file_is_tolerated(clearance_file):
|
|
clearance_file.write_text('{"a": {"cookies": {"k": "v"}, "expires": "bad"}, "b": 7}', "utf-8")
|
|
store = clearance.Store(clearance_file)
|
|
assert len(store) == 0
|
|
|
|
|
|
def test_unwritable_path_is_tolerated(tmp_path, monkeypatch):
|
|
store = clearance.Store(tmp_path / "missing-dir" / "c.json")
|
|
store.put("a.com", None, {"k": "v"})
|
|
assert store.lookup("a.com")[1] == "k=v"
|
|
|
|
|
|
def test_ttl_bounds(monkeypatch):
|
|
import importlib
|
|
|
|
monkeypatch.setenv("MCP_CLEARANCE_TTL", "5")
|
|
reloaded = importlib.reload(clearance)
|
|
assert reloaded._TTL == 60.0
|
|
monkeypatch.setenv("MCP_CLEARANCE_TTL", "999999")
|
|
reloaded = importlib.reload(clearance)
|
|
assert reloaded._TTL == 14400.0
|
|
|
|
|
|
def test_now_based_expiry(clearance_file):
|
|
store = clearance.Store(clearance_file)
|
|
store.put("a.com", None, {"k": "v"})
|
|
entry = store._data["a.com"]
|
|
assert entry.expires > time.time()
|