forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader-test.js
More file actions
88 lines (78 loc) · 2.58 KB
/
header-test.js
File metadata and controls
88 lines (78 loc) · 2.58 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
78
79
80
81
82
83
84
85
86
87
88
const { expect } = require('chai')
const path = require('path')
const ldnode = require('../../index')
const supertest = require('supertest')
const serverOptions = {
root: path.join(__dirname, '../resources/headers'),
multiuser: false,
webid: true,
sslKey: path.join(__dirname, '../keys/key.pem'),
sslCert: path.join(__dirname, '../keys/cert.pem'),
forceUser: 'https://ruben.verborgh.org/profile/#me'
}
describe('Header handler', () => {
let request
before(() => {
const server = ldnode.createServer(serverOptions)
request = supertest(server)
})
describe('MS-Author-Via', () => {
describeHeaderTest('read/append for the public', {
resource: '/public-ra',
headers: {
'MS-Author-Via': 'SPARQL',
'Access-Control-Expose-Headers': /(^|,\s*)MS-Author-Via(,|$)/
}
})
})
describe('WAC-Allow', () => {
describeHeaderTest('read/append for the public', {
resource: '/public-ra',
headers: {
'WAC-Allow': 'user="read append",public="read append"',
'Access-Control-Expose-Headers': /(^|,\s*)WAC-Allow(,|$)/
}
})
describeHeaderTest('read/write for the user, read for the public', {
resource: '/user-rw-public-r',
headers: {
'WAC-Allow': 'user="read write append",public="read"',
'Access-Control-Expose-Headers': /(^|,\s*)WAC-Allow(,|$)/
}
})
describeHeaderTest('read/write/append/control for the user, nothing for the public', {
resource: '/user-rwac-public-0',
headers: {
'WAC-Allow': 'user="read write append control",public=""',
'Access-Control-Expose-Headers': /(^|,\s*)WAC-Allow(,|$)/
}
})
})
function describeHeaderTest (label, { resource, headers }) {
describe(`a resource that is ${label}`, () => {
// Retrieve the response headers
let response = {}
before(async () => {
const { headers } = await request.get(resource)
response.headers = headers
})
// Assert the existence of each of the expected headers
for (const header in headers) {
assertResponseHasHeader(response, header, headers[header])
}
})
}
function assertResponseHasHeader (response, name, value) {
const key = name.toLowerCase()
if (value instanceof RegExp) {
it(`has a ${name} header matching ${value}`, () => {
expect(response.headers).to.have.property(key)
expect(response.headers[key]).to.match(value)
})
} else {
it(`has a ${name} header of ${value}`, () => {
expect(response.headers).to.have.property(key, value)
})
}
}
})