Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions backend/src/middleware/__tests__/jwtAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,26 @@ describe('jwtAuth middleware', () => {
);
});

it('should reject access when any one of multiple required scopes is missing', () => {
mockRequest.user = {
publicKey: 'GBORROWER',
role: 'borrower',
scopes: ['read:loans'],
iat: 1000,
exp: 2000,
};

const middleware = requireScopes('read:loans', 'write:repayment');

expect(() => middleware(mockRequest as Request, mockResponse as Response, mockNext)).toThrow(
expect.objectContaining({
statusCode: 403,
message: 'Missing required scope: write:repayment',
}),
);
expect(mockNext).not.toHaveBeenCalled();
});

it('should grant access when user has all required scopes', () => {
mockRequest.user = {
publicKey: 'GBORROWER',
Expand Down
Loading