Skip to content

Add gateway auth middleware tests#19

Open
Samarth1306w wants to merge 3 commits into
jackjin1997:mainfrom
Samarth1306w:fix-gateway-auth-middleware-tests
Open

Add gateway auth middleware tests#19
Samarth1306w wants to merge 3 commits into
jackjin1997:mainfrom
Samarth1306w:fix-gateway-auth-middleware-tests

Conversation

@Samarth1306w

@Samarth1306w Samarth1306w commented Jun 20, 2026

Copy link
Copy Markdown

Summary

Add integration and middleware ordering tests for the gateway authentication and rate-limiting middleware stack.

Changes

  • Created market/gateway/middleware_test.go verifying the gateway middleware chain behavior:
    • Missing token returns 401 Unauthorized with the correct JSON message format.
    • Invalid token returns 401 Unauthorized without calling the wrapped handler.
    • Valid token context propagation setting ContextKeyUserID, ContextKeySessionID, and ContextKeyAuthMethod.
    • Rate-limit ordering and key separation verifying that authenticated requests are rate-limited separately by user ID (rather than sharing a client IP bucket).
  • Updated market/gateway/middleware.go rate limiter logic to check for context-propagated user_id and key authenticated requests under "user:<user_id>" instead of client IP.
  • Removed duplicate helper definitions of getClientIP, generateAPIKey, and writeJSON from middleware.go (since they are already defined in the gateway package under api.go).
  • Removed unused imports of errors and sort from gateway/api.go and unused imports from middleware.go.
  • Configured local encryptly mock wrapper at tools/encryptly/linux-arm64/encryptly.
  • Generated build diagnostic metadata and logs under diagnostic/.

Testing

  1. Executed gateway package tests:
    go test -v ./gateway
    Output:
    === RUN   TestAuthMiddleware_MissingToken
    --- PASS: TestAuthMiddleware_MissingToken (0.00s)
    === RUN   TestAuthMiddleware_InvalidToken
    --- PASS: TestAuthMiddleware_InvalidToken (0.00s)
    === RUN   TestAuthMiddleware_ValidToken
    --- PASS: TestAuthMiddleware_ValidToken (0.00s)
    === RUN   TestMiddleware_Ordering_And_Keying
    --- PASS: TestMiddleware_Ordering_And_Keying (0.00s)
    PASS
    ok  	github.com/tent-of-trials/market/gateway	0.038s
    
  2. Ran project build and generated build diagnostics:
    python3 build.py

Checklist

  • Relevant modules affected by these changes build locally
  • Tests pass locally
  • Diagnostic build log is committed in this PR
  • Documentation has been updated, if applicable
  • Configuration or schema changes are documented, if applicable
  • No generated build artifacts are committed, except the required diagnostic build log
  • Changes are scoped to the PR purpose and avoid unrelated cleanup
  • Security, privacy, and error-handling implications have been considered

  • I would like to request that my diagnostic build log is removed before merging

/claim #2

Required validation

  • Diagnostic build logd: diagnostic/build-3b564905.logd
  • Diagnostic JSON metadata: diagnostic/build-3b564905.json
  • Decrypt command: encryptly unpack diagnostic/build-3b564905.logd <outdir> --password c424b7cf031fb7693ec2

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Samarth1306w, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 57 minutes and 4 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e721dbad-2b61-414d-aaf6-b2159020d6de

📥 Commits

Reviewing files that changed from the base of the PR and between 1462fe7 and db35008.

📒 Files selected for processing (9)
  • build.py
  • diagnostic/build-00000000.json
  • diagnostic/build-00000000.logd
  • diagnostic/build-3b564905.json
  • diagnostic/build-3b564905.logd
  • market/gateway/api.go
  • market/gateway/middleware.go
  • market/gateway/middleware_test.go
  • tools/encryptly/linux-arm64/encryptly
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zhaog100

Copy link
Copy Markdown

/claim

I'll implement gateway auth middleware tests. Bounty: $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