1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-06 09:19:22 +02:00

Server: throwing an error if the password being saved already seems to be hashed (#8637)

This commit is contained in:
pedr
2023-08-08 07:15:03 -03:00
committed by GitHub
parent 3d4740203f
commit 3b1a726a23
5 changed files with 55 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
import { createUserAndSession, beforeAllDb, afterAllTests, beforeEachDb, models, checkThrowAsync, expectThrow } from '../utils/testing/testUtils';
import { EmailSender, UserFlagType } from '../services/database/types';
import { ErrorUnprocessableEntity } from '../utils/errors';
import { ErrorBadRequest, ErrorUnprocessableEntity } from '../utils/errors';
import { betaUserDateRange, stripeConfig } from '../utils/stripe';
import { accountByType, AccountType } from './UserModel';
import { failedPaymentFinalAccount, failedPaymentWarningInterval } from './SubscriptionModel';
@@ -425,4 +425,13 @@ describe('UserModel', () => {
expect((await models().user().load(user1.id)).enabled).toBe(0);
});
test('should throw an error if the password being saved seems to be hashed', async () => {
const passwordSimilarToHash = '$2a$10';
const error = await checkThrowAsync(async () => await models().user().save({ password: passwordSimilarToHash }));
expect(error.message).toBe('Unable to save user because password already seems to be hashed. User id: undefined');
expect(error instanceof ErrorBadRequest).toBe(true);
});
});