Skip to content

Commit

Permalink
Remove helmet.noCache
Browse files Browse the repository at this point in the history
Closes [#215][0].

[0]: #215
  • Loading branch information
EvanHahn committed Jun 12, 2020
1 parent 1bc4f76 commit ca483bd
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 73 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

### Removed

- `helmet.hpkp`. If you still need it, use the `hpkp` package on npm.
- `helmet.featurePolicy`. If you still need it, use the `feature-policy` package on npm.
- `helmet.hpkp`. If you still need it, use the `hpkp` package on npm.
- `helmet.noCache`. If you still need it, use the `nocache` package on npm.

## 3.23.0 - 2020-06-12

Expand Down
13 changes: 1 addition & 12 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IncomingMessage, ServerResponse } from "http";
import depd = require("depd");

interface HelmetOptions {
contentSecurityPolicy?: any;
Expand All @@ -13,15 +12,12 @@ interface HelmetOptions {
permittedCrossDomainPolicies?: any;
referrerPolicy?: any;
xssFilter?: any;
noCache?: any;
}

interface MiddlewareFunction {
(req: IncomingMessage, res: ServerResponse, next: () => void): void;
}

const deprecate = depd("helmet");

const DEFAULT_MIDDLEWARE = [
"dnsPrefetchControl",
"frameguard",
Expand All @@ -43,8 +39,7 @@ type MiddlewareName =
| "noSniff"
| "permittedCrossDomainPolicies"
| "referrerPolicy"
| "xssFilter"
| "noCache";
| "xssFilter";

const middlewares: MiddlewareName[] = [
"contentSecurityPolicy",
Expand All @@ -58,7 +53,6 @@ const middlewares: MiddlewareName[] = [
"permittedCrossDomainPolicies",
"referrerPolicy",
"xssFilter",
"noCache",
];

function helmet(options: Readonly<HelmetOptions> = {}) {
Expand Down Expand Up @@ -130,9 +124,4 @@ helmet.permittedCrossDomainPolicies = require("helmet-crossdomain");
helmet.referrerPolicy = require("referrer-policy");
helmet.xssFilter = require("x-xss-protection");

helmet.noCache = deprecate.function(
require("nocache"),
"helmet.noCache is deprecated and will be removed in helmet@4. You can use the `nocache` module instead. For more, see https://github.com/helmetjs/helmet/issues/215."
);

export = helmet;
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"dist/index.js"
],
"dependencies": {
"depd": "2.0.0",
"dns-prefetch-control": "0.2.0",
"dont-sniff-mimetype": "1.1.0",
"expect-ct": "0.2.0",
Expand All @@ -49,13 +48,11 @@
"hide-powered-by": "1.1.0",
"hsts": "2.2.0",
"ienoopen": "1.1.0",
"nocache": "2.1.0",
"referrer-policy": "1.2.0",
"x-xss-protection": "1.3.0"
},
"devDependencies": {
"@types/connect": "^3.4.33",
"@types/depd": "^1.1.32",
"@types/jest": "^26.0.0",
"@types/supertest": "^2.0.9",
"@typescript-eslint/eslint-plugin": "^3.2.0",
Expand Down
43 changes: 0 additions & 43 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import helmet = require("..");

import { IncomingMessage, ServerResponse } from "http";
import connect = require("connect");
import request = require("supertest");

describe("helmet", function () {
describe("module aliases", function () {
it('aliases "dns-prefetch-control"', function () {
Expand Down Expand Up @@ -51,39 +47,6 @@ describe("helmet", function () {
expect(helmet.ieNoOpen).toBe(pkg);
});

// This test will be removed in helmet@4.
it("calls through to nocache but emits a deprecation warning", function () {
const deprecationPromise = new Promise((resolve) => {
process.once("deprecation", (deprecationError) => {
expect(
deprecationError.message.indexOf(
"You can use the `nocache` module instead."
) !== -1
).toBeTruthy();
resolve();
});
});

const app = connect();
app.use(helmet.noCache());
app.use((_req: IncomingMessage, res: ServerResponse) => {
res.end("Hello world!");
});
const supertestPromise = request(app)
.get("/")
.expect(200)
.expect("Surrogate-Control", "no-store")
.expect(
"Cache-Control",
"no-store, no-cache, must-revalidate, proxy-revalidate"
)
.expect("Pragma", "no-cache")
.expect("Expires", "0")
.expect("Hello world!");

return Promise.all([deprecationPromise, supertestPromise]);
});

it('aliases "referrer-policy"', function () {
const pkg = require("referrer-policy");
expect(helmet.referrerPolicy).toBe(pkg);
Expand All @@ -105,7 +68,6 @@ describe("helmet", function () {
jest.spyOn(helmet, "hsts");
jest.spyOn(helmet, "hsts");
jest.spyOn(helmet, "ieNoOpen");
jest.spyOn(helmet, "noCache");
jest.spyOn(helmet, "noSniff");
jest.spyOn(helmet, "permittedCrossDomainPolicies");
jest.spyOn(helmet, "referrerPolicy");
Expand Down Expand Up @@ -133,7 +95,6 @@ describe("helmet", function () {

expect(helmet.contentSecurityPolicy).not.toHaveBeenCalled();
expect(helmet.expectCt).not.toHaveBeenCalled();
expect(helmet.noCache).not.toHaveBeenCalled();
expect(helmet.permittedCrossDomainPolicies).not.toHaveBeenCalled();
});

Expand All @@ -156,7 +117,6 @@ describe("helmet", function () {
expect(helmet.xssFilter).toHaveBeenCalledWith({});
expect(helmet.contentSecurityPolicy).not.toHaveBeenCalled();
expect(helmet.expectCt).not.toHaveBeenCalled();
expect(helmet.noCache).not.toHaveBeenCalled();
});

it("lets you enable a normally-disabled middleware", function () {
Expand All @@ -181,7 +141,6 @@ describe("helmet", function () {
expect(helmet.xssFilter).toHaveBeenCalledWith({});
expect(helmet.contentSecurityPolicy).not.toHaveBeenCalled();
expect(helmet.expectCt).not.toHaveBeenCalled();
expect(helmet.noCache).not.toHaveBeenCalled();
});

it("lets you set options for a default middleware", function () {
Expand All @@ -206,7 +165,6 @@ describe("helmet", function () {
expect(helmet.xssFilter).toHaveBeenCalledWith({});
expect(helmet.contentSecurityPolicy).not.toHaveBeenCalled();
expect(helmet.expectCt).not.toHaveBeenCalled();
expect(helmet.noCache).not.toHaveBeenCalled();
expect(helmet.permittedCrossDomainPolicies).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -237,7 +195,6 @@ describe("helmet", function () {
expect(helmet.noSniff).toHaveBeenCalledWith({});
expect(helmet.xssFilter).toHaveBeenCalledWith({});
expect(helmet.expectCt).not.toHaveBeenCalled();
expect(helmet.noCache).not.toHaveBeenCalled();
expect(helmet.permittedCrossDomainPolicies).not.toHaveBeenCalled();
});

Expand Down

0 comments on commit ca483bd

Please sign in to comment.