Refactor auth module: enhance comments, improve token handling, and add admin dispute override functionality#672
Open
somotochukwu-dev wants to merge 1 commit into
Conversation
…dd admin dispute override functionality
|
@Dubemtopsite is attempting to deploy a commit to the mAzI's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@somotochukwu-dev 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.
BE-W3A-108: Secure Admin Signature Overrides for Platform Disputes
Summary
Implements secure admin signature overrides for platform disputes, enabling authenticated platform arbiters (admins) to override dispute verdicts by signing override authorizations with their Stellar wallet (SEP-53/Freighter-compatible). Also fixes several pre-existing code quality issues in the auth module and adds comprehensive test coverage.
Changes
backend/src/routes/auth.ts/verifyhandler (lines 693-787) that was not registered as a route and would never executeextractSignatureString()was missing its closing}, causingdecodeSignature(raw: string)to be syntactically nested inside itdecodeSignatureoverload — Renamed the internaldecodeSignature(raw: string)todecodeSignatureBytesto resolve a TypeScript duplicate function implementation error (both functions shared the same name with different signatures)createAuthRouter(deps)factory — Accepts{ prismaClient, redisClient }for dependency injection, allowing unit tests to pass in-memory mocks without any I/O. The default export (router) continues to use production Prisma/RedisnormalizeStellarAddress— Public alias forsanitizeStellarAddressisChallengeExpired— Returnstruewhen the given date is in the pastisSessionRevoked(client, token)— Redis blacklist check with a 5ms timeout budget (viaPromise.race), matching existingisSessionBlacklistedbut accepting an explicit Redis client for testabilityPOST /admin/dispute/:id/override— Secure endpoint protected by:authGuard— Validates JWT access tokenrequireRole("admin")— Ensures JWT carries admin roleDispute,Winner,Freelancer Share Basis Points,Adminaddress) with their wallet; the signature is verified against the admin's Stellar address from the JWTverdictsrecord overriding the original dispute outcomebackend/src/middleware/authGuard.tsreq.cookiesaccess to use optional chaining (req.cookies?.[ACCESS_TOKEN_COOKIE]) to preventTypeErrorwhencookie-parsermiddleware is not mounted in test environmentsbackend/package.json"scripts"section was causing all Node.js tooling (ts-node, npm) to fail with parse errorsbackend/tests/auth.test.tsprocess.env.JWT_SECRETat top of file (needed byissueAccessToken)jwtimport for admin override testsnormalizeStellarAddress mirrors sanitizeStellarAddressisChallengeExpired returns true for past dates and false for future datesadmin override rejects request without authorized JWT(401)admin override rejects valid JWT without admin role(403)admin override rejects invalid Stellar signature on override message(401)admin override succeeds with valid JWT admin role and correct Stellar signature(200)prismaClientto include$transaction,refresh_tokens,arbiters,disputes, andverdictstablesrejects request without authorized JWT(was callingapp.listen(0)without saving/closing the server)backend/scripts/auth-helpers.test.tsnormalizeStellarAddress,isChallengeExpired,decodeSignatureare all exported)Acceptance Criteria Met
verifyStellarSignature+ new factory integration testisSessionRevokedtimeout testRunning the Tests
cd backend node --require ts-node/register --test tests/auth.test.tsAll 12 tests pass.
Closes #462