Mechanical extraction, no behavior change, addressing 11 of the 29
open go:S3776 issues (the other 18 are flat validation/checklist
functions or large sequential test setups where splitting would just
scatter the same logic across files for no readability gain):
- storage/contract.go: extract every t.Run closure body in
TestGrantStoreContract/TestAccessTokenStoreContract/
TestBackchannelAuthenticationStoreContract into standalone top-level
functions, mirroring the Transaction/Session/Nonce contracts already
fixed this way.
- cmd/conformance-as/config.go: extract resolveClient's three
independent string-to-enum switches (client_auth_method,
sender_constrain, backchannel_token_delivery_mode) into their own
parseXxx helpers.
- internal/jose/jwk.go: extract ParseJWK's EC/RSA/OKP cases into their
own parse*PublicKey functions.
- keys/publicjwks.go: extract the "validate kid, dedup, build, append"
tail PublicJWKS's signing and encryption loops both duplicated
verbatim into a shared appendPublicJWK helper.
- resource/verify.go: extract Verify's DPoP/Bearer credential
-resolution switch into its own resolveCredential method.
- client/backchannel.go: extract the client-assertion/DPoP signer
-resolution block BeginBackchannelAuthentication and
PollBackchannelAuthentication both duplicated into a shared
resolveClientAuthAndDPoPSigners helper.
- client/flow_test.go: extract fakeAS.handleToken's three response
-mode branches (reject-plain, nonce-challenge, normal-issue) into
their own methods.
server/token.go's ExchangeAuthorizationCode was investigated and left
unchanged: its token-issuance tail already calls the same shared
helpers (issueIDToken, issueRefreshToken, withIdentityClaims,
withRequestedUserinfoClaims) that refresh.go and backchannel_token.go
reuse — no duplication left to extract, and the remaining complexity
is a flat validation checklist.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Summary
Addresses 11 of the 29 open go:S3776 (Cognitive Complexity) issues on SonarCloud, via pure mechanical extraction with no behavior change:
The remaining 18 issues are flat validation/checklist functions (e.g. client/client.go, server/server.go, storage/client_repository.go constructors) or large sequential test/harness setups where splitting would just scatter one audit-worthy list across files without improving readability — left as-is per this repo's own "don't refactor for a linter number alone" convention. server/token.go's ExchangeAuthorizationCode was specifically investigated for duplication and found to already reuse shared helpers (issueIDToken, issueRefreshToken, withIdentityClaims, withRequestedUserinfoClaims) with refresh.go/backchannel_token.go — nothing left to extract there.
Test plan
🤖 Generated with Claude Code
https://claude.ai/code/session_013tGG2Ssuq5BDgCMbF8zYb8