Skip to content

Commit

Permalink
Strict-Transport-Security: remove old setIf warning
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn committed May 6, 2023
1 parent 4515701 commit d45282c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
5 changes: 0 additions & 5 deletions middlewares/strict-transport-security/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ function getHeaderValueFromOptions(
'Strict-Transport-Security middleware should use `includeSubDomains` instead of `includeSubdomains`. (The correct one has an uppercase "D".)'
);
}
if ("setIf" in options) {
console.warn(
"Strict-Transport-Security middleware no longer supports the `setIf` parameter. See the documentation and <https://github.com/helmetjs/helmet/wiki/Conditionally-using-middleware> if you need help replicating this behavior."
);
}

const directives: string[] = [`max-age=${parseMaxAge(options.maxAge)}`];

Expand Down
30 changes: 7 additions & 23 deletions test/strict-transport-security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,14 @@ describe("Strict-Transport-Security middleware", () => {
expect(() => strictTransportSecurity({ maxage: 1234 } as any)).toThrow();
});

// This functionality only exists to ease the transition to this major version.
// It's safe to remove these warnings (and therefore these tests) without a
// breaking change.
describe("warnings for legacy usage", () => {
beforeEach(() => {
jest.spyOn(console, "warn").mockImplementation(() => {});
});

it("logs a warning when using the `includeSubdomains` parameter", () => {
strictTransportSecurity({ includeSubdomains: false } as any);

expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenCalledWith(
'Strict-Transport-Security middleware should use `includeSubDomains` instead of `includeSubdomains`. (The correct one has an uppercase "D".)'
);
});
it("logs a warning when using the mis-capitalized `includeSubdomains` parameter", () => {
jest.spyOn(console, "warn").mockImplementation(() => {});

it("logs a warning when using the `setIf` parameter", () => {
strictTransportSecurity({ setIf: () => false } as any);
strictTransportSecurity({ includeSubdomains: false } as any);

expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenCalledWith(
"Strict-Transport-Security middleware no longer supports the `setIf` parameter. See the documentation and <https://github.com/helmetjs/helmet/wiki/Conditionally-using-middleware> if you need help replicating this behavior."
);
});
expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenCalledWith(
'Strict-Transport-Security middleware should use `includeSubDomains` instead of `includeSubdomains`. (The correct one has an uppercase "D".)'
);
});
});

0 comments on commit d45282c

Please sign in to comment.