fix: защита от дубликатов сканов — UPDATED-only + per-URL мьютекс
- constants.py: RELEVANT_WEBHOOK_ACTIONS теперь только UPDATED (CREATED игнорируется, Nexs proxy шлёт UPDATED при обновл кэша) - harvester.py: asyncio.Lock на каждый download_url — при параллельных вебхуках только первый пройдёт, остальные skipped — lock проверяется + DB re-check внутри критической секции - tests: обновлены фикстуры (CREATED→UPDATED), добавлен тест ignores_created
This commit is contained in:
@@ -99,7 +99,7 @@ def sample_nexus_webhook():
|
||||
"timestamp": "2026-05-09T12:00:00.000+00:00",
|
||||
"nodeId": "test-node",
|
||||
"initiator": "admin",
|
||||
"action": "CREATED",
|
||||
"action": "UPDATED",
|
||||
"repositoryName": "pypi-proxy",
|
||||
"asset": {
|
||||
"id": "abc123",
|
||||
@@ -117,7 +117,7 @@ def sample_nexus_component_webhook():
|
||||
"timestamp": "2026-05-09T12:00:00.000+00:00",
|
||||
"nodeId": "test-node",
|
||||
"initiator": "admin",
|
||||
"action": "CREATED",
|
||||
"action": "UPDATED",
|
||||
"repositoryName": "pypi-proxy",
|
||||
"component": {
|
||||
"id": "comp1",
|
||||
|
||||
@@ -24,14 +24,11 @@ async def test_webhook_ignores_deleted_action(client, sample_nexus_webhook):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_webhook_accepts_asset_created(client, sample_nexus_webhook):
|
||||
with patch("guarddog_nexus.webhooks._scan_in_background") as _mock:
|
||||
resp = await client.post("/webhooks/nexus", json=sample_nexus_webhook)
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert data["status"] == "accepted"
|
||||
assert data["action"] == "CREATED"
|
||||
assert "/packages/requests/2.31.0/requests-2.31.0.tar.gz" in data["asset"]
|
||||
async def test_webhook_ignores_created_action(client, sample_nexus_webhook):
|
||||
sample_nexus_webhook["action"] = "CREATED"
|
||||
resp = await client.post("/webhooks/nexus", json=sample_nexus_webhook)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["status"] == "ignored"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user