mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
null check user when getting user id from session
This commit is contained in:
parent
b7b307e82b
commit
479b37a48c
2 changed files with 36 additions and 1 deletions
|
@ -44,7 +44,11 @@ module.exports = AuthenticationController =
|
||||||
res.send(auth_token)
|
res.send(auth_token)
|
||||||
|
|
||||||
getLoggedInUserId: (req, callback = (error, user_id) ->) ->
|
getLoggedInUserId: (req, callback = (error, user_id) ->) ->
|
||||||
callback null, req.session.user._id.toString()
|
if req?.session?.user?._id?
|
||||||
|
callback null, req.session.user._id.toString()
|
||||||
|
else
|
||||||
|
e = new Error("user is not on req session")
|
||||||
|
callback e
|
||||||
|
|
||||||
getLoggedInUser: (req, options = {allow_auth_token: false}, callback = (error, user) ->) ->
|
getLoggedInUser: (req, options = {allow_auth_token: false}, callback = (error, user) ->) ->
|
||||||
if req.session?.user?._id?
|
if req.session?.user?._id?
|
||||||
|
|
|
@ -122,6 +122,37 @@ describe "AuthenticationController", ->
|
||||||
it "should only redirect to the local path", ->
|
it "should only redirect to the local path", ->
|
||||||
expect(@res.body).to.deep.equal redir: "/test"
|
expect(@res.body).to.deep.equal redir: "/test"
|
||||||
|
|
||||||
|
describe "getLoggedInUserId", ->
|
||||||
|
|
||||||
|
beforeEach ->
|
||||||
|
@req =
|
||||||
|
session :{}
|
||||||
|
|
||||||
|
it "should return the user id from the session", (done)->
|
||||||
|
@user_id = "2134"
|
||||||
|
@req.session.user =
|
||||||
|
_id:@user_id
|
||||||
|
@AuthenticationController.getLoggedInUserId @req, (err, user_id)=>
|
||||||
|
expect(user_id).to.equal @user_id
|
||||||
|
done()
|
||||||
|
|
||||||
|
it "should return an error if there is no user on the session", (done)->
|
||||||
|
@AuthenticationController.getLoggedInUserId @req, (err, user_id)=>
|
||||||
|
expect(err).to.exist
|
||||||
|
done()
|
||||||
|
|
||||||
|
it "should return an error if there is no session", (done)->
|
||||||
|
@req = {}
|
||||||
|
@AuthenticationController.getLoggedInUserId @req, (err, user_id)=>
|
||||||
|
expect(err).to.exist
|
||||||
|
done()
|
||||||
|
|
||||||
|
it "should return an error if there is no req", (done)->
|
||||||
|
@req = {}
|
||||||
|
@AuthenticationController.getLoggedInUserId @req, (err, user_id)=>
|
||||||
|
expect(err).to.exist
|
||||||
|
done()
|
||||||
|
|
||||||
describe "getLoggedInUser", ->
|
describe "getLoggedInUser", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@UserGetter.getUser = sinon.stub().callsArgWith(1, null, @user)
|
@UserGetter.getUser = sinon.stub().callsArgWith(1, null, @user)
|
||||||
|
|
Loading…
Reference in a new issue