Merge pull request #11436 from overleaf/jk-increase-password-min-length-to-8

[web] Increase the minimum password length to 8 characters

GitOrigin-RevId: 94eb3c5605183b5e189babd3342dc308f403ebbd
This commit is contained in:
June Kelly
2023-02-02 09:02:56 +00:00
committed by Copybot
parent f532abfd1c
commit be7b424a63
5 changed files with 43 additions and 5 deletions
@@ -12,6 +12,7 @@ describe('AuthenticationManager', function () {
beforeEach(function () {
tk.freeze(Date.now())
this.settings = { security: { bcryptRounds: 4 } }
this.metrics = { inc: sinon.stub().returns() }
this.AuthenticationManager = SandboxedModule.require(modulePath, {
requires: {
'../../models/User': {
@@ -34,6 +35,7 @@ describe('AuthenticationManager', function () {
'../User/UserAuditLogHandler': (this.UserAuditLogHandler = {
addEntry: sinon.stub().callsArgWith(5, null),
}),
'@overleaf/metrics': this.metrics,
},
})
this.callback = sinon.stub()
@@ -63,6 +65,7 @@ describe('AuthenticationManager', function () {
}
this.user.hashedPassword = this.testPassword
this.User.findOne = sinon.stub().callsArgWith(1, null, this.user)
this.metrics.inc.reset()
})
describe('when the hashed password matches', function () {
@@ -98,6 +101,12 @@ describe('AuthenticationManager', function () {
it('should return the user', function () {
this.callback.calledWith(null, this.user).should.equal(true)
})
it('should send metrics', function () {
expect(
this.metrics.inc.calledWith('check-password', { status: 'success' })
).to.equal(true)
})
})
describe('when the encrypted passwords do not match', function () {
@@ -128,6 +137,10 @@ describe('AuthenticationManager', function () {
it('should not return the user', function () {
this.callback.calledWith(null, null).should.equal(true)
})
it('should not send metrics', function () {
expect(this.metrics.inc.called).to.equal(false)
})
})
describe('when another request runs in parallel', function () {
@@ -240,6 +253,7 @@ describe('AuthenticationManager', function () {
}
this.unencryptedPassword = 'banana'
this.User.findOne = sinon.stub().callsArgWith(1, null, this.user)
this.metrics.inc.reset()
})
describe('when the hashed password matches', function () {
@@ -267,6 +281,14 @@ describe('AuthenticationManager', function () {
.should.equal(true)
})
it('should send metrics', function () {
expect(
this.metrics.inc.calledWith('check-password', {
status: 'too_short',
})
).to.equal(true)
})
it('should return the user', function () {
this.callback.calledWith(null, this.user).should.equal(true)
})
@@ -283,6 +305,10 @@ describe('AuthenticationManager', function () {
)
})
it('should not send metrics', function () {
expect(this.metrics.inc.called).to.equal(false)
})
it('should not return the user', function () {
this.callback.calledWith(null, null).should.equal(true)
this.UserAuditLogHandler.addEntry.callCount.should.equal(0)
@@ -649,7 +675,7 @@ describe('AuthenticationManager', function () {
describe('setUserPassword', function () {
beforeEach(function () {
this.user_id = ObjectId()
this.password = 'banana'
this.password = 'bananagram'
this.hashedPassword = 'asdkjfa;osiuvandf'
this.salt = 'saltaasdfasdfasdf'
this.user = {