Repository navigation
test: sign webhook requests in test_api.py and the CI integration job - #185
Merged
OkiriGabriel merged 1 commit intoNov 24, 2026
Merged
Conversation
Step 2 of open-devops-agent#64. Webhook tests and the integration job sent unsigned requests and only passed because no WEBHOOK_SECRET was configured, so CI never exercised webhook authentication. tests/test_api.py: - The client fixture sets WEBHOOK_SECRET; webhook tests sign the exact bytes they send via a _post_signed helper. - New: missing signature -> 401 (github), unsigned manual -> 401, Alertmanager bearer token -> 200 and wrong bearer token -> 401. - The no-secret test stays as the one explicit fail-open case. CI integration job: - WEBHOOK_SECRET is set at job level for the server and the test steps. - The helpers sign bodies with HMAC-SHA256 (openssl) and send them with --data-binary so the signed bytes are the bytes sent; Alertmanager and Grafana use Authorization: Bearer. - New "Test Webhook Authentication" step: unsigned, wrong signature, signature for a different body and wrong bearer token all get 401. - The five manual-webhook steps are folded into one step using the shared helpers, with the same assertions. Part of open-devops-agent#64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Step 2 of the plan on #64 (non-breaking), as agreed in #64.
The webhook tests in
tests/test_api.pyand the CI integration job sent unsigned requests. They only passed because noWEBHOOK_SECRETwas configured, so CI never exercised webhook authentication. This makes both run with a secret and sign their requests, so step 3 (fail closed) won't break them.tests/test_api.pyclientfixture setsWEBHOOK_SECRET; webhook tests sign the exact bytes they send through a_post_signedhelper./webhook/github→ 401; unsigned/webhook/manual→ 401; Alertmanager withAuthorization: Bearer <secret>→ 200; wrong bearer token → 401.test_github_webhook_no_secret_accepts_allstays as the one explicit no-secret test. Step 3 will turn it into the 503 case.CI integration job (
.github/workflows/ci.yml)WEBHOOK_SECRET: ci-webhook-secretis set at job level (a dummy value), so the server verifies every webhook request and the test steps can sign.post(HMAC-SHA256 viaopenssl, sent asX-Hub-Signature-256) andpost_bearer(Authorization: Bearer, used for Alertmanager and Grafana as you suggested). Bodies are sent with--data-binary, so the signed bytes are exactly the bytes sent.Invalid signature.Part of #64 (step 3, fail closed, will follow in a separate PR)
Type of Change
Tests and CI configuration only (none of the listed types fit).
Platform/Component
Testing
Unit tests added/updated
Integration tests pass (pending CI on this PR)
Manual testing performed
Tested with dummy data
Tested in production-like environment
tests/test_api.py: 16 passed (5 new).Full suite locally (Windows): 1172 passed, 30 skipped, 1 failed. The failure is the same unrelated
tests/test_nginx_bamboo.py::TestNginxTools::test_write_file_command_prevents_shell_expansion, which needspython3on PATH (see test(ci): assert status codes and response shape for /webhook/manual in integration job #107); it runs on Linux in CI.CI steps: I extracted the workflow's own
run:scripts and ran them against a local server (uvicorn api.server:app --lifespan off, so no queue worker or agent ran) withWEBHOOK_SECRET=ci-webhook-secret. All 26 checks passed across the 7 webhook steps, twice. The four 401s show the server had the secret, so the 200s confirm theopensslsignatures match the server's HMAC.jqisn't installed on my machine, so for that local runjqwas stubbed and I checked each response body against its filter by eye. The status codes were checked for real. This PR's CI run executes the actualjqfilters.Workflow parsed with
yaml.safe_load;bash -npasses on every new or changedrun:script.Blocking Flake8 check (
E9,F63,F7,F82) is clean. Full Flake8 shows three unused imports intests/test_api.py(os,AsyncMock,MagicMock); they're already onmain, so I left them out of this PR.Test Configuration
Checklist
Screenshots (if applicable)
N/A
Breaking Changes
None to the application. In CI, the integration job now fails if webhook authentication stops rejecting unsigned or wrongly signed requests.
Additional Notes
WEBHOOK_AUTH_DISABLED/SLACK_AUTH_DISABLED, 503 vs 401,docker-compose.yml,middleware/README.md,.env.example) will come in its own PR after this one, as you described on [SECURITY] Fail-closed webhook defaults and rate limiting for credential endpoints #64.Reviewer Checklist