Proofed admin endpoint some more, no more dangling connections

This commit is contained in:
Ruben Vereecken 2014-07-23 13:06:51 +02:00
parent 8969311d82
commit ebfe1fc1c0
2 changed files with 15 additions and 2 deletions

View file

@ -20,7 +20,9 @@ module.exports.setup = (app) ->
name = handlers[moduleName]
handler = require('../' + name)
return errors.notFound res, 'Handler not found for ' + moduleName unless handler
return handler[parts[1]](req, res, parts[2..]...) if parts[1] of handler
return errors.notFound res, 'Method not found for handler ' + name
catch error
log.error("Error trying db method '#{req.route.method}' route '#{parts}' from #{name}: #{error}")

View file

@ -15,9 +15,20 @@ describe 'recalculate statistics', ->
expect(res.statusCode).toBe 202
done()
it 'responds with a 404 when not found', (done) ->
xit 'responds with a 404 if handler not found', (done) ->
loginAdmin ->
request.post {uri:getURL '/admin/blobfish/swim'}, (err, res, body) ->
expect(res.statusCode).toBe 404
done()
it 'responds with a 404 if handler method not found', (done) ->
loginAdmin ->
request.post {uri:getURL '/admin/user/hammertime'}, (err, res, body) ->
expect(res.statusCode).toBe 404
done()
it 'responds with a 404 if recalculate method not found', (done) ->
loginAdmin ->
request.post {uri:url + 'ballsKicked'}, (err, res, body) ->
expect(res.statusCode).toBe 404
done()