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
77 lines (74 loc) · 1.85 KB
/
Copy pathtest.js
File metadata and controls
77 lines (74 loc) · 1.85 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
68
69
70
71
72
73
74
75
76
77
'use strict'
var test = require('tape');
var hapi = require('hapi');
var http = require('http');
var plugin = require('./');
test('proxied requests', async function(t) {
t.plan(2);
const response = Server().inject({
url: '/',
headers: {
host: 'host',
'x-forwarded-proto': 'http'
}
});
t.equal(response.statusCode, 301, 'sets 301 code');
t.equal(response.headers.location, 'https://host/', 'sets Location header');
});
//
// test('un-proxied requests: options = {proxy: false}', async function (t) {
// t.plan(2)
//
// const response = Server({proxy: false}).inject({
// url: '/',
// headers: {
// host: 'host'
// }
// });
// t.equal(response.statusCode, 301, 'sets 301 code')
// t.equal(response.headers.location, 'https://host/', 'sets Location header')
// })
//
// test('query string', async function (t) {
// t.plan(2)
//
// const response = Server().inject({
// url: '/?test=test&test2=test2',
// headers: {
// host: 'host',
// 'x-forwarded-proto': 'http'
// }
// });
// t.equal(response.statusCode, 301, 'sets 301 code')
// t.equal(
// response.headers.location,
// 'https://host/?test=test&test2=test2',
// 'sets Location header with query string'
// )
// })
//
// test('ignores unmatched', async function (t) {
// t.plan(2)
//
// const response = Server().inject({
// url: '/',
// headers: {
// host: 'host',
// 'x-forwarded-proto': 'https'
// }
// });
// t.equal(response.statusCode, 200, 'receives 200')
// t.equal(response.result, 'Hello!', 'receives body')
// })
async function Server (options) {
var server = new hapi.Server()
await server.register({ register: plugin, options: options });
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
return 'Hello!';
}
});
return server;
}