Skip to content

test(security): route-specific regression tests for #684 admin auth fix - #739

Merged
HongmingWang-Rabbit merged 1 commit into
mainfrom
test/issue-684-adminauth-bearer-scope-v2
Apr 17, 2026
Merged

test(security): route-specific regression tests for #684 admin auth fix#739
HongmingWang-Rabbit merged 1 commit into
mainfrom
test/issue-684-adminauth-bearer-scope-v2

Conversation

@molecule-ai

@molecule-ai molecule-ai Bot commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Summary

What changed

3 new table-driven test functions in wsauth_middleware_test.go, each covering /admin/liveness, /admin/github-installation-token, and /approvals/pending:

Test function Sub-tests What it pins
TestAdminAuth_684_SpecificRoutes_WorkspaceTokenRejected 3 Workspace bearer ≠ ADMIN_TOKEN → 401 on every vulnerable route
TestAdminAuth_684_SpecificRoutes_CorrectAdminTokenAccepted 3 Exact ADMIN_TOKEN → 200; no DB token lookup fires
TestAdminAuth_684_SpecificRoutes_NoBearer_Returns401 6 No bearer → 401 with and without ADMIN_TOKEN set

Why this approach

PR #729's AdminAuth implementation uses ADMIN_TOKEN env var + crypto/subtle.ConstantTimeCompare (tier 2) before falling back to ValidateAnyToken (tier 3 deprecated). When ADMIN_TOKEN is set:

  • Only HasAnyLiveTokenGlobal makes a DB call
  • ValidateAnyToken is never called — the mock sets no DB expectation for token validation, which itself proves the code path is correct (a stray DB call would hit sqlmock's "unexpected query" error and fail the test)

Test output

--- PASS: TestAdminAuth_684_SpecificRoutes_WorkspaceTokenRejected (0.00s)
    --- PASS: .../admin/liveness
    --- PASS: .../admin/github-installation-token
    --- PASS: .../approvals/pending
--- PASS: TestAdminAuth_684_SpecificRoutes_CorrectAdminTokenAccepted (0.00s)
    --- PASS: .../admin/liveness
    --- PASS: .../admin/github-installation-token
    --- PASS: .../approvals/pending
--- PASS: TestAdminAuth_684_SpecificRoutes_NoBearer_Returns401 (0.00s)
    --- PASS: .../admin/liveness/ADMIN_TOKEN=some-admin-secret
    --- PASS: .../admin/github-installation-token/ADMIN_TOKEN=some-admin-secret
    --- PASS: .../approvals/pending/ADMIN_TOKEN=some-admin-secret
    --- PASS: .../admin/liveness/ADMIN_TOKEN=
    --- PASS: .../admin/github-installation-token/ADMIN_TOKEN=
    --- PASS: .../approvals/pending/ADMIN_TOKEN=

All 18 TestAdminAuth_684* tests (6 existing from BE + 12 new) pass. Full go test ./... is green across all 15 platform packages.

Test plan

  • go build ./... — clean (zero errors)
  • All TestAdminAuth_684* tests: 18/18 PASS
  • Full go test ./... across 15 packages: all green
  • Diff: only wsauth_middleware_test.go changed, +165 lines, no deletions

🤖 Generated with Claude Code

…in routes

The BE's tests (AdminTokenSet_*, FailOpen_*) validated the core AdminAuth
contract on /admin/secrets. These table-driven additions pin the same contract
on the three routes explicitly named in the #684 security report, each with
three scenarios: workspace token rejected, correct ADMIN_TOKEN accepted, no
bearer rejected.

Routes covered:
  GET /admin/liveness
  GET /admin/github-installation-token
  GET /approvals/pending

When ADMIN_TOKEN is set (tier 2), ValidateAnyToken is never called — the
env-var comparison short-circuits before any DB lookup. The mock sets only
HasAnyLiveTokenGlobal and nothing else; an extra DB expectation would itself
be a test bug (calling it proves the middleware regressed to tier 3).

All 18 TestAdminAuth_684* tests pass. Full go test ./... is green across all
15 platform packages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@molecule-ai molecule-ai Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVED — Correct approach, clean implementation.

Tests now match PR #729's ADMIN_TOKEN env-var implementation exactly:

  • t.Setenv("ADMIN_TOKEN", ...) — no DB mock approach ✅
  • Only hasAnyLiveTokenGlobalQuery mocked — ValidateAnyToken never called ✅
  • The absence of a DB token-lookup expectation proves the env-var short-circuit fires; any stray DB call would hit sqlmock's 'unexpected query' error and fail the test — elegant self-checking design ✅
  • Table-driven across all 3 vulnerable routes (#684 report: /admin/liveness, /admin/github-installation-token, /approvals/pending) ✅
  • rt := rt capture for parallel-safe subtests ✅
  • mock.ExpectationsWereMet() in every subtest ✅
  • 18/18 TestAdminAuth_684* (6 BE + 12 QA), full go test ./... green ✅

Ready to merge alongside PR #729. These two PRs together give complete application-layer coverage of the #684 fix.

@HongmingWang-Rabbit
HongmingWang-Rabbit merged commit e8c1f7a into main Apr 17, 2026
6 checks passed
@HongmingWang-Rabbit
HongmingWang-Rabbit deleted the test/issue-684-adminauth-bearer-scope-v2 branch April 17, 2026 15:47
molecule-ai Bot pushed a commit that referenced this pull request Apr 21, 2026
…rer-scope-v2

test(security): route-specific regression tests for #684 admin auth fix
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.

1 participant