1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-19 01:17:18 +02:00

fix: Password hash is null should yield PasswordMissmatch (#4392)

We are giving a strange error message if the user does not have a
password_hash defined in the database.
This commit is contained in:
Ivar Conradi Østhus 2023-08-03 08:51:13 +02:00 committed by GitHub
parent 1017260c00
commit 5377243afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

@ -296,13 +296,12 @@ class UserService {
? { email: usernameOrEmail }
: { username: usernameOrEmail };
let user;
let user, passwordHash;
try {
user = await this.store.getByQuery(idQuery);
passwordHash = await this.store.getPasswordHash(user.id);
} catch (error) {}
if (user) {
const passwordHash = await this.store.getPasswordHash(user.id);
if (user && passwordHash) {
const match = await bcrypt.compare(password, passwordHash);
if (match) {
await this.store.successfullyLogin(user);

View File

@ -122,6 +122,25 @@ test('should not be able to login with deleted user', async () => {
);
});
test('should not be able to login without password_hash on user', async () => {
const user = await userService.createUser({
username: 'deleted_user',
password: 'unleash4all',
rootRole: adminRole.id,
});
/*@ts-ignore: we are testing for null on purpose! */
await userStore.setPasswordHash(user.id, null);
await expect(
userService.loginUser('deleted_user', 'anything-should-fail'),
).rejects.toThrow(
new PasswordMismatch(
`The combination of password and username you provided is invalid. If you have forgotten your password, visit /forgotten-password or get in touch with your instance administrator.`,
),
);
});
test('should not login user if simple auth is disabled', async () => {
await settingService.insert(
simpleAuthSettingsKey,