forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-accounts.js
More file actions
128 lines (116 loc) · 3.64 KB
/
api-accounts.js
File metadata and controls
128 lines (116 loc) · 3.64 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
const Solid = require('../')
const parallel = require('run-parallel')
const waterfall = require('run-waterfall')
const path = require('path')
const supertest = require('supertest')
const expect = require('chai').expect
const nock = require('nock')
// In this test we always assume that we are Alice
describe('API', () => {
let aliceServer
let bobServer
let alice
let bob
const alicePod = Solid.createServer({
root: path.join(__dirname, '/resources/accounts-scenario/alice'),
sslKey: path.join(__dirname, '/keys/key.pem'),
sslCert: path.join(__dirname, '/keys/cert.pem'),
auth: 'oidc',
dataBrowser: false,
fileBrowser: false,
webid: true
})
const bobPod = Solid.createServer({
root: path.join(__dirname, '/resources/accounts-scenario/bob'),
sslKey: path.join(__dirname, '/keys/key.pem'),
sslCert: path.join(__dirname, '/keys/cert.pem'),
auth: 'oidc',
dataBrowser: false,
fileBrowser: false,
webid: true
})
function getBobFoo (alice, bob, done) {
bob.get('/foo')
.expect(401)
.end((err, res) => {
if (err) return done(err)
expect(res).to.match(/META http-equiv="refresh"/)
done()
})
}
function postBobDiscoverSignIn (alice, bob, done) {
done()
}
function entersPasswordAndConsent (alice, bob, done) {
done()
}
before(function (done) {
parallel([
(cb) => {
aliceServer = alicePod.listen(5000, cb)
alice = supertest('https://localhost:5000')
},
(cb) => {
bobServer = bobPod.listen(5001, cb)
bob = supertest('https://localhost:5001')
}
], done)
})
after(function () {
if (aliceServer) aliceServer.close()
if (bobServer) bobServer.close()
})
describe('APIs', () => {
describe('/api/accounts/signin', () => {
it('should complain if a URL is missing', (done) => {
alice.post('/api/accounts/signin')
.expect(400)
.end(done)
})
it('should complain if a URL is invalid', (done) => {
alice.post('/api/accounts/signin')
.send('webid=HELLO')
.expect(400)
.end(done)
})
it('should return a 400 if endpoint doesn\'t have Link Headers', (done) => {
nock('https://amazingwebsite.tld').intercept('/', 'OPTIONS').reply(200)
alice.post('/api/accounts/signin')
.send('webid=https://amazingwebsite.tld/')
.expect(400)
.end(done)
})
it('should return a 400 if endpoint doesn\'t have oidc in the headers', (done) => {
nock('https://amazingwebsite.tld').intercept('/', 'OPTIONS').reply(200, '', {
'Link': function (req, res, body) {
return '<https://oidc.amazingwebsite.tld>; rel="oidc.issuer"'
}})
alice.post('/api/accounts/signin')
.send('webid=https://amazingwebsite.tld/')
.expect(302)
.end((err, res) => {
expect(res.header.location).to.eql('https://oidc.amazingwebsite.tld')
done(err)
})
})
})
})
describe('Auth workflow', () => {
it.skip('step1: User tries to get /foo and gets 401 and meta redirect', (done) => {
getBobFoo(alice, bob, done)
})
it.skip('step2: User enters webId to signin', (done) => {
postBobDiscoverSignIn(alice, bob, done)
})
it.skip('step3: User enters password', (done) => {
entersPasswordAndConsent(alice, bob, done)
})
it.skip('entire flow', (done) => {
waterfall([
(cb) => getBobFoo(alice, bob, cb),
(cb) => postBobDiscoverSignIn(alice, bob, cb),
(cb) => entersPasswordAndConsent(alice, bob, cb)
], done)
})
})
})