test: add edge-case coverage for POST /api/auth/refresh - #748
Merged
Conversation
Expands the refresh-route test suite from 7 to 15 tests, covering gaps identified during the mux-labs#745 audit: - Cookie secure flag when NODE_ENV=production - Caller's cookie header forwarded to upstream backend - Upstream auth headers (x-api-key, x-api-secret) propagated - Request body forwarded to backend - extractSessionToken handling all three response keys (token, accessToken, sessionToken) - No cookie set when backend response has no token field - Descriptive error message present in 503 response Also adds src/app/api/** to the default vitest coverage include list so route handler tests count toward reported coverage numbers. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
…cases test: add edge-case coverage for POST /api/auth/refresh
|
@Sundayabel222 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #656
Closes #657
Closes #658
Closes #659
Summary
Expands the
POST /api/auth/refreshroute test suite from 7 → 15 tests, filling coverage gaps identified in the #745 audit. Also fixes the vitest coverage config so API route tests count toward reported numbers.What changed
src/app/api/auth/refresh/route.test.ts— 8 new testssets secure flag on the session cookie when NODE_ENV=productionsecure: truein prod builds was untestedforwards the caller's cookie header to the upstreamCookieheader reaching the backend wasn't verifiedforwards upstream auth headers (x-api-key, x-api-secret)getUpstreamAuthHeaders()propagation was untestedforwards the request body to the upstreamrecognises the sessionToken key for cookie rotationextractSessionTokenwithsessionTokenkey wasn't testedrecognises the token key for cookie rotationextractSessionTokenwithtokenkey wasn't testeddoes not set a session cookie when the backend returns no token fieldreturns 503 with a descriptive messagevitest.config.ts— coverage config fixAdded
"src/app/api/**"to the defaultcoverage.includelist. Previously, route handler tests ran but didn't count toward reported coverage (only the separatevitest.coverage.full.config.tsincluded them).Why
The refresh route is the production auth renewal path —
src/lib/api.jsandsrc/utils/fetchWithAuth.tsboth call it on 401. Without edge-case coverage:secureflag could leak session tokens over HTTP in productionextractSessionTokenkey variants (token,accessToken,sessionToken) could silently stop rotating cookiesVerification
```bash
pnpm vitest run src/app/api/auth/refresh/route.test.ts
✓ 15 tests passed
```
All 15 tests pass. The pre-existing logout route test failure (
POST()missing aRequestarg) is unrelated and exists onstaging.Related
/api/auth/refreshreturns503 backend_unavailablewhen no backend is configured in production — no silent mock successNEXT_PUBLIC_*orlocalStorage— verified via test assertions on cookie attributes🤖 Generated with Codebuff
Co-Authored-By: Codebuff noreply@codebuff.com