Skip to content

Instantly share code, notes, and snippets.

@nqd
Created August 12, 2017 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nqd/200fec4270c17784a9600e381f4180d4 to your computer and use it in GitHub Desktop.
Save nqd/200fec4270c17784a9600e381f4180d4 to your computer and use it in GitHub Desktop.
const request = require('supertest')
const app = require('../../server/server')
const faker = require('faker')
const expect = require('chai').expect
function req (verb, url) {
return request(app)[verb](url)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
}
describe('HTTP header', () => {
describe('should send login request, and returned headers', () => {
let headers
before(done => {
req('post', '/api/users/login')
.send({ email: faker.internet.email(), password: faker.internet.password() })
.expect(401, function (err, res) {
expect(err).to.be.null
headers = res.header
done()
})
})
it('Content-Security-Policy: default-src none header', done => {
expect(headers['content-security-policy']).to.be.eq('default-src "none"')
done()
})
it('X-Content-Type-Options: nosniff', done => {
expect(headers['x-content-type-options']).to.be.eq('nosniff')
done()
})
it('X-Frame-Options: deny', done => {
expect(headers['x-frame-options']).to.be.eq('DENY')
done()
})
it('remove header X-Powered-By, Server', done => {
expect(headers['x-powered-by']).to.be.null
expect(headers['server']).to.be.null
done()
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment