Skip to content

Commit

Permalink
Assign default value to twilioHeader during validation (#446)
Browse files Browse the repository at this point in the history
* Assign default value to twilioHeader during validation

* Added tests for the validation

* Fixed test bug where wrong variable was being used

* Removed duplicate test
  • Loading branch information
mniehe authored and childish-sambino committed May 16, 2019
1 parent 4f80e68 commit 5dbef34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/webhooks/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function getExpectedBodyHash(body) {
@returns {boolean} - valid
*/
function validateRequest(authToken, twilioHeader, url, params) {
twilioHeader = twilioHeader || '';
var expectedSignature = getExpectedTwilioSignature(authToken, url, params);
return scmp(Buffer.from(twilioHeader), Buffer.from(expectedSignature));
}
Expand Down
6 changes: 6 additions & 0 deletions spec/validation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ describe('Request validation', () => {

expect(isValid).toBeFalsy();
});

it('should fail when signature undefined', () => {
const isValid = validateRequest(token, undefined, requestUrl, defaultParams);

expect(isValid).toBeFalsy();
});
});

describe('Request validation middleware', () => {
Expand Down

0 comments on commit 5dbef34

Please sign in to comment.