changed authentication controller to use req.parsedUrl.pathname as query strings on req.url were breaking the whitelist

This commit is contained in:
Henry Oswald 2015-04-30 11:57:40 +01:00
parent 635f79d2f6
commit a7640b5bbd
3 changed files with 14 additions and 2 deletions

View file

@ -90,7 +90,7 @@ module.exports = AuthenticationController =
AuthenticationController._globalLoginWhitelist.push endpoint AuthenticationController._globalLoginWhitelist.push endpoint
requireGlobalLogin: (req, res, next) -> requireGlobalLogin: (req, res, next) ->
if req.url in AuthenticationController._globalLoginWhitelist if req._parsedUrl.pathname in AuthenticationController._globalLoginWhitelist
return next() return next()
if req.headers['authorization']? if req.headers['authorization']?
@ -98,6 +98,7 @@ module.exports = AuthenticationController =
else if req.session.user? else if req.session.user?
return next() return next()
else else
logger.log url:req.url, "user trying to access endpoint not in global whitelist"
return res.redirect "/login" return res.redirect "/login"
httpAuth: require('express').basicAuth (user, pass)-> httpAuth: require('express').basicAuth (user, pass)->

View file

@ -284,12 +284,22 @@ describe "AuthenticationController", ->
describe "with white listed url", -> describe "with white listed url", ->
beforeEach -> beforeEach ->
@AuthenticationController.addEndpointToLoginWhitelist "/login" @AuthenticationController.addEndpointToLoginWhitelist "/login"
@req.url = "/login" @req._parsedUrl.pathname = "/login"
@AuthenticationController.requireGlobalLogin @req, @res, @next @AuthenticationController.requireGlobalLogin @req, @res, @next
it "should call next() directly", -> it "should call next() directly", ->
@next.called.should.equal true @next.called.should.equal true
describe "with white listed url and a query string", ->
beforeEach ->
@AuthenticationController.addEndpointToLoginWhitelist "/login"
@req._parsedUrl.pathname = "/login"
@req.url = "/login?query=something"
@AuthenticationController.requireGlobalLogin @req, @res, @next
it "should call next() directly", ->
@next.called.should.equal true
describe "with http auth", -> describe "with http auth", ->
beforeEach -> beforeEach ->
@req.headers["authorization"] = "Mock Basic Auth" @req.headers["authorization"] = "Mock Basic Auth"

View file

@ -5,6 +5,7 @@ class MockRequest
params: {} params: {}
query: {} query: {}
_parsedUrl:{}
i18n: i18n:
translate:-> translate:->