From 08567ff2202ef853052a9e846e79742b6f26d632 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Wed, 10 May 2017 15:25:23 +0100 Subject: [PATCH] if projectId is not defined, error out --- .../Features/Cooldown/CooldownMiddlewear.coffee | 2 ++ .../Cooldown/CooldownMiddlewearTests.coffee | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/services/web/app/coffee/Features/Cooldown/CooldownMiddlewear.coffee b/services/web/app/coffee/Features/Cooldown/CooldownMiddlewear.coffee index b073541945..6d1e158699 100644 --- a/services/web/app/coffee/Features/Cooldown/CooldownMiddlewear.coffee +++ b/services/web/app/coffee/Features/Cooldown/CooldownMiddlewear.coffee @@ -6,6 +6,8 @@ module.exports = CooldownMiddlewear = freezeProject: (req, res, next) -> projectId = req.params.Project_id + if !projectId? + return next(new Error('[Cooldown] No projectId parameter on route')) CooldownManager.isProjectOnCooldown projectId, (err, projectIsOnCooldown) -> if err? return next(err) diff --git a/services/web/test/UnitTests/coffee/Cooldown/CooldownMiddlewearTests.coffee b/services/web/test/UnitTests/coffee/Cooldown/CooldownMiddlewearTests.coffee index 694ca11fce..646e7ffbde 100644 --- a/services/web/test/UnitTests/coffee/Cooldown/CooldownMiddlewearTests.coffee +++ b/services/web/test/UnitTests/coffee/Cooldown/CooldownMiddlewearTests.coffee @@ -70,3 +70,19 @@ describe "CooldownMiddlewear", -> @CooldownMiddlewear.freezeProject @req, @res, @next @next.callCount.should.equal 1 expect(@next.lastCall.args[0]).to.be.instanceof Error + + describe 'when projectId is not part of route', -> + beforeEach -> + @CooldownManager.isProjectOnCooldown = sinon.stub().callsArgWith(1, null, true) + @req = {params: {lol: 'abc'}} + @res = {sendStatus: sinon.stub()} + @next = sinon.stub() + + it 'call next with an error', -> + @CooldownMiddlewear.freezeProject @req, @res, @next + @next.callCount.should.equal 1 + expect(@next.lastCall.args[0]).to.be.instanceof Error + + it 'should not call CooldownManager.isProjectOnCooldown', -> + @CooldownMiddlewear.freezeProject @req, @res, @next + @CooldownManager.isProjectOnCooldown.callCount.should.equal 0