|
|
@@ -33,6 +33,7 @@ describe('AuthenticationController', function() {
|
|
|
'../Analytics/AnalyticsManager': (this.AnalyticsManager = {
|
|
|
recordEvent: sinon.stub()
|
|
|
}),
|
|
|
+ '../../infrastructure/SessionStoreManager': (this.SessionStoreManager = {}),
|
|
|
'logger-sharelatex': (this.logger = {
|
|
|
log: sinon.stub(),
|
|
|
warn: sinon.stub(),
|
|
|
@@ -582,6 +583,54 @@ describe('AuthenticationController', function() {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+ describe('validateUserSession', function() {
|
|
|
+ beforeEach(function() {
|
|
|
+ this.user = {
|
|
|
+ _id: 'user-id-123',
|
|
|
+ email: 'user@sharelatex.com'
|
|
|
+ }
|
|
|
+ this.middleware = this.AuthenticationController.validateUserSession()
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('when the user has a session token', function() {
|
|
|
+ beforeEach(function() {
|
|
|
+ this.req.user = this.user
|
|
|
+ this.SessionStoreManager.hasValidationToken = sinon.stub().returns(true)
|
|
|
+ this.middleware(this.req, this.res, this.next)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should call the next method in the chain', function() {
|
|
|
+ this.next.called.should.equal(true)
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('when the user does not have a session token', function() {
|
|
|
+ beforeEach(function() {
|
|
|
+ this.req.session = {
|
|
|
+ user: this.user,
|
|
|
+ regenerate: sinon.stub().yields()
|
|
|
+ }
|
|
|
+ this.req.user = this.user
|
|
|
+ this.AuthenticationController._redirectToLoginOrRegisterPage = sinon.stub()
|
|
|
+ this.req.query = {}
|
|
|
+ this.SessionStoreManager.hasValidationToken = sinon
|
|
|
+ .stub()
|
|
|
+ .returns(false)
|
|
|
+ this.middleware(this.req, this.res, this.next)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should destroy the current session', function() {
|
|
|
+ this.req.session.regenerate.called.should.equal(true)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should redirect to the register or login page', function() {
|
|
|
+ this.AuthenticationController._redirectToLoginOrRegisterPage
|
|
|
+ .calledWith(this.req, this.res)
|
|
|
+ .should.equal(true)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
describe('requireOauth', function() {
|
|
|
beforeEach(function() {
|
|
|
this.res.send = sinon.stub()
|