Report catalogue pace per document, not only per byte
CI / Python 3.13 (push) Successful in 42s
CI / Python 3.12 (push) Successful in 47s
CI / Build and smoke-test image (push) Successful in 18s

This commit is contained in:
omar committed 2026-11-29 09:26:18 +03:00
1 parent 58e4ec35ac
commit 7763634e6f
2 files changed
+47 -2

No files matched your search

+35 -1
View File
@@ -141,7 +141,7 @@ async def test_one_broken_document_does_not_cost_the_catalogue(tmp_path, monkeyp
return original_client(transport=httpx.MockTransport(respond), trust_env=False)
monkeypatch.setattr(httpx, "AsyncClient", make_client)
caplog.set_level("WARNING")
caplog.set_level("INFO")
settings = SimpleNamespace(proxies=("http://proxy.test:8080",), max_retries=0, live_route="proxy", live_timeout=9.5)
async with Store(tmp_path) as store, HttpClients(settings, store) as clients:
assert await Sync(store, clients.index).refresh_once("msrc")
@@ -149,3 +149,37 @@ async def test_one_broken_document_does_not_cost_the_catalogue(tmp_path, monkeyp
assert cve.native_id == "msrc_" + _CVE
assert not await store.by_id(_ADV)
assert "msrc skipped msrc_adv260001" in caplog.text
def _identifier(url: str) -> str:
return url.rsplit("/", 1)[-1].removesuffix(".json").removeprefix("msrc_")
@pytest.mark.anyio
async def test_long_catalogue_reports_pace(tmp_path, monkeypatch, caplog) -> None:
metadata = {"metadata_version": "2.0", "list_on_CSAF_aggregators": True,
"distributions": [{"directory_url": _ROOT.rstrip("/")}]}
rows = b"".join(('"2026/msrc_adv%06d.json","2026-10-13T07:00:00Z"\r\n' % n).encode() for n in range(100))
rows += b'"2026/msrc_cve-2026-70175.json","2026-11-23T08:00:00Z"\r\n'
original_client = httpx.AsyncClient
def make_client(*, proxy: str | None, trust_env: bool) -> httpx.AsyncClient:
def respond(request: httpx.Request) -> httpx.Response:
url = str(request.url)
if url == _MANIFEST:
return httpx.Response(200, content=rows)
if url == _METADATA:
return httpx.Response(200, json=metadata)
if url == _CVE_URL:
return httpx.Response(200, json=_cve_document())
return httpx.Response(200, json=_document(_identifier(url), "2026-10-13T07:00:00.000Z"))
return original_client(transport=httpx.MockTransport(respond), trust_env=False)
monkeypatch.setattr(httpx, "AsyncClient", make_client)
caplog.set_level("INFO", logger="vuln_mcp.sources.feeds_csaf")
settings = SimpleNamespace(proxies=("http://proxy.test:8080",), max_retries=0, live_route="proxy", live_timeout=9.5)
async with Store(tmp_path) as store, HttpClients(settings, store) as clients:
assert await Sync(store, clients.index).refresh_once("msrc")
lines = [r.getMessage() for r in caplog.records if "import" in r.getMessage()]
assert len(rows.splitlines()) == 101
assert lines and lines[0].startswith("msrc import 100/101"), (lines, len(rows.splitlines()))