Skip to content

test: add unit tests for OIDC checkAuth claim extraction - #65

Merged
philipgough merged 1 commit into
rhobs:rhobs-obs-api-konfluxfrom
redhat-chai-bot:chai-bot/oidc-checkauth-tests
Oct 1, 2026
Merged

philipgough merged 1 commit into
rhobs:rhobs-obs-api-konfluxfrom
redhat-chai-bot:chai-bot/oidc-checkauth-tests

Conversation

@redhat-chai-bot

Copy link
Copy Markdown

Add comprehensive table-driven unit tests for the OIDC checkAuth method,
covering the claim extraction flexibility added in PRs #60 and #61.

What's tested

10 scenarios covering all claim permutations:

  1. Both username + group claims present → 200
  2. Username present, group claim missing → 200 (PR authentication/oidc: skip group claim check when username claim is configured #61)
  3. Group present, username claim missing → 200 (PR authentication/oidc: skip username claim check when group claim is configured #60)
  4. Neither claim present → 400
  5. Username claim empty string → 400
  6. Username claim wrong type (int) → 400
  7. Group claim as string → single group
  8. Group claim as []interface{} → multiple groups
  9. No claims configured → 200 (uses token subject)
  10. Group claim with non-string elements → converted via fmt.Sprintf

Implementation

Uses httptest.Server serving OIDC discovery + JWKS endpoints with RSA
key pair for signing test JWTs via go-jose/v4. Tests exercise the full
OIDC verification pipeline — no mocks.

Verification

  • go test -v -race ./authentication/... ✅ all pass
  • make build ✅
  • make test --always-make ✅
  • make lint --always-make ✅

Ref: RHOBS-1794


AI-generated. Review for accuracy.

@philipgough requested from Slack

Create authentication/oidc_test.go with table-driven tests covering
10 scenarios: both claims present, username-only (PR stolostron#61 behavior),
group-only (PR stolostron#60 behavior), neither claim, empty username, wrong
type username, group as string, group as []interface{}, no claims
configured, and non-string group elements. Uses a test OIDC server
with signed JWTs via go-jose/v4.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@philipgough
philipgough merged commit 90556e6 into rhobs:rhobs-obs-api-konflux Oct 1, 2026
5 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