Skip to content

Add tests for /v1/oauth/authorize PKCE endpoint#696

Merged
rickyrombo merged 2 commits intomjp-oauth-endpointsfrom
copilot/sub-pr-686
Mar 9, 2026
Merged

Add tests for /v1/oauth/authorize PKCE endpoint#696
rickyrombo merged 2 commits intomjp-oauth-endpointsfrom
copilot/sub-pr-686

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

The /v1/oauth/authorize endpoint (entry point to the PKCE flow) had no test coverage, leaving happy paths, validation logic, and grant enforcement untested.

Changes

  • makeOAuthJWT helper: generates valid Ethereum personal-signed JWTs using a fixed test private key, replicating the exact signing format validated by validateOAuthJWTTokenToUserId
  • seedOAuthTestData update: user 100's wallet updated to the address derived from the test private key, enabling real JWT verification against the DB in authorize tests
  • 10 new test cases for POST /v1/oauth/authorize:
    • Happy path: read scope and write scope with an approved grant
    • Required-field validation: missing token, client_id, redirect_uri, code_challenge, scope400 invalid_request
    • code_challenge_method must be S256400 invalid_request
    • Invalid scope value → 400 invalid_request
    • Invalid/unsigned JWT → 401 access_denied
    • Unknown client_id400 invalid_client
    • write scope with no approved grant → 403 access_denied
// makeOAuthJWT signs a JWT with a known test private key whose wallet
// is seeded into the users table, enabling full JWT validation in tests.
func makeOAuthJWT(t *testing.T, userID int, privKeyHex string) string {
    privKey, _ := crypto.HexToECDSA(privKeyHex)
    message := header + "." + base64url(payload)
    sig := crypto.Sign(keccak256(ethereumPrefix+message), privKey)
    return message + "." + base64url(hexEncode(sig))
}

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…ion, invalid token, unknown client, write scope grant enforcement

Co-authored-by: rickyrombo <3690498+rickyrombo@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback on adding OAuth 2.0 endpoints Add tests for /v1/oauth/authorize PKCE endpoint Mar 9, 2026
@rickyrombo rickyrombo marked this pull request as ready for review March 9, 2026 18:02
@rickyrombo rickyrombo merged commit ce76931 into mjp-oauth-endpoints Mar 9, 2026
4 checks passed
@rickyrombo rickyrombo deleted the copilot/sub-pr-686 branch March 9, 2026 18:03
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