diff --git a/spec/validation.spec.js b/spec/validation.spec.js index 7e1e67f6a..ff60da51f 100644 --- a/spec/validation.spec.js +++ b/spec/validation.spec.js @@ -348,6 +348,24 @@ describe("Request validation middleware", () => { expect(response.statusCode).toEqual(200); }); + it("should validate if options passed but not validate flag", () => { + const newUrl = + fullUrl.pathname + fullUrl.search + "&somethingUnexpected=true"; + const request = httpMocks.createRequest( + Object.assign({}, defaultRequest, { + originalUrl: newUrl, + }) + ); + + const middleware = webhook(token, {}); + + middleware(request, response, () => { + expect(true).toBeFalsy(); + }); + + expect(response.statusCode).toEqual(403); + }); + it("should accept manual host+proto", (done) => { const request = httpMocks.createRequest( Object.assign({}, defaultRequest, { diff --git a/src/webhooks/webhooks.ts b/src/webhooks/webhooks.ts index e5b14517f..08a200439 100644 --- a/src/webhooks/webhooks.ts +++ b/src/webhooks/webhooks.ts @@ -355,10 +355,8 @@ export function webhook( } } - if (!options) - options = {}; - if (!options.validate) - options.validate = true + if (!options) options = {}; + if (!options.validate) options.validate = true; // Process arguments var tokenString;