Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
evheniy committed Oct 30, 2017
1 parent 523d5fb commit e2e4176
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 122 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

charset = utf-8

indent_style = space
indent_size = 2
17 changes: 3 additions & 14 deletions .eslintrc
@@ -1,22 +1,11 @@
{
"extends": "eslint",
"extends": "airbnb-base",
"env": {
"es6": true,
"node": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module"
},
"rules": {
"indent": ["error", 4, {"SwitchCase": 1}],
"quotes": ["error", "single"],
"no-unused-expressions": 0,
"no-underscore-dangle": 0,
"func-style": [
"error",
"declaration", { "allowArrowFunctions": true }
]
"no-param-reassign": 0
}
}
}
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -3,4 +3,4 @@ coverage
npm-debug.log
node_modules
.DS_Store
logs/app.error.log
package-lock.json
9 changes: 3 additions & 6 deletions .travis.yml
@@ -1,10 +1,7 @@
language: node_js
node_js:
- "7.6"
- "7.7"
- "7.8"
- "7.9"
- "7"
- "8"
script:
- npm run lint
- npm run test
- npm run report
- npm run report
20 changes: 14 additions & 6 deletions README.md
Expand Up @@ -25,24 +25,32 @@ It helps you secure your YEPS apps by setting various HTTP headers

npm i -S yeps-helmet


## How to use

const App = require('yeps');

const error = require('yeps-error');
const logger = require('yeps-logger');
const server = require('yeps-server');
const helmet = require('yeps-helmet');

const app = new App();

app.all([
helmet();
error(),
logger(),
helmet(),
]);

server.createHttpServer(app);

Or with options:
Or with **options**:

app.all([
helmet({...});
helmet({...}),
]);

