test.js
1.97 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 opts = { port: 0 };
var redirect = require('./')(opts);
function r80to443() {
// using port 80 and 443
opts.port = 443;
var req = { connection: {}, headers: { host: 'example.com' }, url: '/path/to/somewhere.html' };
var res = {
setHeader: function () {}
, end: function (body) {
if (!/:/.test(body)) {
throw new Error("test didn't pass with port 80 redirecting to 443");
}
console.log('PASS: 80 to 443');
}
};
var next = function () {};
redirect(req, res, next);
}
function r80to8443() {
// using port 80, but not 443
opts.port = 8443;
var req = { connection: {}, headers: { host: 'example.com' }, url: '/path/to/somewhere.html' };
var res = {
setHeader: function () {}
, end: function (body) {
if (!/:8443/.test(body)) {
throw new Error("test didn't pass with port 80 redirecting to non-443");
}
console.log('PASS: 80 to 8443');
}
};
var next = function () {};
redirect(req, res, next);
}
function r4080to8443() {
// using port 80 and 443
opts.port = 8443;
var req = { connection: {}, headers: { host: 'example.com:4080' }, url: '/path/to/somewhere.html' };
var res = {
setHeader: function () {}
, end: function (body) {
if (!/:8443/.test(body)) {
throw new Error("test didn't pass with port 4080 redirecting to 8443");
}
console.log('PASS: 4080 to 8443');
}
};
var next = function () {};
redirect(req, res, next);
}
function r4080to443() {
// using port 80 and 443
opts.port = 8443;
var req = { connection: {}, headers: { host: 'example.com:4080' }, url: '/path/to/somewhere.html' };
var res = {
setHeader: function () {}
, end: function (body) {
if (/:/.test(body)) {
throw new Error("test didn't pass with port 4080 redirecting to 8443");
}
console.log('PASS: 4080 to 8443');
}
};
var next = function () {};
redirect(req, res, next);
}
r80to443();
r80to8443();
r4080to8443();
//r4080to443();