-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathauth-proxy-test.mjs
More file actions
144 lines (126 loc) · 4.14 KB
/
auth-proxy-test.mjs
File metadata and controls
144 lines (126 loc) · 4.14 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { createRequire } from 'module'
import { expect } from 'chai'
import supertest from 'supertest'
import nock from 'nock'
import { fileURLToPath } from 'url'
import { dirname, join } from 'path'
import ldnode from '../../index.mjs'
const require = createRequire(import.meta.url)
const __dirname = dirname(fileURLToPath(import.meta.url))
const { rm } = require('../utils.mjs')
const USER = 'https://ruben.verborgh.org/profile/#me'
describe('Auth Proxy', () => {
describe('A Solid server with the authProxy option', () => {
let server
before(() => {
// Set up test back-end server
nock('http://server-a.org').persist()
.get(/./).reply(200, function () { return this.req.headers })
.options(/./).reply(200)
.post(/./).reply(200)
// Set up Solid server
server = ldnode({
root: join(__dirname, '../resources/auth-proxy'),
configPath: join(__dirname, '../resources/config'),
authProxy: {
'/server/a': 'http://server-a.org'
},
forceUser: USER
})
})
after(() => {
// Release back-end server
nock.cleanAll()
// Remove created index files
rm('index.html')
rm('index.html.acl')
})
// Skipped tests due to not supported deep acl:accessTo #963
describe.skip('responding to /server/a', () => {
let response
before(() =>
supertest(server).get('/server/a/')
.then(res => { response = res })
)
it('sets the User header on the proxy request', () => {
expect(response.body).to.have.property('user', USER)
})
})
describe('responding to GET', () => {
describe.skip('for a path with read permissions', () => {
let response
before(() =>
supertest(server).get('/server/a/r')
.then(res => { response = res })
)
it('returns status code 200', () => {
expect(response.statusCode).to.equal(200)
})
})
describe('for a path without read permissions', () => {
let response
before(() =>
supertest(server).get('/server/a/wc')
.then(res => { response = res })
)
it('returns status code 403', () => {
expect(response.statusCode).to.equal(403)
})
})
})
describe('responding to OPTIONS', () => {
describe.skip('for a path with read permissions', () => {
let response
before(() =>
supertest(server).options('/server/a/r')
.then(res => { response = res })
)
it('returns status code 200', () => {
expect(response.statusCode).to.equal(200)
})
})
describe('for a path without read permissions', () => {
let response
before(() =>
supertest(server).options('/server/a/wc')
.then(res => { response = res })
)
it('returns status code 403', () => {
expect(response.statusCode).to.equal(403)
})
})
})
describe('responding to POST', () => {
describe.skip('for a path with read and write permissions', () => {
let response
before(() =>
supertest(server).post('/server/a/rw')
.then(res => { response = res })
)
it('returns status code 200', () => {
expect(response.statusCode).to.equal(200)
})
})
describe('for a path without read permissions', () => {
let response
before(() =>
supertest(server).post('/server/a/w')
.then(res => { response = res })
)
it('returns status code 403', () => {
expect(response.statusCode).to.equal(403)
})
})
describe('for a path without write permissions', () => {
let response
before(() =>
supertest(server).post('/server/a/r')
.then(res => { response = res })
)
it('returns status code 403', () => {
expect(response.statusCode).to.equal(403)
})
})
})
})
})