|
@@ -20,7 +20,7 @@ describe "AuthenticationController", ->
|
|
|
"../Security/LoginRateLimiter": @LoginRateLimiter = { processLoginRequest:sinon.stub(), recordSuccessfulLogin:sinon.stub() }
|
|
"../Security/LoginRateLimiter": @LoginRateLimiter = { processLoginRequest:sinon.stub(), recordSuccessfulLogin:sinon.stub() }
|
|
|
"../User/UserHandler": @UserHandler = {setupLoginData:sinon.stub()}
|
|
"../User/UserHandler": @UserHandler = {setupLoginData:sinon.stub()}
|
|
|
"../Analytics/AnalyticsManager": @AnalyticsManager = { recordEvent: sinon.stub() }
|
|
"../Analytics/AnalyticsManager": @AnalyticsManager = { recordEvent: sinon.stub() }
|
|
|
- "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
|
|
|
|
|
|
+ "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), err: sinon.stub() }
|
|
|
"settings-sharelatex": {}
|
|
"settings-sharelatex": {}
|
|
|
"passport": @passport =
|
|
"passport": @passport =
|
|
|
authenticate: sinon.stub().returns(sinon.stub())
|
|
authenticate: sinon.stub().returns(sinon.stub())
|
|
@@ -50,6 +50,10 @@ describe "AuthenticationController", ->
|
|
|
@info = null
|
|
@info = null
|
|
|
@req.login = sinon.stub().callsArgWith(1, null)
|
|
@req.login = sinon.stub().callsArgWith(1, null)
|
|
|
@res.json = sinon.stub()
|
|
@res.json = sinon.stub()
|
|
|
|
|
+ @req.session = @session = {test: 'test'}
|
|
|
|
|
+ @req.session.destroy = sinon.stub()
|
|
|
|
|
+ @req.session.save = sinon.stub().callsArgWith(0, null)
|
|
|
|
|
+ @req.sessionStore = {generate: sinon.stub()}
|
|
|
@passport.authenticate.callsArgWith(1, null, @user, @info)
|
|
@passport.authenticate.callsArgWith(1, null, @user, @info)
|
|
|
|
|
|
|
|
it 'should call passport.authenticate', () ->
|
|
it 'should call passport.authenticate', () ->
|
|
@@ -85,6 +89,18 @@ describe "AuthenticationController", ->
|
|
|
@res.json.callCount.should.equal 1
|
|
@res.json.callCount.should.equal 1
|
|
|
@res.json.calledWith({redir: @req._redir}).should.equal true
|
|
@res.json.calledWith({redir: @req._redir}).should.equal true
|
|
|
|
|
|
|
|
|
|
+ describe 'when session.save produces an error', () ->
|
|
|
|
|
+ beforeEach ->
|
|
|
|
|
+ @req.session.save = sinon.stub().callsArgWith(0, new Error('woops'))
|
|
|
|
|
+
|
|
|
|
|
+ it 'should return next with an error', () ->
|
|
|
|
|
+ @AuthenticationController.passportLogin @req, @res, @next
|
|
|
|
|
+ @next.calledWith(@err).should.equal true
|
|
|
|
|
+
|
|
|
|
|
+ it 'should not return json', () ->
|
|
|
|
|
+ @AuthenticationController.passportLogin @req, @res, @next
|
|
|
|
|
+ @res.json.callCount.should.equal 0
|
|
|
|
|
+
|
|
|
describe 'when authenticate does not produce a user', ->
|
|
describe 'when authenticate does not produce a user', ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
beforeEach ->
|