mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
Merge pull request #12342 from overleaf/jk-password-ux-please-use-another-password
[web] Password UX: 'Please use another password' GitOrigin-RevId: ca9b26cbcf2dabb27c716da314764ee40ffc83dd
This commit is contained in:
@@ -200,7 +200,11 @@ describe('PasswordReset', function () {
|
||||
expect(response.status).to.equal(400)
|
||||
const body = await response.json()
|
||||
expect(body).to.deep.equal({
|
||||
message: { text: 'Password cannot contain parts of email address' },
|
||||
message: {
|
||||
type: 'error',
|
||||
key: 'password-contains-email',
|
||||
text: 'Password cannot contain parts of email address',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@@ -223,7 +227,11 @@ describe('PasswordReset', function () {
|
||||
expect(response.status).to.equal(400)
|
||||
const body = await response.json()
|
||||
expect(body).to.deep.equal({
|
||||
message: { text: 'Password is too similar to email address' },
|
||||
message: {
|
||||
type: 'error',
|
||||
key: 'password-too-similar',
|
||||
text: 'Password is too similar to parts of email address',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -133,7 +133,43 @@ describe('PasswordUpdate', function () {
|
||||
})
|
||||
it('should return error message', async function () {
|
||||
const body = await response.json()
|
||||
expect(body.message).to.equal('password is too short')
|
||||
expect(body.message).to.deep.equal({
|
||||
type: 'error',
|
||||
key: 'password-too-short',
|
||||
text: 'Password too short, minimum 8',
|
||||
})
|
||||
})
|
||||
it('should not update audit log', async function () {
|
||||
const auditLog = userHelper.getAuditLogWithoutNoise()
|
||||
expect(auditLog).to.deep.equal([])
|
||||
})
|
||||
})
|
||||
describe('new password contains part of email', function () {
|
||||
beforeEach(async function () {
|
||||
response = await userHelper.fetch('/user/password/update', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
currentPassword: password,
|
||||
newPassword1: 'somecooluser123',
|
||||
newPassword2: 'somecooluser123',
|
||||
}),
|
||||
})
|
||||
userHelper = await UserHelper.getUser({ email })
|
||||
})
|
||||
it('should return 400', async function () {
|
||||
expect(response.status).to.equal(400)
|
||||
})
|
||||
it('should return error message', async function () {
|
||||
const body = await response.json()
|
||||
expect(body.message).to.deep.equal({
|
||||
key: 'password-contains-email',
|
||||
type: 'error',
|
||||
text: 'Password cannot contain parts of email address',
|
||||
})
|
||||
})
|
||||
it('should not update audit log', async function () {
|
||||
const auditLog = userHelper.getAuditLogWithoutNoise()
|
||||
@@ -161,9 +197,11 @@ describe('PasswordUpdate', function () {
|
||||
})
|
||||
it('should return error message', async function () {
|
||||
const body = await response.json()
|
||||
expect(body.message).to.equal(
|
||||
'Password is too similar to email address'
|
||||
)
|
||||
expect(body.message).to.deep.equal({
|
||||
key: 'password-too-similar',
|
||||
type: 'error',
|
||||
text: 'Password is too similar to parts of email address',
|
||||
})
|
||||
})
|
||||
it('should not update audit log', async function () {
|
||||
const auditLog = userHelper.getAuditLogWithoutNoise()
|
||||
|
||||
@@ -61,6 +61,9 @@ describe('UserController', function () {
|
||||
authenticate: sinon.stub(),
|
||||
setUserPassword: sinon.stub(),
|
||||
},
|
||||
getMessageForInvalidPasswordError: sinon
|
||||
.stub()
|
||||
.returns({ type: 'error', key: 'some-key' }),
|
||||
}
|
||||
this.UserUpdater = {
|
||||
changeEmailAddress: sinon.stub(),
|
||||
@@ -771,18 +774,21 @@ describe('UserController', function () {
|
||||
// .returns({ message: 'validation-error' })
|
||||
const err = new Error('bad')
|
||||
err.name = 'InvalidPasswordError'
|
||||
const message = {
|
||||
type: 'error',
|
||||
key: 'some-message-key',
|
||||
}
|
||||
this.AuthenticationManager.getMessageForInvalidPasswordError.returns(
|
||||
message
|
||||
)
|
||||
this.AuthenticationManager.promises.setUserPassword.rejects(err)
|
||||
this.AuthenticationManager.promises.authenticate.resolves({})
|
||||
this.req.body = {
|
||||
newPassword1: 'newpass',
|
||||
newPassword2: 'newpass',
|
||||
}
|
||||
this.HttpErrorHandler.badRequest.callsFake(() => {
|
||||
expect(this.HttpErrorHandler.badRequest).to.have.been.calledWith(
|
||||
this.req,
|
||||
this.res,
|
||||
err.message
|
||||
)
|
||||
this.res.json.callsFake(result => {
|
||||
expect(result.message).to.deep.equal(message)
|
||||
this.AuthenticationManager.promises.setUserPassword.callCount.should.equal(
|
||||
1
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user