Don't redirect to images, icons, etc, in login workflow

This commit is contained in:
Shane Kilkelly 2017-05-12 15:46:16 +01:00
parent d550ede112
commit 0e26222551
2 changed files with 13 additions and 1 deletions

View file

@ -196,7 +196,11 @@ module.exports = AuthenticationController =
_setRedirectInSession: (req, value) -> _setRedirectInSession: (req, value) ->
if !value? if !value?
value = if Object.keys(req.query).length > 0 then "#{req.path}?#{querystring.stringify(req.query)}" else "#{req.path}" value = if Object.keys(req.query).length > 0 then "#{req.path}?#{querystring.stringify(req.query)}" else "#{req.path}"
if req.session? && !value.match(new RegExp('^\/(socket.io|js|stylesheets|img)\/.*$')) if (
req.session? &&
!value.match(new RegExp('^\/(socket.io|js|stylesheets|img)\/.*$')) &&
!value.match(new RegExp('^.*\.(png|jpeg|svg)$'))
)
req.session.postLoginRedirect = value req.session.postLoginRedirect = value
_getRedirectFromSession: (req) -> _getRedirectFromSession: (req) ->

View file

@ -555,6 +555,14 @@ describe "AuthenticationController", ->
@AuthenticationController._setRedirectInSession(@req, '/somewhere/specific') @AuthenticationController._setRedirectInSession(@req, '/somewhere/specific')
expect(@req.session.postLoginRedirect).to.equal "/somewhere/specific" expect(@req.session.postLoginRedirect).to.equal "/somewhere/specific"
describe 'with a png', ->
beforeEach ->
@req = {session: {}}
it 'should not set the redirect', ->
@AuthenticationController._setRedirectInSession(@req, '/something.png')
expect(@req.session.postLoginRedirect).to.equal undefined
describe 'with a js path', -> describe 'with a js path', ->
beforeEach -> beforeEach ->