forked from bendrucker/hapi-require-https
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
67 lines (61 loc) · 1.56 KB
/
Copy pathtest.js
File metadata and controls
67 lines (61 loc) · 1.56 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
63
64
65
66
67
'use strict'
var Code = require('code')
var Lab = require('lab')
var lab = exports.lab = Lab.script()
var describe = lab.describe
var it = lab.it
var expect = Code.expect
var hapi = require('hapi')
describe('hapi-require-https', function () {
var server = new hapi.Server()
server.connection()
server.register(require('./'), function (err) {
if (err) throw err
})
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply('Hello!')
}
})
it('redirects requests where x-forwarded-proto is http', function (done) {
server.inject({
url: '/',
headers: {
host: 'host',
'x-forwarded-proto': 'http'
}
}, function (response) {
expect(response.statusCode).to.equal(301)
expect(response.headers.location).to.equal('https://host/')
done()
})
})
it('includes the query string in redirects', function (done) {
server.inject({
url: '/?test=test&test2=test2',
headers: {
host: 'host',
'x-forwarded-proto': 'http'
}
}, function (response) {
expect(response.statusCode).to.equal(301)
expect(response.headers.location).to.equal('https://host/?test=test&test2=test2')
done()
})
})
it('ignores all other requests', function (done) {
server.inject({
url: '/',
headers: {
host: 'host',
'x-forwarded-proto': 'https'
}
}, function (response) {
expect(response.statusCode).to.equal(200)
expect(response.result).to.equal('Hello!')
done()
})
})
})