Remove dead auth_token code

This commit is contained in:
James Allen
2016-03-10 17:15:14 +00:00
parent e36be96ec9
commit 3e03164ed4
9 changed files with 30 additions and 267 deletions
@@ -173,7 +173,7 @@ describe "AuthenticationController", ->
beforeEach ->
@req.session =
user: @user
@AuthenticationController.getLoggedInUser(@req, {}, @callback)
@AuthenticationController.getLoggedInUser(@req, @callback)
it "should look up the user in the database", ->
@UserGetter.getUser
@@ -183,105 +183,37 @@ describe "AuthenticationController", ->
it "should return the user", ->
@callback.calledWith(null, @user).should.equal true
describe "with an auth token, but without auth_token_allowed set to true", ->
beforeEach ->
@req.query =
auth_token: "auth-token"
@AuthenticationController.getLoggedInUser(@req, {}, @callback)
it "should not look up the user in the database", ->
@UserGetter.getUser.called.should.equal false
it "should return null in the callback", ->
@callback.calledWith(null, null).should.equal true
describe "with an auth token and auth_token_allowed set to true", ->
beforeEach ->
@req.query =
auth_token: "auth-token"
@AuthenticationController.getLoggedInUser(@req, {allow_auth_token: true}, @callback)
it "should look up the user in the database", ->
@UserGetter.getUser
.calledWith(auth_token: @req.query.auth_token)
.should.equal true
it "should return the user", ->
@callback.calledWith(null, @user).should.equal true
describe "requireLogin", ->
beforeEach ->
@user =
_id: "user-id-123"
email: "user@sharelatex.com"
@middleware = @AuthenticationController.requireLogin()
describe "when loading from the database", ->
describe "when the user is logged in", ->
beforeEach ->
@middleware = @AuthenticationController.requireLogin(@options = { allow_auth_token: true, load_from_db: true })
describe "when the user is logged in", ->
beforeEach ->
@AuthenticationController.getLoggedInUser = sinon.stub().callsArgWith(2, null, @user)
@middleware(@req, @res, @next)
it "should call getLoggedInUser with the passed options", ->
@AuthenticationController.getLoggedInUser.calledWith(@req, { allow_auth_token: true }).should.equal true
it "should set the user property on the request", ->
@req.user.should.deep.equal @user
it "should call the next method in the chain", ->
@next.called.should.equal true
describe "when the user is not logged in", ->
beforeEach ->
@AuthenticationController._redirectToLoginOrRegisterPage = sinon.stub()
@AuthenticationController.getLoggedInUser = sinon.stub().callsArgWith(2, null, null)
@middleware(@req, @res, @next)
it "should redirect to the register page", ->
@AuthenticationController._redirectToLoginOrRegisterPage.calledWith(@req, @res).should.equal true
describe "when not loading from the database", ->
beforeEach ->
@middleware = @AuthenticationController.requireLogin(@options = { load_from_db: false })
describe "when the user is logged in", ->
beforeEach ->
@req.session =
user: @user = {
_id: "user-id-123"
email: "user@sharelatex.com"
}
@middleware(@req, @res, @next)
it "should set the user property on the request", ->
@req.user.should.deep.equal @user
it "should call the next method in the chain", ->
@next.called.should.equal true
describe "when the user is not logged in", ->
beforeEach ->
@req.session = {}
@AuthenticationController._redirectToLoginOrRegisterPage = sinon.stub()
@req.query = {}
@middleware(@req, @res, @next)
it "should redirect to the register or login page", ->
@AuthenticationController._redirectToLoginOrRegisterPage.calledWith(@req, @res).should.equal true
describe "when not loading from the database but an auth_token is provided", ->
beforeEach ->
@AuthenticationController.getLoggedInUser = sinon.stub().callsArgWith(2, null, @user)
@middleware = @AuthenticationController.requireLogin(@options = { load_from_db: false, allow_auth_token: true })
@req.query = auth_token: @auth_token = "auth-token-provided"
@req.session =
user: @user = {
_id: "user-id-123"
email: "user@sharelatex.com"
}
@middleware(@req, @res, @next)
it "should try to load the user from the database anyway", ->
@AuthenticationController.getLoggedInUser
.calledWith(@req, {allow_auth_token: true})
.should.equal true
it "should set the user property on the request", ->
@req.user.should.deep.equal @user
it "should call the next method in the chain", ->
@next.called.should.equal true
describe "when the user is not logged in", ->
beforeEach ->
@req.session = {}
@AuthenticationController._redirectToLoginOrRegisterPage = sinon.stub()
@req.query = {}
@middleware(@req, @res, @next)
it "should redirect to the register or login page", ->
@AuthenticationController._redirectToLoginOrRegisterPage.calledWith(@req, @res).should.equal true
describe "requireGlobalLogin", ->
beforeEach ->
@@ -95,49 +95,3 @@ describe "AuthenticationManager", ->
it "should call the callback", ->
@callback.called.should.equal true
describe "getAuthToken", ->
beforeEach ->
@auth_token = "auth-token"
describe "when the user has an auth token set", ->
beforeEach ->
@db.users.findOne = sinon.stub().callsArgWith(2, null, auth_token: @auth_token)
@AuthenticationManager.getAuthToken(@user_id, @callback)
it "should look up the auth token in the db", ->
@db.users.findOne
.calledWith({
_id: ObjectId(@user_id.toString())
}, {
auth_token: true
})
.should.equal true
it "should return the auth token", ->
@callback.calledWith(null, @auth_token).should.equal true
describe "when the user does not have an auth token set", ->
beforeEach ->
@db.users.findOne = sinon.stub().callsArgWith(2, null, auth_token: null)
@db.users.update = sinon.stub().callsArgWith(2, null)
@AuthenticationManager._createSecureToken = sinon.stub().callsArgWith(0, null, @auth_token)
@AuthenticationManager.getAuthToken(@user_id, @callback)
it "should generate a new auth token", ->
@AuthenticationManager._createSecureToken.called.should.equal true
it "should set the auth token on the user document in the db", ->
@db.users.update
.calledWith({
_id: ObjectId(@user_id.toString())
}, {
$set: auth_token: @auth_token
})
.should.equal true
it "should return the auth token", ->
@callback.calledWith(null, @auth_token).should.equal true
@@ -24,52 +24,6 @@ describe "CollaboratorsController", ->
@project_id = "project-id-123"
@callback = sinon.stub()
describe "getCollaborators", ->
beforeEach ->
@req.params =
Project_id: @project_id
@members = [
{
user: { _id: "admin-id", email: "admin@example.com", first_name: "Joe", last_name: "Admin", foo: "bar" }
privilegeLevel: "admin"
},
{
user: { _id: "rw-id", email: "rw@example.com", first_name: "Jane", last_name: "Write", foo: "bar" }
privilegeLevel: "readAndWrite"
},
{
user: { _id: "ro-id", email: "ro@example.com", first_name: "Joe", last_name: "Read", foo: "bar" }
privilegeLevel: "readOnly"
}
]
@CollaboratorsHandler.getMembersWithPrivilegeLevels = sinon.stub()
@CollaboratorsHandler.getMembersWithPrivilegeLevels
.withArgs(@project_id)
.yields(null, @members)
@res.json = sinon.stub()
@CollaboratorsController.getCollaborators(@req, @res)
it "should return the formatted collaborators", ->
@res.json
.calledWith([
{
id: "admin-id", email: "admin@example.com", first_name: "Joe", last_name: "Admin"
permissions: ["read", "write", "admin"]
owner: true
}
{
id: "rw-id", email: "rw@example.com", first_name: "Jane", last_name: "Write"
permissions: ["read", "write"]
owner: false
}
{
id: "ro-id", email: "ro@example.com", first_name: "Joe", last_name: "Read"
permissions: ["read"]
owner: false
}
])
.should.equal true
describe "addUserToProject", ->
beforeEach ->
@req.params =