Skip to content

test: Add SPIFFE exchange, malformed bearer, and credential error tests - #306

Merged
huang195 merged 1 commit into
rossoctl:mainfrom
huang195:test/tier1-exchange-gaps
Apr 14, 2026
Merged

huang195 merged 1 commit into
rossoctl:mainfrom
huang195:test/tier1-exchange-gaps

Conversation

@huang195

Copy link
Copy Markdown
Member

Summary

Cover the highest-value remaining gaps in go-processor token exchange:

SPIFFE federated exchange (3 subtests):

  • Succeeds with JWT-SVID file, verifies client_assertion_type and client_assertion params
  • Fails gracefully when SVID file is missing (no Keycloak call made)
  • Fails gracefully when SVID file is empty

Outbound edge cases (3 tests):

  • Malformed (non-Bearer) Authorization header on routed host returns 503
  • clientCredentialsGrant surfaces Keycloak 401 errors correctly
  • client_credentials fallback failure on routed host returns 503 (not passthrough)

Coverage changes (this branch only):

  • exchangeToken: 70.8% -> 87.5%
  • handleOutbound: 87.7% -> 93.8%

Combined with #304 (inbound) and #305 (config/utility), total go-processor coverage reaches ~65-70%.

Test plan

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Clean test-only PR — well-structured tests with proper resource cleanup, global state isolation, and good assertion coverage. Two minor nits below, neither blocking.

Areas reviewed: Go tests, commit conventions, security
CI: all passing

// TestOutboundMalformedBearerToken verifies that an outbound request with an
// Authorization header that doesn't have the "Bearer " prefix gets denied (503).
func TestOutboundMalformedBearerToken(t *testing.T) {
saved := saveGlobals()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Unlike the "svid file missing" subtest (which checks strings.Contains(err.Error(), "JWT-SVID unavailable")), this subtest only checks err != nil. Consider adding a similar error message assertion for consistency — it guards against the wrong error path being taken (e.g. a network error from the mock server instead of the expected empty-file validation).

"subject-token", "auth-target", "openid auth-target-aud",
true, svidPath, "")
if err != nil {
t.Fatalf("unexpected error: %v", err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit (cosmetic): os.WriteFile return value is unchecked here and in the empty-SVID subtest. Idiomatic for Go tests since the test would fail downstream, but a quick if err != nil { t.Fatal(err) } would make setup failures immediately obvious.

Cover the highest-value remaining gaps in go-processor:

- TestExchangeTokenSPIFFE (3 subtests): SPIFFE federated auth path
  using JWT-SVID as client_assertion, missing SVID file, empty SVID
- TestOutboundMalformedBearerToken: non-Bearer auth header on routed
  host returns 503
- TestClientCredentialsGrantError: Keycloak 401 response surfaces error
- TestOutboundClientCredentialsFails: client_credentials fallback
  failure returns 503 (not passthrough)

Addresses review feedback: os.WriteFile errors checked, empty-SVID
error message asserted.

Signed-off-by: Hai Huang <[email protected]>
@huang195
huang195 force-pushed the test/tier1-exchange-gaps branch from 64a614d to 30a57d0 Compare April 14, 2026 12:46
@huang195
huang195 merged commit da3b655 into rossoctl:main Apr 14, 2026
15 checks passed
@huang195
huang195 deleted the test/tier1-exchange-gaps branch April 14, 2026 12:50
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