37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from applepy import catalog_cache
|
|
|
|
|
|
def test_load_loobins_entries_filters() -> None:
|
|
rows = catalog_cache.load_loobins_entries(
|
|
[
|
|
{"name": "curl", "paths": ["/usr/bin/curl"], "short_description": "x"},
|
|
{"bad": 1},
|
|
{"name": "", "paths": []},
|
|
]
|
|
)
|
|
assert len(rows) == 1
|
|
assert rows[0]["name"] == "curl"
|
|
|
|
|
|
def test_iter_gtfo_modern_api_shape() -> None:
|
|
data = {
|
|
"functions": {},
|
|
"contexts": {},
|
|
"executables": {
|
|
"7z": {"functions": {"Shell": {}}},
|
|
"apt": {"alias": "apt-get"},
|
|
},
|
|
}
|
|
out = catalog_cache.iter_gtfo_binaries(data)
|
|
assert out == [("7z", {"functions": {"Shell": {}}})]
|
|
|
|
|
|
def test_fetch_json_offline_uses_stale(tmp_path, monkeypatch) -> None:
|
|
monkeypatch.setattr(catalog_cache, "_cache_dir", lambda: tmp_path)
|
|
url = "https://example.test/x.json"
|
|
p = catalog_cache._cache_path(url)
|
|
p.write_text("[1]", encoding="utf-8")
|
|
parsed, status = catalog_cache.fetch_json_url(url, offline=True, max_age_hours=0)
|
|
assert parsed == [1]
|
|
assert "offline" in status
|