forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentity-provider.js
More file actions
232 lines (210 loc) · 7.04 KB
/
identity-provider.js
File metadata and controls
232 lines (210 loc) · 7.04 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
var supertest = require('supertest')
// Helper functions for the FS
var rm = require('./test-utils').rm
var $rdf = require('rdflib')
// var write = require('./test-utils').write
// var cp = require('./test-utils').cp
var read = require('./test-utils').read
var ldnode = require('../index')
var path = require('path')
describe('Identity Provider', function () {
this.timeout(10000)
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
var address = 'https://localhost:3457'
var host = 'localhost:3457'
var ldpHttpsServer
var ldp = ldnode.createServer({
root: path.join(__dirname, '/resources/accounts/'),
sslKey: path.join(__dirname, '/keys/key.pem'),
sslCert: path.join(__dirname, '/keys/cert.pem'),
webid: true,
idp: true,
strictOrigin: true
})
before(function (done) {
ldpHttpsServer = ldp.listen(3457, done)
})
after(function () {
if (ldpHttpsServer) ldpHttpsServer.close()
})
var server = supertest(address)
it('should redirect to signup on GET /accounts', function (done) {
server.get('/api/accounts')
.expect(302, done)
})
describe('accessing accounts', function () {
it('should be able to access public file of an account', function (done) {
var subdomain = supertest('https://tim.' + host)
subdomain.get('/hello.html')
.expect(200, done)
})
it('should get 404 if root does not exist', function (done) {
var 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('generating a certificate', function () {
beforeEach(function () {
rm('accounts/nicola.localhost')
})
after(function () {
rm('accounts/nicola.localhost')
})
it('should generate a certificate if spkac is valid', function (done) {
var spkac = read('example_spkac.cnf')
var subdomain = supertest.agent('https://nicola.' + host)
subdomain.post('/api/accounts/new')
.send('username=nicola')
.expect(200)
.end(function (err, req) {
if (err) return done(err)
subdomain.post('/api/accounts/cert')
.send('spkac=' + spkac + '&webid=https%3A%2F%2Fnicola.localhost%3A3457%2Fprofile%2Fcard%23me')
.expect('Content-Type', /application\/x-x509-user-cert/)
.expect(200)
.end(done)
})
})
it('should not generate a certificate if spkac is not valid', function (done) {
var subdomain = supertest('https://nicola.' + host)
subdomain.post('/api/accounts/new')
.send('username=nicola')
.expect(200)
.end(function (err) {
if (err) return done(err)
var spkac = ''
subdomain.post('/api/accounts/cert')
.send('webid=https://nicola.' + host + '/profile/card#me&spkac=' + spkac)
.expect(500, done)
})
})
})
describe('creating an account with POST', function () {
beforeEach(function () {
rm('accounts/nicola.localhost')
})
after(function () {
rm('accounts/nicola.localhost')
})
it('should return create WebID if only username is given', function (done) {
var subdomain = supertest('https://nicola.' + host)
subdomain.post('/api/accounts/new')
.send('username=nicola')
.expect(200)
.end(function (err) {
done(err)
})
})
it('should not create a WebID if it already exists', function (done) {
var subdomain = supertest('https://nicola.' + host)
subdomain.post('/api/accounts/new')
.send('username=nicola')
.expect(200)
.end(function (err) {
if (err) {
return done(err)
}
subdomain.post('/api/accounts/new')
.send('username=nicola')
.expect(406)
.end(function (err) {
done(err)
})
})
})
it('should create the default folders', function (done) {
var subdomain = supertest('https://nicola.' + host)
subdomain.post('/api/accounts/new')
.send('username=nicola')
.expect(200)
.end(function (err) {
if (err) {
return done(err)
}
var domain = host.split(':')[0]
var card = read(path.join('accounts/nicola.' + domain,
'profile/card'))
var cardAcl = read(path.join('accounts/nicola.' + domain,
'profile/card.acl'))
var prefs = read(path.join('accounts/nicola.' + domain,
'settings/prefs.ttl'))
var inboxAcl = read(path.join('accounts/nicola.' + domain,
'inbox/.acl'))
var rootMeta = read(path.join('accounts/nicola.' + domain, '.meta'))
var rootMetaAcl = read(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'))
}
})
})
it('should link WebID to the root account', function (done) {
var subdomain = supertest('https://nicola.' + host)
subdomain.post('/api/accounts/new')
.send('username=nicola')
.expect(200)
.end(function (err) {
if (err) {
return done(err)
}
subdomain.get('/.meta')
.expect(200)
.end(function (err, data) {
if (err) {
return done(err)
}
var graph = $rdf.graph()
$rdf.parse(
data.text,
graph,
'https://nicola.' + host + '/.meta',
'text/turtle')
var 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'))
}
})
})
})
it('should create a private settings container', function (done) {
var 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) {
var 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) {
var subdomain = supertest('https://nicola.' + host)
subdomain.head('/inbox/')
.expect(401)
.end(function (err) {
done(err)
})
})
})
})