diff --git a/services/web/test/unit/coffee/Authentication/AuthenticationManagerTests.coffee b/services/web/test/unit/coffee/Authentication/AuthenticationManagerTests.coffee index 0a041a0865..be2ed44979 100644 --- a/services/web/test/unit/coffee/Authentication/AuthenticationManagerTests.coffee +++ b/services/web/test/unit/coffee/Authentication/AuthenticationManagerTests.coffee @@ -94,6 +94,48 @@ describe "AuthenticationManager", -> it "should not return a user", -> @callback.calledWith(null, null).should.equal true + describe "validateEmail", -> + describe "valid", -> + it "should return null", -> + result = @AuthenticationManager.validateEmail 'foo@example.com' + expect(result).to.equal null + + describe "invalid", -> + it "should return validation error object for no email", -> + result = @AuthenticationManager.validateEmail '' + expect(result).to.not.equal null + expect(result.message).to.equal 'email not valid' + + it "should return validation error object for invalid", -> + result = @AuthenticationManager.validateEmail 'notanemail' + expect(result).to.not.equal null + expect(result.message).to.equal 'email not valid' + + describe "validatePassword", -> + it "should return null if valid", -> + result = @AuthenticationManager.validatePassword 'banana' + expect(result).to.equal null + + describe "invalid", -> + beforeEach -> + @settings.passwordStrengthOptions = + length: + max:10 + min:6 + + it "should return validation error object if not set", -> + result = @AuthenticationManager.validatePassword() + expect(result).to.not.equal null + expect(result.message).to.equal 'password not set' + + it "should return validation error object if too short", -> + result = @AuthenticationManager.validatePassword 'dsd' + expect(result).to.not.equal null + expect(result.message).to.equal 'password is too short' + + it "should return validation error object if too long", -> + result = @AuthenticationManager.validatePassword 'dsdsadsadsadsadsadkjsadjsadjsadljs' + describe "setUserPassword", -> beforeEach -> @user_id = ObjectId() diff --git a/services/web/test/unit/coffee/User/UserRegistrationHandlerTests.coffee b/services/web/test/unit/coffee/User/UserRegistrationHandlerTests.coffee index f8bcce30ce..7fcd2147a5 100644 --- a/services/web/test/unit/coffee/User/UserRegistrationHandlerTests.coffee +++ b/services/web/test/unit/coffee/User/UserRegistrationHandlerTests.coffee @@ -19,6 +19,8 @@ describe "UserRegistrationHandler", -> @UserCreator = createNewUser:sinon.stub().callsArgWith(1, null, @user) @AuthenticationManager = + validateEmail: sinon.stub().returns(null) + validatePassword: sinon.stub().returns(null) setUserPassword: sinon.stub().callsArgWith(2) @NewsLetterManager = subscribe: sinon.stub().callsArgWith(1) @@ -44,28 +46,25 @@ describe "UserRegistrationHandler", -> describe 'validate Register Request', -> - - - it 'allow working account through', -> + it 'allows passing validation through', -> result = @handler._registrationRequestIsValid @passingRequest result.should.equal true - - it 'not allow not valid email through ', ()-> - @passingRequest.email = "notemail" - result = @handler._registrationRequestIsValid @passingRequest - result.should.equal false - it 'not allow no email through ', -> - @passingRequest.email = "" - result = @handler._registrationRequestIsValid @passingRequest - result.should.equal false - - it 'not allow no password through ', ()-> - @passingRequest.password= "" - result = @handler._registrationRequestIsValid @passingRequest - result.should.equal false + describe 'failing email validation', -> + beforeEach -> + @AuthenticationManager.validateEmail.returns({ message: 'email not set' }) + it 'does not allow through', -> + result = @handler._registrationRequestIsValid @passingRequest + result.should.equal false + describe 'failing password validation', -> + beforeEach -> + @AuthenticationManager.validatePassword.returns({ message: 'password is too short' }) + + it 'does not allow through', -> + result = @handler._registrationRequestIsValid @passingRequest + result.should.equal false describe "registerNewUser", ->