See [helmet](https://github.com/helmetjs/helmet) documentation
See [helmet](https://github.com/helmetjs/helmet) documentation.

#### [YEPS documentation](http://yeps.info/)
#### [YEPS documentation](http://yeps.info/)
6 changes: 3 additions & 3 deletions appveyor.yml
@@ -1,13 +1,13 @@
environment:
matrix:
- nodejs_version: "7.7"
- nodejs_version: "8"
install:
- ps: Install-Product node $env:nodejs_version
- npm install
test_script:
- node --version
- npm --version
- npm run lint
- npm run test:lint
- npm run test:security
- npm run test:code
build: off
build: off
7 changes: 3 additions & 4 deletions index.js
Expand Up @@ -2,9 +2,8 @@ const debug = require('debug')('yeps:helmet');
const wrapper = require('yeps-express-wrapper');
const helmet = require('helmet');

module.exports = (options = {}) => async context => {
module.exports = (options = {}) => async (context) => {
debug('Options: %O', options);

debug('Options: %O', options);

return wrapper(helmet(options))(context);
return wrapper(helmet(options))(context);
};
46 changes: 23 additions & 23 deletions package.json
@@ -1,17 +1,16 @@
{
"name": "yeps-helmet",
"version": "1.0.0",
"version": "1.0.1",
"description": "YEPS helmet",
"main": "index.js",
"scripts": {
"lint": "./node_modules/.bin/npm-run-all --parallel lint:**",
"lint:js": "./node_modules/.bin/eslint index.js tests",
"test": "./node_modules/.bin/npm-run-all --parallel test:**",
"test:security": "./node_modules/.bin/nsp check",
"test:code": "node ./node_modules/mocha/bin/_mocha tests --recursive",
"test:coverage": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- tests --recursive",
"report": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
"clear": "./node_modules/.bin/rimraf coverage",
"test": "npm-run-all test:**",
"test:lint": "eslint index.js tests",
"test:security": "nsp check",
"test:code": "mocha tests --recursive",
"test:coverage": "istanbul cover _mocha -- tests --recursive",
"report": "cat ./coverage/lcov.info | coveralls",
"clear": "rimraf coverage",
"precommit": "npm run lint && npm test",
"prepush": "npm run lint && npm test"
},
Expand Down Expand Up @@ -46,24 +45,25 @@
"node": ">=7.6.0"
},
"devDependencies": {
"chai": "^3.5.0",
"chai": "^4.1.2",
"chai-http": "^3.0.0",
"coveralls": "^2.12.0",
"debug": "^2.6.3",
"eslint": "^3.18.0",
"eslint-config-eslint": "^3.0.0",
"husky": "^0.13.2",
"coveralls": "^3.0.0",
"eslint": "^4.10.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.8.0",
"husky": "^0.14.3",
"istanbul": "^1.1.0-alpha.1",
"mocha": "^3.2.0",
"mocha": "^4.0.1",
"mocha-lcov-reporter": "^1.3.0",
"npm-run-all": "^4.0.2",
"nsp": "^2.6.3",
"rimraf": "^2.6.1",
"sinon": "^1.17.7"
"npm-run-all": "^4.1.1",
"nsp": "^3.0.0",
"rimraf": "^2.6.2",
"yeps": "^1.0.1",
"yeps-server": "^1.1.0"
},
"dependencies": {
"helmet": "^3.5.0",
"yeps": "^1.0.0",
"yeps-express-wrapper": "^1.0.0"
"debug": "^3.1.0",
"helmet": "^3.9.0",
"yeps-express-wrapper": "^1.0.1"
}
}
135 changes: 70 additions & 65 deletions tests/index.js
@@ -1,81 +1,86 @@
const App = require('yeps');
const chai = require('chai');
const chaiHttp = require('chai-http');
const http = require('http');
const srv = require('yeps-server');
const helmet = require('..');
const expect = chai.expect;

const { expect } = chai;

chai.use(chaiHttp);
let app;
let server;

describe('YEPS helmet', async () => {
beforeEach(() => {
app = new App();
server = srv.createHttpServer(app);
});

beforeEach(() => {
app = new App();
});
afterEach(() => {
server.close();
});

it('should test helmet', async () => {
let isTestFinished1 = false;
let isTestFinished2 = false;

app.then(helmet());

app.then(async (ctx) => {
isTestFinished1 = true;

it('should test helmet', async () => {
let isTestFinished1 = false;
let isTestFinished2 = false;

app.then(helmet());

app.then(async ctx => {
isTestFinished1 = true;

ctx.res.statusCode = 200;
ctx.res.end();
});

await chai.request(http.createServer(app.resolve()))
.get('/')
.send()
.then(res => {
expect(res).to.have.status(200);
expect(res.headers['x-dns-prefetch-control']).to.be.equal('off');
expect(res.headers['x-frame-options']).to.be.equal('SAMEORIGIN');
expect(res.headers['x-download-options']).to.be.equal('noopen');
expect(res.headers['x-content-type-options']).to.be.equal('nosniff');
expect(res.headers['x-xss-protection']).to.be.equal('1; mode=block');
isTestFinished2 = true;
});

expect(isTestFinished1).is.true;
expect(isTestFinished2).is.true;
ctx.res.statusCode = 200;
ctx.res.end();
});

it('should test helmet with options', async () => {
let isTestFinished1 = false;
let isTestFinished2 = false;

app.then(helmet({
frameguard: {
action: 'deny'
}
}));

app.then(async ctx => {
isTestFinished1 = true;

ctx.res.statusCode = 200;
ctx.res.end();
});

await chai.request(http.createServer(app.resolve()))
.get('/')
.send()
.then(res => {
expect(res).to.have.status(200);
expect(res.headers['x-dns-prefetch-control']).to.be.equal('off');
expect(res.headers['x-frame-options']).to.be.equal('DENY');
expect(res.headers['x-download-options']).to.be.equal('noopen');
expect(res.headers['x-content-type-options']).to.be.equal('nosniff');
expect(res.headers['x-xss-protection']).to.be.equal('1; mode=block');
isTestFinished2 = true;
});

expect(isTestFinished1).is.true;
expect(isTestFinished2).is.true;
await chai.request(server)
.get('/')
.send()
.then((res) => {
expect(res).to.have.status(200);
expect(res.headers['x-dns-prefetch-control']).to.be.equal('off');
expect(res.headers['x-frame-options']).to.be.equal('SAMEORIGIN');
expect(res.headers['x-download-options']).to.be.equal('noopen');
expect(res.headers['x-content-type-options']).to.be.equal('nosniff');
expect(res.headers['x-xss-protection']).to.be.equal('1; mode=block');
isTestFinished2 = true;
});

expect(isTestFinished1).is.true;
expect(isTestFinished2).is.true;
});

it('should test helmet with options', async () => {
let isTestFinished1 = false;
let isTestFinished2 = false;

app.then(helmet({
frameguard: {
action: 'deny',
},
}));

app.then(async (ctx) => {
isTestFinished1 = true;

ctx.res.statusCode = 200;
ctx.res.end();
});

await chai.request(server)
.get('/')
.send()
.then((res) => {
expect(res).to.have.status(200);
expect(res.headers['x-dns-prefetch-control']).to.be.equal('off');
expect(res.headers['x-frame-options']).to.be.equal('DENY');
expect(res.headers['x-download-options']).to.be.equal('noopen');
expect(res.headers['x-content-type-options']).to.be.equal('nosniff');
expect(res.headers['x-xss-protection']).to.be.equal('1; mode=block');
isTestFinished2 = true;
});

expect(isTestFinished1).is.true;
expect(isTestFinished2).is.true;
});
});

0 comments on commit e2e4176

Please sign in to comment.