-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathwww-account-creation-oidc-test.mjs
More file actions
310 lines (278 loc) · 9.96 KB
/
Copy pathwww-account-creation-oidc-test.mjs
File metadata and controls
310 lines (278 loc) · 9.96 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import supertest from 'supertest'
import rdf from 'rdflib'
import ldnode from '../../index.mjs'
import path from 'path'
import { fileURLToPath } from 'url'
import fs from 'fs-extra'
import { rm, read, checkDnsSettings, cleanDir } from '../utils/index.mjs'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const $rdf = rdf
// FIXME: #1502
describe('AccountManager (OIDC account creation tests)', function () {
const port = 7457
const serverUri = `https://localhost:${port}`
const host = `localhost:${port}`
const root = path.normalize(path.join(__dirname, '../resources/accounts/'))
const configPath = path.normalize(path.join(__dirname, '../resources/config'))
const dbPath = path.normalize(path.join(__dirname, '../resources/accounts/db'))
let ldpHttpsServer
const ldp = ldnode.createServer({
root,
configPath,
sslKey: path.normalize(path.join(__dirname, '../keys/key.pem')),
sslCert: path.normalize(path.join(__dirname, '../keys/cert.pem')),
auth: 'oidc',
webid: true,
multiuser: true,
strictOrigin: true,
dbPath,
serverUri,
enforceToc: true
})
before(checkDnsSettings)
before(function (done) {
ldpHttpsServer = ldp.listen(port, done)
})
after(function () {
if (ldpHttpsServer) ldpHttpsServer.close()
fs.removeSync(path.join(dbPath, 'oidc/users/users'))
cleanDir(path.join(root, 'localhost'))
})
const server = supertest(serverUri)
it('should expect a 404 on GET /accounts', function (done) {
server.get('/api/accounts')
.expect(404, done)
})
describe('accessing accounts', function () {
it('should be able to access public file of an account', function (done) {
const subdomain = supertest('https://tim.' + host)
subdomain.get('/hello.html')
.expect(200, done)
})
it('should get 404 if root does not exist', function (done) {
const subdomain = supertest('https://nicola.' + host)
subdomain.get('/')
.set('Accept', 'text/turtle')
.set('Origin', 'http://example.com')
.expect(404)
.expect('Access-Control-Allow-Origin', 'http://example.com')
.expect('Access-Control-Allow-Credentials', 'true')
.end(function (err, res) {
done(err)
})
})
})
describe('creating an account with POST', function () {
beforeEach(function () {
rm('accounts/nicola.localhost')
})
after(function () {
rm('accounts/nicola.localhost')
})
it('should not create WebID if no username is given', (done) => {
const subdomain = supertest('https://' + host)
subdomain.post('/api/accounts/new')
.send('username=&password=12345')
.expect(400, done)
})
it('should not create WebID if no password is given', (done) => {
const subdomain = supertest('https://' + host)
subdomain.post('/api/accounts/new')
.send('username=nicola&password=')
.expect(400, done)
})
it('should not create a WebID if it already exists', function (done) {
const subdomain = supertest('https://' + host)
subdomain.post('/api/accounts/new')
.send('username=nicola&password=12345&acceptToc=true')
.expect(302)
.end((err, res) => {
if (err) {
return done(err)
}
subdomain.post('/api/accounts/new')
.send('username=nicola&password=12345&acceptToc=true')
.expect(400)
.end((err) => {
done(err)
})
})
})
it('should not create WebID if T&C is not accepted', (done) => {
const subdomain = supertest('https://' + host)
subdomain.post('/api/accounts/new')
.send('username=nicola&password=12345&acceptToc=')
.expect(400, done)
})
it('should create the default folders', function (done) {
const subdomain = supertest('https://' + host)
subdomain.post('/api/accounts/new')
.send('username=nicola&password=12345&acceptToc=true')
.expect(302)
.end(function (err) {
if (err) {
return done(err)
}
const domain = host.split(':')[0]
const card = read(path.normalize(path.join('accounts/nicola.' + domain,
'profile/card$.ttl')))
const cardAcl = read(path.normalize(path.join('accounts/nicola.' + domain,
'profile/.acl')))
const prefs = read(path.normalize(path.join('accounts/nicola.' + domain,
'settings/prefs.ttl')))
const inboxAcl = read(path.normalize(path.join('accounts/nicola.' + domain,
'inbox/.acl')))
const rootMeta = read(path.normalize(path.join('accounts/nicola.' + domain, '.meta')))
const rootMetaAcl = read(path.normalize(path.join('accounts/nicola.' + domain,
'.meta.acl')))
if (domain && card && cardAcl && prefs && inboxAcl && rootMeta &&
rootMetaAcl) {
done()
} else {
done(new Error('failed to create default files'))
}
})
}).timeout(20000)
it('should link WebID to the root account', function (done) {
const domain = supertest('https://' + host)
domain.post('/api/accounts/new')
.send('username=nicola&password=12345&acceptToc=true')
.expect(302)
.end(function (err) {
if (err) {
return done(err)
}
const subdomain = supertest('https://nicola.' + host)
subdomain.get('/.meta')
.expect(200)
.end(function (err, data) {
if (err) {
return done(err)
}
const graph = $rdf.graph()
$rdf.parse(
data.text,
graph,
'https://nicola.' + host + '/.meta',
'text/turtle')
const statements = graph.statementsMatching(
undefined,
$rdf.sym('http://www.w3.org/ns/solid/terms#account'),
undefined)
if (statements.length === 1) {
done()
} else {
done(new Error('missing link to WebID of account'))
}
})
})
}).timeout(20000)
describe('after setting up account', () => {
beforeEach(done => {
const subdomain = supertest('https://' + host)
subdomain.post('/api/accounts/new')
.send('username=nicola&password=12345&acceptToc=true')
.end(done)
})
it('should create a private settings container', function (done) {
const subdomain = supertest('https://nicola.' + host)
subdomain.head('/settings/')
.expect(401)
.end(function (err) {
done(err)
})
})
it('should create a private prefs file in the settings container', function (done) {
const subdomain = supertest('https://nicola.' + host)
subdomain.head('/inbox/prefs.ttl')
.expect(401)
.end(function (err) {
done(err)
})
})
it('should create a private inbox container', function (done) {
const subdomain = supertest('https://nicola.' + host)
subdomain.head('/inbox/')
.expect(401)
.end(function (err) {
done(err)
})
})
})
})
})
// FIXME: #1502
describe('Single User signup page', () => {
const serverUri = 'https://localhost:7457'
const port = 7457
let ldpHttpsServer
const rootDir = path.normalize(path.join(__dirname, '../resources/accounts/single-user/'))
const configPath = path.normalize(path.join(__dirname, '../resources/config'))
const ldp = ldnode.createServer({
port,
root: rootDir,
configPath,
sslKey: path.normalize(path.join(__dirname, '../keys/key.pem')),
sslCert: path.normalize(path.join(__dirname, '../keys/cert.pem')),
webid: true,
multiuser: false,
strictOrigin: true
})
const server = supertest(serverUri)
before(function (done) {
fs.removeSync(rootDir)
ldpHttpsServer = ldp.listen(port, () => server.post('/api/accounts/new')
.send('username=foo&password=12345&acceptToc=true')
.end(done))
})
after(function () {
if (ldpHttpsServer) ldpHttpsServer.close()
fs.removeSync(rootDir)
})
it('should return a 406 not acceptable without accept text/html', done => {
server.get('/')
.set('accept', 'text/plain')
.expect(406)
.end(done)
})
})
// FIXME: #1502
describe('Signup page where Terms & Conditions are not being enforced', () => {
const port = 3457
const host = `localhost:${port}`
const root = path.normalize(path.join(__dirname, '../resources/accounts/'))
const configPath = path.normalize(path.join(__dirname, '../resources/config'))
const dbPath = path.normalize(path.join(__dirname, '../resources/accounts/db'))
const ldp = ldnode.createServer({
port,
root,
configPath,
sslKey: path.normalize(path.join(__dirname, '../keys/key.pem')),
sslCert: path.normalize(path.join(__dirname, '../keys/cert.pem')),
auth: 'oidc',
webid: true,
multiuser: true,
strictOrigin: true,
enforceToc: false
})
let ldpHttpsServer
before(function (done) {
ldpHttpsServer = ldp.listen(port, done)
})
after(function () {
if (ldpHttpsServer) ldpHttpsServer.close()
fs.removeSync(path.join(dbPath, 'oidc/users/users'))
cleanDir(path.join(root, 'localhost'))
rm('accounts/nicola.localhost')
})
beforeEach(function () {
rm('accounts/nicola.localhost')
})
it('should not enforce T&C upon creating account', function (done) {
const subdomain = supertest('https://' + host)
subdomain.post('/api/accounts/new')
.send('username=nicola&password=12345')
.expect(302, done)
})
})