-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_nginx.js
101 lines (89 loc) · 2.9 KB
/
test_nginx.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const request = require('request');
const _ = require('lodash');
require('should');
const baseUrl = `http://${process.env.MOBILE_DOMAIN}`;
const mobileAgentStr = [
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 ',
'(KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'
].join('');
describe('nginx config', () => {
const empty = { expectHeadersNotPresent: [], headers: {} };
const preventIframe = path => Object.assign({}, empty, {
path,
expectedCode: 200,
headers: {
'user-agent': mobileAgentStr
},
title: `prevent rendering ${path} in iframe`,
expectedHeaders: { 'x-frame-options': 'SAMEORIGIN' }
});
const allowIframe = path => Object.assign({}, empty, {
path,
expectedCode: 200,
headers: {
'user-agent': mobileAgentStr
},
title: `allow rendering ${path} in iframe`,
expectHeadersNotPresent: ['x-frame-options']
});
const desktopRedirect = path => Object.assign({}, empty, {
path,
expectedCode: 301,
title: `mobile redirect for ${path}`,
expectedHeaders: { 'location': `https://${process.env.DESKTOP_SERVER_NAME}${path}` }
});
const redirect = (path, toPath) => Object.assign({}, empty, {
path,
title: `redirect from ${path} to ${toPath}`,
headers: {
'user-agent': mobileAgentStr
},
expectedCode: 301,
expectedHeaders: { 'location': `http://${process.env.MOBILE_DOMAIN}${toPath}` }
});
const notRedirect = (path) => Object.assign({}, empty, {
path,
headers: {
'user-agent': mobileAgentStr
},
title: `not redirect from ${path}`,
expectedCode: 200
});
const testCases = [
preventIframe('/'),
preventIframe('/officer/123/jerome-finnigan/'),
preventIframe('/cr/123/'),
preventIframe('/trr/123/'),
allowIframe('/embed/top-officers-page/'),
allowIframe('/embed/officers/'),
allowIframe('/img/favicon-16x16.ico'),
desktopRedirect('/'),
desktopRedirect('/officer/123/jerome-finnigan/'),
desktopRedirect('/cr/123/'),
desktopRedirect('/trr/123/'),
redirect('/officer/robbin-parker/21860/', '/officer/21860/robbin-parker/'),
redirect('/documents', '/documents/'),
redirect('/documents?match=abc', '/documents/?match=abc'),
notRedirect('/documents/abc.pdf'),
];
const func = testCase => done => {
request({
followRedirect: false,
url: `${baseUrl}${testCase.path}`,
headers: testCase.headers
}, (error, response, body) => {
response.statusCode.should.eql(testCase.expectedCode);
for (let pair of _.toPairs(testCase.expectedHeaders)) {
const [header, value] = pair;
response.headers[header].should.eql(value);
}
for (let header of testCase.expectHeadersNotPresent) {
response.headers.should.not.have.keys(header);
}
done();
});
};
for (let testCase of testCases) {
it(testCase.title, func(testCase));
}
});