Merge pull request #17409 from overleaf/jpa-check-before-hibp

[web] check user password before HIBP check

GitOrigin-RevId: 7c1bdc220fb9369733a1ff3bf26bed8cacc8e8d4
This commit is contained in:
Jakob Ackermann
2024-03-05 09:03:46 +00:00
committed by Copybot
parent 84a2b25a3c
commit 9daacea6cb
3 changed files with 93 additions and 95 deletions
@@ -85,11 +85,17 @@ describe('HaveIBeenPwnedApi', function () {
beforeEach('login', async function () {
try {
await user.loginNoUpdate()
} catch (e) {
expect(e.message).to.include('password-compromised')
return
expect.fail('should have failed login with weak password')
} catch (err) {
expect(err).to.match(/login failed: status=400/)
expect(err.info.body).to.deep.equal({
message: {
type: 'error',
key: 'password-compromised',
text: `The password youve entered is on a public list of compromised passwords (https://haveibeenpwned.com). Please try logging in from a device youve previously used or reset your password (${Settings.siteUrl}/user/password/reset).`,
},
})
}
expect.fail('should have failed login with weak password')
})
it('should track the weak password', async function () {
const after = await getMetricReUsed()
@@ -160,19 +166,15 @@ describe('HaveIBeenPwnedApi', function () {
await user.loginWithEmailPassword(user.email, 'aLeakedPassword42')
expect.fail('expected the login request to fail')
} catch (err) {
expect(err).to.match(/login failed: status=400/)
expect(err).to.match(/login failed: status=401/)
expect(err.info.body).to.deep.equal({
message: {
type: 'error',
key: 'password-compromised',
text: `The password youve entered is on a public list of compromised passwords (https://haveibeenpwned.com). Please check its correct and try again. Alternatively, try logging in from a device youve previously used or reset your password (${Settings.siteUrl}/user/password/reset).`,
},
message: { type: 'error', key: 'invalid-password-retry-or-reset' },
})
}
})
it('should increment the counter', async function () {
it('should not increment the counter', async function () {
expect(previous).to.deep.equal({
reUsed: (await getMetricReUsed()) - 1,
reUsed: await getMetricReUsed(),
unique: await getMetricUnique(),
failure: await getMetricFailure(),
})