fix: Convert ints to strings for validation

This commit is contained in:
Bouncey
2019-02-24 10:12:51 +00:00
committed by mrugesh mohapatra
parent 014c26cd4e
commit f743f4edf5
2 changed files with 16 additions and 1 deletions

View File

@ -199,7 +199,7 @@ export function isValidChallengeCompletion(req, res, next) {
log('isObjectId', id, ObjectID.isValid(id));
return res.sendStatus(403);
}
if ('challengeType' in req.body && !isNumeric(challengeType)) {
if ('challengeType' in req.body && !isNumeric(String(challengeType))) {
log('challengeType', challengeType, isNumeric(challengeType));
return res.sendStatus(403);
}

View File

@ -310,6 +310,21 @@ describe('boot/challenge', () => {
expect(next.called).toBe(true);
});
it('can handle an "int" challengeType', () => {
const req = mockReq({
body: {
id: validObjectId,
challengeType: 1
}
});
const res = mockRes();
const next = sinon.spy();
isValidChallengeCompletion(req, res, next);
expect(next.called).toBe(true);
});
});
xdescribe('modernChallengeCompleted');