Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/aio_fleet/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"upstream-monitor",
"upstream-update",
}
HTTP_USER_AGENT = "aio-fleet-alerts/1.0"


@dataclass(frozen=True)
Expand Down Expand Up @@ -222,7 +223,7 @@ def send_webhook(
request = urllib.request.Request(
webhook_url,
data=body,
headers=headers,
headers={**headers, "User-Agent": HTTP_USER_AGENT},
method="POST",
)
with urllib.request.urlopen(request, timeout=20) as response: # nosec B310
Expand Down
2 changes: 2 additions & 0 deletions tests/test_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def fake_urlopen(request: urllib.request.Request, timeout: int):
body = json.loads(seen[0].data.decode()) # type: ignore[union-attr]
assert body["dedupe_key"] == "registry-audit:fleet" # nosec B101
assert body["status"] == "failure" # nosec B101
assert seen[0].headers["User-agent"] == "aio-fleet-alerts/1.0" # nosec B101


def test_discord_webhook_uses_discord_payload(monkeypatch) -> None:
Expand Down Expand Up @@ -107,6 +108,7 @@ def fake_urlopen(request: urllib.request.Request, timeout: int):
body = json.loads(seen[0].data.decode()) # type: ignore[union-attr]
assert body["allowed_mentions"]["parse"] == [] # nosec B101
assert body["content"].startswith("aio-fleet: upstream updates") # nosec B101
assert seen[0].headers["User-agent"] == "aio-fleet-alerts/1.0" # nosec B101
assert body["embeds"][0]["fields"][2]["value"] == ( # nosec B101
"upstream-monitor:fleet:all"
)
Expand Down