Skip to content

Commit 1ae893b

Browse files
authored
Fix minor bug where invalid password triggered sentry (#229)
1 parent 5aa92b2 commit 1ae893b

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎packages/db-service/src/modules/user/user.controller.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ export class UserController implements UserProto.UserServiceController {
5151
): Promise<UserProto.UserPasswordHash> {
5252
const userFind = validate.validateUserIdentifier(identifier);
5353
const user = await this.userService.user(userFind);
54+
55+
if (!user) {
56+
throw new RpcException({
57+
code: status.NOT_FOUND,
58+
message: 'User not found',
59+
});
60+
}
61+
5462
return {
5563
hash: user.password,
5664
};

‎packages/db-service/test/user.e2e-spec.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,42 @@ describe('DB Service User Tests', () => {
434434
await getUserPasswordHashPromise;
435435
});
436436

437+
it('throws NOT_FOUND error when getting password hash for non-existent user by email', async () => {
438+
const promise = new Promise((resolve) => {
439+
userClient.getUserPasswordHash(
440+
{
441+
email: 'nonexistent@test.com',
442+
},
443+
(err) => {
444+
expect(err).toBeDefined();
445+
expect(err.code).toBe(GRPC.status.NOT_FOUND);
446+
expect(err.details).toBe('User not found');
447+
resolve({});
448+
},
449+
);
450+
});
451+
452+
await promise;
453+
});
454+
455+
it('throws NOT_FOUND error when getting password hash for non-existent user by id', async () => {
456+
const promise = new Promise((resolve) => {
457+
userClient.getUserPasswordHash(
458+
{
459+
id: 99999,
460+
},
461+
(err) => {
462+
expect(err).toBeDefined();
463+
expect(err.code).toBe(GRPC.status.NOT_FOUND);
464+
expect(err.details).toBe('User not found');
465+
resolve({});
466+
},
467+
);
468+
});
469+
470+
await promise;
471+
});
472+
437473
it('throws an error when both id and email are provided', async () => {
438474
const promise = new Promise((resolve) => {
439475
userClient.updateUser(

0 commit comments

Comments
 (0)