Skip to content

Commit 78f574b

Browse files
committed
rm('resources/accounts/single-user/')
1 parent eb8d1e8 commit 78f574b

File tree

1 file changed

+307
-0
lines changed

1 file changed

+307
-0
lines changed
Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
1+
const supertest = require('supertest')
2+
// Helper functions for the FS
3+
const $rdf = require('rdflib')
4+
5+
const { rm, read, checkDnsSettings, cleanDir } = require('../utils')
6+
const ldnode = require('../../index')
7+
const path = require('path')
8+
const fs = require('fs-extra')
9+
10+
// FIXME: #1502
11+
describe('AccountManager (OIDC account creation tests)', function () {
12+
const port = 3457
13+
const serverUri = `https://localhost:${port}`
14+
const host = `localhost:${port}`
15+
const root = path.join(__dirname, '../resources/accounts/')
16+
const configPath = path.join(__dirname, '../resources/config')
17+
const dbPath = path.join(__dirname, '../resources/accounts/db')
18+
19+
let ldpHttpsServer
20+
21+
const ldp = ldnode.createServer({
22+
root,
23+
configPath,
24+
sslKey: path.join(__dirname, '../keys/key.pem'),
25+
sslCert: path.join(__dirname, '../keys/cert.pem'),
26+
auth: 'oidc',
27+
webid: true,
28+
multiuser: true,
29+
strictOrigin: true,
30+
dbPath,
31+
serverUri,
32+
enforceToc: true
33+
})
34+
35+
before(checkDnsSettings)
36+
37+
before(function (done) {
38+
ldpHttpsServer = ldp.listen(port, done)
39+
})
40+
41+
after(function () {
42+
if (ldpHttpsServer) ldpHttpsServer.close()
43+
fs.removeSync(path.join(dbPath, 'oidc/users/users'))
44+
cleanDir(path.join(root, 'localhost'))
45+
})
46+
47+
const server = supertest(serverUri)
48+
49+
it('should expect a 404 on GET /accounts', function (done) {
50+
server.get('/api/accounts')
51+
.expect(404, done)
52+
})
53+
54+
describe('accessing accounts', function () {
55+
it('should be able to access public file of an account', function (done) {
56+
const subdomain = supertest('https://tim.' + host)
57+
subdomain.get('/hello.html')
58+
.expect(200, done)
59+
})
60+
it('should get 404 if root does not exist', function (done) {
61+
const subdomain = supertest('https://nicola.' + host)
62+
subdomain.get('/')
63+
.set('Accept', 'text/turtle')
64+
.set('Origin', 'http://example.com')
65+
.expect(404)
66+
.expect('Access-Control-Allow-Origin', 'http://example.com')
67+
.expect('Access-Control-Allow-Credentials', 'true')
68+
.end(function (err, res) {
69+
done(err)
70+
})
71+
})
72+
})
73+
74+
describe('creating an account with POST', function () {
75+
beforeEach(function () {
76+
rm('accounts/nicola.localhost')
77+
})
78+
79+
after(function () {
80+
rm('accounts/nicola.localhost')
81+
})
82+
83+
it('should not create WebID if no username is given', (done) => {
84+
const subdomain = supertest('https://' + host)
85+
subdomain.post('/api/accounts/new')
86+
.send('username=&password=12345')
87+
.expect(400, done)
88+
})
89+
90+
it('should not create WebID if no password is given', (done) => {
91+
const subdomain = supertest('https://' + host)
92+
subdomain.post('/api/accounts/new')
93+
.send('username=nicola&password=')
94+
.expect(400, done)
95+
})
96+
97+
it('should not create a WebID if it already exists', function (done) {
98+
const subdomain = supertest('https://' + host)
99+
subdomain.post('/api/accounts/new')
100+
.send('username=nicola&password=12345&acceptToc=true')
101+
.expect(302)
102+
.end((err, res) => {
103+
if (err) {
104+
return done(err)
105+
}
106+
subdomain.post('/api/accounts/new')
107+
.send('username=nicola&password=12345&acceptToc=true')
108+
.expect(400)
109+
.end((err) => {
110+
done(err)
111+
})
112+
})
113+
})
114+
115+
it('should not create WebID if T&C is not accepted', (done) => {
116+
const subdomain = supertest('https://' + host)
117+
subdomain.post('/api/accounts/new')
118+
.send('username=nicola&password=12345&acceptToc=')
119+
.expect(400, done)
120+
})
121+
122+
it('should create the default folders', function (done) {
123+
const subdomain = supertest('https://' + host)
124+
subdomain.post('/api/accounts/new')
125+
.send('username=nicola&password=12345&acceptToc=true')
126+
.expect(302)
127+
.end(function (err) {
128+
if (err) {
129+
return done(err)
130+
}
131+
const domain = host.split(':')[0]
132+
const card = read(path.join('accounts/nicola.' + domain,
133+
'profile/card$.ttl'))
134+
const cardAcl = read(path.join('accounts/nicola.' + domain,
135+
'profile/.acl'))
136+
const prefs = read(path.join('accounts/nicola.' + domain,
137+
'settings/prefs.ttl'))
138+
const inboxAcl = read(path.join('accounts/nicola.' + domain,
139+
'inbox/.acl'))
140+
const rootMeta = read(path.join('accounts/nicola.' + domain, '.meta'))
141+
const rootMetaAcl = read(path.join('accounts/nicola.' + domain,
142+
'.meta.acl'))
143+
144+
if (domain && card && cardAcl && prefs && inboxAcl && rootMeta &&
145+
rootMetaAcl) {
146+
done()
147+
} else {
148+
done(new Error('failed to create default files'))
149+
}
150+
})
151+
}).timeout(20000)
152+
153+
it('should link WebID to the root account', function (done) {
154+
const domain = supertest('https://' + host)
155+
domain.post('/api/accounts/new')
156+
.send('username=nicola&password=12345&acceptToc=true')
157+
.expect(302)
158+
.end(function (err) {
159+
if (err) {
160+
return done(err)
161+
}
162+
const subdomain = supertest('https://nicola.' + host)
163+
subdomain.get('/.meta')
164+
.expect(200)
165+
.end(function (err, data) {
166+
if (err) {
167+
return done(err)
168+
}
169+
const graph = $rdf.graph()
170+
$rdf.parse(
171+
data.text,
172+
graph,
173+
'https://nicola.' + host + '/.meta',
174+
'text/turtle')
175+
const statements = graph.statementsMatching(
176+
undefined,
177+
$rdf.sym('http://www.w3.org/ns/solid/terms#account'),
178+
undefined)
179+
if (statements.length === 1) {
180+
done()
181+
} else {
182+
done(new Error('missing link to WebID of account'))
183+
}
184+
})
185+
})
186+
}).timeout(20000)
187+
188+
describe('after setting up account', () => {
189+
beforeEach(done => {
190+
const subdomain = supertest('https://' + host)
191+
subdomain.post('/api/accounts/new')
192+
.send('username=nicola&password=12345&acceptToc=true')
193+
.end(done)
194+
})
195+
196+
it('should create a private settings container', function (done) {
197+
const subdomain = supertest('https://nicola.' + host)
198+
subdomain.head('/settings/')
199+
.expect(401)
200+
.end(function (err) {
201+
done(err)
202+
})
203+
})
204+
205+
it('should create a private prefs file in the settings container', function (done) {
206+
const subdomain = supertest('https://nicola.' + host)
207+
subdomain.head('/inbox/prefs.ttl')
208+
.expect(401)
209+
.end(function (err) {
210+
done(err)
211+
})
212+
})
213+
214+
it('should create a private inbox container', function (done) {
215+
const subdomain = supertest('https://nicola.' + host)
216+
subdomain.head('/inbox/')
217+
.expect(401)
218+
.end(function (err) {
219+
done(err)
220+
})
221+
})
222+
})
223+
})
224+
})
225+
226+
// FIXME: #1502
227+
describe('Single User signup page', () => {
228+
const serverUri = 'https://localhost:7457'
229+
const port = 7457
230+
let ldpHttpsServer
231+
rm('resources/accounts/single-user/')
232+
const rootDir = path.join(__dirname, '../resources/accounts/single-user/')
233+
const configPath = path.join(__dirname, '../resources/config')
234+
const ldp = ldnode.createServer({
235+
port,
236+
root: rootDir,
237+
configPath,
238+
sslKey: path.join(__dirname, '../keys/key.pem'),
239+
sslCert: path.join(__dirname, '../keys/cert.pem'),
240+
webid: true,
241+
multiuser: false,
242+
strictOrigin: true
243+
})
244+
const server = supertest(serverUri)
245+
246+
before(function (done) {
247+
ldpHttpsServer = ldp.listen(port, () => server.post('/api/accounts/new')
248+
.send('username=foo&password=12345&acceptToc=true')
249+
.end(done))
250+
})
251+
252+
after(function () {
253+
if (ldpHttpsServer) ldpHttpsServer.close()
254+
fs.removeSync(rootDir)
255+
})
256+
257+
it('should return a 406 not acceptable without accept text/html', done => {
258+
server.get('/')
259+
.set('accept', 'text/plain')
260+
.expect(406)
261+
.end(done)
262+
})
263+
})
264+
265+
// FIXME: #1502
266+
describe('Signup page where Terms & Conditions are not being enforced', () => {
267+
const port = 3457
268+
const host = `localhost:${port}`
269+
const root = path.join(__dirname, '../resources/accounts/')
270+
const configPath = path.join(__dirname, '../resources/config')
271+
const dbPath = path.join(__dirname, '../resources/accounts/db')
272+
const ldp = ldnode.createServer({
273+
port,
274+
root,
275+
configPath,
276+
sslKey: path.join(__dirname, '../keys/key.pem'),
277+
sslCert: path.join(__dirname, '../keys/cert.pem'),
278+
auth: 'oidc',
279+
webid: true,
280+
multiuser: true,
281+
strictOrigin: true,
282+
enforceToc: false
283+
})
284+
let ldpHttpsServer
285+
286+
before(function (done) {
287+
ldpHttpsServer = ldp.listen(port, done)
288+
})
289+
290+
after(function () {
291+
if (ldpHttpsServer) ldpHttpsServer.close()
292+
fs.removeSync(path.join(dbPath, 'oidc/users/users'))
293+
cleanDir(path.join(root, 'localhost'))
294+
rm('accounts/nicola.localhost')
295+
})
296+
297+
beforeEach(function () {
298+
rm('accounts/nicola.localhost')
299+
})
300+
301+
it('should not enforce T&C upon creating account', function (done) {
302+
const subdomain = supertest('https://' + host)
303+
subdomain.post('/api/accounts/new')
304+
.send('username=nicola&password=12345')
305+
.expect(302, done)
306+
})
307+
})

0 commit comments

Comments
 (0)