Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/validate access token user not found #8484

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,13 @@ describe('JwtAuthStrategy', () => {
);

await expect(strategy.validate(payload as JwtPayload)).rejects.toThrow(
new AuthException('User not found', AuthExceptionCode.INVALID_INPUT),
new AuthException('User not found', expect.any(String)),
);
try {
await strategy.validate(payload as JwtPayload);
} catch (e) {
expect(e.code).toBe(AuthExceptionCode.USER_NOT_FOUND);
}
Comment on lines 153 to +160
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Redundant error testing - the second test using try/catch is unnecessary since Jest's rejects.toThrow() can check both message and code using a matcher object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well... that seems to be wrong, following this comment jestjs/jest#13232 (comment)

However there might be a more elegant way using another matcher inside the .toThrow, but I don't quite have the syntax.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good enough like this imo! Thanks a lot!

});

it('should be truthy if type is ACCESS, no jti, and user exist', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class JwtAuthStrategy extends PassportStrategy(Strategy, 'jwt') {
if (!user) {
throw new AuthException(
'User not found',
AuthExceptionCode.INVALID_INPUT,
AuthExceptionCode.USER_NOT_FOUND,
);
}

Expand Down
Loading