index.js
1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var hidePoweredBy = require('..')
var connect = require('connect')
var request = require('supertest')
var assert = require('assert')
describe('hidePoweredBy', function () {
function test (name, options) {
it(name, function (done) {
var app = connect()
app.use(function (req, res, next) {
res.setHeader('X-Powered-By', 'Computers')
next()
})
app.use(options.middleware)
app.use(function (req, res) {
res.end('Hello world!')
})
request(app).get('/')
.end(function (err, res) {
if (err) {
done(err)
return
}
assert.equal(res.header['x-powered-by'], options.shouldBe)
done()
})
})
}
it('works even if no header is set', function (done) {
var app = connect()
app.use(hidePoweredBy())
app.use(function (req, res) {
res.end('Hello world!')
})
request(app).get('/')
.end(function (err, res) {
if (err) {
done(err)
return
}
assert.equal(res.header['x-powered-by'], undefined)
done()
})
})
test('removes the X-Powered-By header', {
middleware: hidePoweredBy(),
shouldBe: undefined
})
test('allows you to explicitly set the header', {
middleware: hidePoweredBy({ setTo: 'steampowered' }),
shouldBe: 'steampowered'
})
it('names its function and middleware', function () {
assert.equal(hidePoweredBy.name, 'hidePoweredBy')
assert.equal(hidePoweredBy().name, 'hidePoweredBy')
})
})