Skip to content

Commit

Permalink
fix: corrected options.validate to default true (#1022)
Browse files Browse the repository at this point in the history
* fix: corrected options.validate to default true

* chore: added test

* chore: corrected options.validate check
  • Loading branch information
tiwarishubham635 committed May 22, 2024
1 parent aef9087 commit 0addf39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
18 changes: 18 additions & 0 deletions spec/validation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
7 changes: 2 additions & 5 deletions src/webhooks/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,8 @@ export function webhook(
}
}

if (!options) {
options = {
validate: true,
};
}
if (!options) options = {};
if (options.validate == undefined) options.validate = true;

// Process arguments
var tokenString;
Expand Down

0 comments on commit 0addf39

Please sign in to comment.