Repository navigation
test: Add SPIFFE exchange, malformed bearer, and credential error tests - #306
Conversation
pdettori
left a comment
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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]>
64a614d to
30a57d0
Compare
Summary
Cover the highest-value remaining gaps in go-processor token exchange:
SPIFFE federated exchange (3 subtests):
Outbound edge cases (3 tests):
Coverage changes (this branch only):
Combined with #304 (inbound) and #305 (config/utility), total go-processor coverage reaches ~65-70%.
Test plan