Merge pull request #4338 from overleaf/ab-session-manager

Extract functions from AuthenticationController to SessionManager

GitOrigin-RevId: 86870ce03a762e1a837dcf493759e8851e759883
This commit is contained in:
Alexandre Bourdin
2021-07-28 12:36:22 +00:00
committed by Copybot
parent 7e61fc4035
commit 9468e5cb4f
66 changed files with 460 additions and 458 deletions
@@ -24,6 +24,7 @@ const _ = require('underscore')
const UserGetter = require('../../../../app/src/Features/User/UserGetter')
const { User } = require('../../../../app/src/models/User')
const AuthenticationController = require('../../../../app/src/Features/Authentication/AuthenticationController')
const SessionManager = require('../../../../app/src/Features/Authentication/SessionManager')
module.exports = LaunchpadController = {
_getAuthMethod() {
@@ -39,7 +40,7 @@ module.exports = LaunchpadController = {
launchpadPage(req, res, next) {
// TODO: check if we're using external auth?
// * how does all this work with ldap and saml?
const sessionUser = AuthenticationController.getSessionUser(req)
const sessionUser = SessionManager.getSessionUser(req.session)
const authMethod = LaunchpadController._getAuthMethod()
return LaunchpadController._atLeastOneAdminExists(function (
err,
@@ -38,6 +38,7 @@ describe('LaunchpadController', function () {
'../../../../app/src/Features/User/UserGetter': (this.UserGetter = {}),
'../../../../app/src/models/User': { User: this.User },
'../../../../app/src/Features/Authentication/AuthenticationController': (this.AuthenticationController = {}),
'../../../../app/src/Features/Authentication/SessionManager': (this.SessionManager = {}),
},
})
@@ -74,9 +75,7 @@ describe('LaunchpadController', function () {
describe('when the user is not logged in', function () {
beforeEach(function () {
this.AuthenticationController.getSessionUser = sinon
.stub()
.returns(null)
this.SessionManager.getSessionUser = sinon.stub().returns(null)
return (this.res.render = sinon.stub())
})
@@ -134,9 +133,7 @@ describe('LaunchpadController', function () {
_id: 'abcd',
email: 'abcd@example.com',
}
this.AuthenticationController.getSessionUser = sinon
.stub()
.returns(this.user)
this.SessionManager.getSessionUser = sinon.stub().returns(this.user)
this._atLeastOneAdminExists.callsArgWith(0, null, true)
this.res.render = sinon.stub()
return (this.res.redirect = sinon.stub())