forked from netlify/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheaders.test.js
More file actions
76 lines (69 loc) · 2.17 KB
/
Copy pathheaders.test.js
File metadata and controls
76 lines (69 loc) · 2.17 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
const test = require('ava')
const path = require('path')
const { parseHeadersFile, objectForPath } = require('./headers.js')
const { createSiteBuilder } = require('../../tests/utils/siteBuilder')
const headers = [
{ path: '/', headers: ['X-Frame-Options: SAMEORIGIN'] },
{ path: '/*', headers: ['X-Frame-Thing: SAMEORIGIN'] },
{
path: '/something/*',
headers: [
'X-Frame-Options: DENY',
'X-XSS-Protection: 1; mode=block',
'cache-control: max-age=0',
'cache-control: no-cache',
'cache-control: no-store',
'cache-control: must-revalidate',
],
},
{ path: '/:ding/index.html', headers: ['X-Frame-Options: SAMEORIGIN'] },
]
test.before(async t => {
const builder = createSiteBuilder({ siteName: 'site-for-detecting-server' })
builder.withHeadersFile({
headers,
})
await builder.buildAsync()
t.context.builder = builder
})
test('_headers: validate correct parsing', t => {
const rules = parseHeadersFile(path.resolve(t.context.builder.directory, '_headers'))
t.deepEqual(rules, {
'/': {
'X-Frame-Options': ['SAMEORIGIN'],
},
'/*': {
'X-Frame-Thing': ['SAMEORIGIN'],
},
'/something/*': {
'X-Frame-Options': ['DENY'],
'X-XSS-Protection': ['1; mode=block'],
'cache-control': ['max-age=0', 'no-cache', 'no-store', 'must-revalidate'],
},
'/:ding/index.html': {
'X-Frame-Options': ['SAMEORIGIN'],
},
})
})
test('_headers: rulesForPath testing', t => {
const rules = parseHeadersFile(path.resolve(t.context.builder.directory, '_headers'))
t.deepEqual(objectForPath(rules, '/'), {
'X-Frame-Options': ['SAMEORIGIN'],
})
t.deepEqual(objectForPath(rules, '/ding'), {
'X-Frame-Thing': ['SAMEORIGIN'],
})
t.deepEqual(objectForPath(rules, '/something/ding'), {
'X-Frame-Thing': ['SAMEORIGIN'],
'X-Frame-Options': ['DENY'],
'X-XSS-Protection': ['1; mode=block'],
'cache-control': ['max-age=0', 'no-cache', 'no-store', 'must-revalidate'],
})
t.deepEqual(objectForPath(rules, '/ding/index.html'), {
'X-Frame-Options': ['SAMEORIGIN'],
'X-Frame-Thing': ['SAMEORIGIN'],
})
})
test.after(async t => {
await t.context.builder.cleanupAsync()
})