Skip to content

test: sign webhook requests in test_api.py and the CI integration job - #185

Merged
OkiriGabriel merged 1 commit into
open-devops-agent:mainfrom
OpeyemiAdeniji:ci/sign-webhook-requests
Nov 24, 2026
Merged

OkiriGabriel merged 1 commit into
open-devops-agent:mainfrom
OpeyemiAdeniji:ci/sign-webhook-requests

Conversation

@OpeyemiAdeniji

Copy link
Copy Markdown
Contributor

Description

Step 2 of the plan on #64 (non-breaking), as agreed in #64.

The webhook tests in tests/test_api.py and the CI integration job sent unsigned requests. They only passed because no WEBHOOK_SECRET was 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.py

  • The client fixture sets WEBHOOK_SECRET; webhook tests sign the exact bytes they send through a _post_signed helper.
  • New tests: missing signature on /webhook/github → 401; unsigned /webhook/manual → 401; Alertmanager with Authorization: Bearer <secret> → 200; wrong bearer token → 401.
  • test_github_webhook_no_secret_accepts_all stays 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-secret is set at job level (a dummy value), so the server verifies every webhook request and the test steps can sign.
  • The shared helpers now have post (HMAC-SHA256 via openssl, sent as X-Hub-Signature-256) and post_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.
  • New Test Webhook Authentication step: unsigned request, wrong signature, a valid signature for a different body, and a wrong bearer token all get 401 Invalid signature.
  • The five manual-webhook steps from test(ci): assert status codes and response shape for /webhook/manual in integration job #107 are now one Test Manual Webhook step using the same helpers, with the same assertions. The helper step moved above it.
  • The GitHub, GitLab, Bitbucket, Alertmanager and Grafana steps from test(ci): assert status codes and response shape for the remaining /webhook/* routes #176 are unchanged except that their requests are now signed (or use the bearer token).

Part of #64 (step 3, fail closed, will follow in a separate PR)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • New platform/collector support

Tests and CI configuration only (none of the listed types fit).

Platform/Component

  • Core Agent
  • Kubernetes
  • CI/CD (specify: GitHub Actions workflow, integration-test job)
  • Cloud Provider
  • ArgoCD
  • Docker
  • API Server
  • Tools/Executor
  • Documentation
  • Tests

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 needs python3 on 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) with WEBHOOK_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 the openssl signatures match the server's HMAC.

  • jq isn't installed on my machine, so for that local run jq was 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 actual jq filters.

  • Workflow parsed with yaml.safe_load; bash -n passes on every new or changed run: script.

  • Blocking Flake8 check (E9,F63,F7,F82) is clean. Full Flake8 shows three unused imports in tests/test_api.py (os, AsyncMock, MagicMock); they're already on main, so I left them out of this PR.

Test Configuration

OS: Windows (Git Bash)
Python Version: 3.12 (CI integration job uses 3.10)
Kubernetes Version: N/A
Cloud Provider: N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (N/A)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (1 Windows-only failure unrelated to this change, see Testing)
  • Any dependent changes have been merged and published

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

Reviewer Checklist

  • Code quality is acceptable
  • Tests are comprehensive
  • Documentation is updated
  • No security concerns
  • Performance impact is acceptable

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
@OkiriGabriel
OkiriGabriel merged commit eed8e77 into open-devops-agent:main Nov 24, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants