Skip to content

Commit 2916b1f

Browse files
committed
reafctor: fixed assert statement
1 parent 2def18e commit 2916b1f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

middlewares/authorizeBot.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const verifyCronJob = async (req, res, next) => {
1919
const verifyDiscordBot = async (req, res, next) => {
2020
try {
2121
const token = req.headers.authorization.split(" ")[1];
22-
const serviceName = req.headers[HEADERS.SERVICE_NAME] || "";
22+
const serviceName = req.headers[HEADERS.SERVICE_NAME] ?? "";
2323

2424
if (serviceName === DISCORD_SERVICE) {
2525
const data = botVerifcation.verifyDiscordService(token);
@@ -28,6 +28,7 @@ const verifyDiscordBot = async (req, res, next) => {
2828
}
2929
return next();
3030
}
31+
3132
const data = botVerifcation.verifyToken(token);
3233
if (data.name !== CLOUDFLARE_WORKER) {
3334
return res.boom.unauthorized("Unauthorized Bot");

test/unit/middlewares/authorizeBot.test.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ describe("Middleware | Authorize Bot", function () {
150150
authorizeBot.verifyDiscordBot(request, response, nextSpy);
151151

152152
expect(nextSpy.calledOnce).to.be.equal(false);
153-
expect(boomUnauthorizedSpy.calledOnce).to.be.equal(true);
154-
153+
expect(response.boom.unauthorized.calledOnce).to.be.equal(true);
155154
jwtStub.restore();
156155
});
157156

@@ -171,7 +170,7 @@ describe("Middleware | Authorize Bot", function () {
171170

172171
authorizeBot.verifyDiscordBot(request, response, nextSpy);
173172
expect(nextSpy.calledOnce).to.be.equal(false);
174-
expect(boomBadRequestSpy.calledOnce).to.be.equal(true);
173+
expect(response.boom.badRequest.calledOnce).to.be.equal(true);
175174
});
176175

177176
it("should allow request propagation when token is valid for discord service", function () {
@@ -217,7 +216,7 @@ describe("Middleware | Authorize Bot", function () {
217216

218217
authorizeBot.verifyDiscordBot(request, response, nextSpy);
219218
expect(nextSpy.calledOnce).to.be.equal(false);
220-
expect(boomUnauthorizedSpy.calledOnce).to.be.equal(true);
219+
expect(response.boom.unauthorized.calledOnce).to.be.equal(true);
221220
});
222221

223222
it("should return unauthorized when token is valid but not for cloudflare worker", function () {
@@ -230,7 +229,7 @@ describe("Middleware | Authorize Bot", function () {
230229

231230
const response = {
232231
boom: {
233-
unauthorized: sinon.spy(),
232+
unauthorized: boomUnauthorizedSpy,
234233
},
235234
};
236235
authorizeBot.verifyDiscordBot(request, response, nextSpy);

0 commit comments

Comments
 (0)