|
@@ -26,7 +26,6 @@ describe('AuthenticationManager', function() {
|
|
|
},
|
|
},
|
|
|
bcrypt: (this.bcrypt = {}),
|
|
bcrypt: (this.bcrypt = {}),
|
|
|
'settings-sharelatex': this.settings,
|
|
'settings-sharelatex': this.settings,
|
|
|
- '../V1/V1Handler': (this.V1Handler = {}),
|
|
|
|
|
'../User/UserGetter': (this.UserGetter = {}),
|
|
'../User/UserGetter': (this.UserGetter = {}),
|
|
|
'./AuthenticationErrors': AuthenticationErrors
|
|
'./AuthenticationErrors': AuthenticationErrors
|
|
|
}
|
|
}
|
|
@@ -99,6 +98,8 @@ describe('AuthenticationManager', function() {
|
|
|
_id: '5c8791477192a80b5e76ca7e',
|
|
_id: '5c8791477192a80b5e76ca7e',
|
|
|
email: (this.email = 'USER@sharelatex.com')
|
|
email: (this.email = 'USER@sharelatex.com')
|
|
|
}
|
|
}
|
|
|
|
|
+ this.db.users.updateOne = sinon
|
|
|
|
|
+ this.User.findOne = sinon.stub().callsArgWith(2, null, this.user)
|
|
|
this.db.users.updateOne = sinon
|
|
this.db.users.updateOne = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
.callsArgWith(2, null, { modifiedCount: 1 })
|
|
.callsArgWith(2, null, { modifiedCount: 1 })
|
|
@@ -106,7 +107,7 @@ describe('AuthenticationManager', function() {
|
|
|
|
|
|
|
|
it('should not produce an error', function(done) {
|
|
it('should not produce an error', function(done) {
|
|
|
this.AuthenticationManager.setUserPasswordInV2(
|
|
this.AuthenticationManager.setUserPasswordInV2(
|
|
|
- this.user._id,
|
|
|
|
|
|
|
+ this.user,
|
|
|
'testpassword',
|
|
'testpassword',
|
|
|
(err, updated) => {
|
|
(err, updated) => {
|
|
|
expect(err).to.not.exist
|
|
expect(err).to.not.exist
|
|
@@ -118,7 +119,7 @@ describe('AuthenticationManager', function() {
|
|
|
|
|
|
|
|
it('should set the hashed password', function(done) {
|
|
it('should set the hashed password', function(done) {
|
|
|
this.AuthenticationManager.setUserPasswordInV2(
|
|
this.AuthenticationManager.setUserPasswordInV2(
|
|
|
- this.user._id,
|
|
|
|
|
|
|
+ this.user,
|
|
|
'testpassword',
|
|
'testpassword',
|
|
|
err => {
|
|
err => {
|
|
|
expect(err).to.not.exist
|
|
expect(err).to.not.exist
|
|
@@ -224,7 +225,7 @@ describe('AuthenticationManager', function() {
|
|
|
|
|
|
|
|
it('should set the users password (with a higher number of rounds)', function() {
|
|
it('should set the users password (with a higher number of rounds)', function() {
|
|
|
this.AuthenticationManager.setUserPassword
|
|
this.AuthenticationManager.setUserPassword
|
|
|
- .calledWith('user-id', this.unencryptedPassword)
|
|
|
|
|
|
|
+ .calledWith(this.user, this.unencryptedPassword)
|
|
|
.should.equal(true)
|
|
.should.equal(true)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -258,7 +259,7 @@ describe('AuthenticationManager', function() {
|
|
|
|
|
|
|
|
it('should not set the users password (with a higher number of rounds)', function() {
|
|
it('should not set the users password (with a higher number of rounds)', function() {
|
|
|
this.AuthenticationManager.setUserPassword
|
|
this.AuthenticationManager.setUserPassword
|
|
|
- .calledWith('user-id', this.unencryptedPassword)
|
|
|
|
|
|
|
+ .calledWith(this.user, this.unencryptedPassword)
|
|
|
.should.equal(false)
|
|
.should.equal(false)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -525,11 +526,16 @@ describe('AuthenticationManager', function() {
|
|
|
describe('setUserPassword', function() {
|
|
describe('setUserPassword', function() {
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
this.user_id = ObjectId()
|
|
this.user_id = ObjectId()
|
|
|
|
|
+ this.user = {
|
|
|
|
|
+ _id: this.user_id,
|
|
|
|
|
+ email: 'user@example.com'
|
|
|
|
|
+ }
|
|
|
this.password = 'banana'
|
|
this.password = 'banana'
|
|
|
this.hashedPassword = 'asdkjfa;osiuvandf'
|
|
this.hashedPassword = 'asdkjfa;osiuvandf'
|
|
|
this.salt = 'saltaasdfasdfasdf'
|
|
this.salt = 'saltaasdfasdfasdf'
|
|
|
this.bcrypt.genSalt = sinon.stub().callsArgWith(2, null, this.salt)
|
|
this.bcrypt.genSalt = sinon.stub().callsArgWith(2, null, this.salt)
|
|
|
this.bcrypt.hash = sinon.stub().callsArgWith(2, null, this.hashedPassword)
|
|
this.bcrypt.hash = sinon.stub().callsArgWith(2, null, this.hashedPassword)
|
|
|
|
|
+ this.User.findOne = sinon.stub().callsArgWith(2, null, this.user)
|
|
|
this.db.users.updateOne = sinon.stub().callsArg(2)
|
|
this.db.users.updateOne = sinon.stub().callsArg(2)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -545,7 +551,7 @@ describe('AuthenticationManager', function() {
|
|
|
|
|
|
|
|
it('should return and error', function(done) {
|
|
it('should return and error', function(done) {
|
|
|
this.AuthenticationManager.setUserPassword(
|
|
this.AuthenticationManager.setUserPassword(
|
|
|
- this.user_id,
|
|
|
|
|
|
|
+ this.user,
|
|
|
this.password,
|
|
this.password,
|
|
|
err => {
|
|
err => {
|
|
|
expect(err).to.exist
|
|
expect(err).to.exist
|
|
@@ -556,7 +562,7 @@ describe('AuthenticationManager', function() {
|
|
|
|
|
|
|
|
it('should not start the bcrypt process', function(done) {
|
|
it('should not start the bcrypt process', function(done) {
|
|
|
this.AuthenticationManager.setUserPassword(
|
|
this.AuthenticationManager.setUserPassword(
|
|
|
- this.user_id,
|
|
|
|
|
|
|
+ this.user,
|
|
|
this.password,
|
|
this.password,
|
|
|
() => {
|
|
() => {
|
|
|
this.bcrypt.genSalt.called.should.equal(false)
|
|
this.bcrypt.genSalt.called.should.equal(false)
|
|
@@ -567,6 +573,42 @@ describe('AuthenticationManager', function() {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ describe('contains full email', function() {
|
|
|
|
|
+ beforeEach(function() {
|
|
|
|
|
+ this.password = `some${this.user.email}password`
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should reject the password', function(done) {
|
|
|
|
|
+ this.AuthenticationManager.setUserPassword(
|
|
|
|
|
+ this.user,
|
|
|
|
|
+ this.password,
|
|
|
|
|
+ err => {
|
|
|
|
|
+ expect(err).to.exist
|
|
|
|
|
+ expect(err.name).to.equal('InvalidPasswordError')
|
|
|
|
|
+ done()
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ describe('contains first part of email', function() {
|
|
|
|
|
+ beforeEach(function() {
|
|
|
|
|
+ this.password = `some${this.user.email.split('@')[0]}password`
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should reject the password', function(done) {
|
|
|
|
|
+ this.AuthenticationManager.setUserPassword(
|
|
|
|
|
+ this.user,
|
|
|
|
|
+ this.password,
|
|
|
|
|
+ err => {
|
|
|
|
|
+ expect(err).to.exist
|
|
|
|
|
+ expect(err.name).to.equal('InvalidPasswordError')
|
|
|
|
|
+ done()
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
describe('too short', function() {
|
|
describe('too short', function() {
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
this.settings.passwordStrengthOptions = {
|
|
this.settings.passwordStrengthOptions = {
|
|
@@ -580,7 +622,7 @@ describe('AuthenticationManager', function() {
|
|
|
|
|
|
|
|
it('should return and error', function(done) {
|
|
it('should return and error', function(done) {
|
|
|
this.AuthenticationManager.setUserPassword(
|
|
this.AuthenticationManager.setUserPassword(
|
|
|
- this.user_id,
|
|
|
|
|
|
|
+ this.user,
|
|
|
this.password,
|
|
this.password,
|
|
|
err => {
|
|
err => {
|
|
|
expect(err).to.exist
|
|
expect(err).to.exist
|
|
@@ -591,7 +633,7 @@ describe('AuthenticationManager', function() {
|
|
|
|
|
|
|
|
it('should not start the bcrypt process', function(done) {
|
|
it('should not start the bcrypt process', function(done) {
|
|
|
this.AuthenticationManager.setUserPassword(
|
|
this.AuthenticationManager.setUserPassword(
|
|
|
- this.user_id,
|
|
|
|
|
|
|
+ this.user,
|
|
|
this.password,
|
|
this.password,
|
|
|
() => {
|
|
() => {
|
|
|
this.bcrypt.genSalt.called.should.equal(false)
|
|
this.bcrypt.genSalt.called.should.equal(false)
|
|
@@ -606,7 +648,7 @@ describe('AuthenticationManager', function() {
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
this.UserGetter.getUser = sinon.stub().yields(null, { overleaf: null })
|
|
this.UserGetter.getUser = sinon.stub().yields(null, { overleaf: null })
|
|
|
this.AuthenticationManager.setUserPassword(
|
|
this.AuthenticationManager.setUserPassword(
|
|
|
- this.user_id,
|
|
|
|
|
|
|
+ this.user,
|
|
|
this.password,
|
|
this.password,
|
|
|
this.callback
|
|
this.callback
|
|
|
)
|
|
)
|