Skip to content

Commit b104918

Browse files
megothrubensworks
authored andcommitted
Fixed broken tests in AccountManager (OIDC account creation tests)
1 parent ff44551 commit b104918

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

lib/acl-checker.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ class ACLChecker {
5050
// aclCheck.checkAccess(acl.graph, this.resource)
5151

5252
// Check the resource's permissions
53-
this.acl = this.acl || await this.getNearestACL()
53+
this.acl = this.acl || await this.getNearestACL().catch(err => {
54+
throw new HTTPError(403, `Found no ACL file:\n${err}`)
55+
})
56+
// console.log('TEST', this.acl)
5457
const resource = rdf.sym(this.resource)
5558
// const directory = this.acl.isContainer ? this.resource : null
5659
const directory = this.acl.isContainer ? rdf.sym(ACLChecker.getDirectory(this.acl.acl)) : null
@@ -96,10 +99,11 @@ class ACLChecker {
9699
let isContainer = false
97100
// let directory = null
98101
// Create a cascade of reject handlers (one for each possible ACL)
99-
const nearestACL = this.getPossibleACLs().reduce((prevACL, acl) => {
102+
const possibleACLs = this.getPossibleACLs()
103+
const nearestACL = possibleACLs.reduce((prevACL, acl) => {
100104
return prevACL.catch(() => new Promise((resolve, reject) => {
101105
this.fetch(acl, (err, graph) => {
102-
if (err && err.code !== 'ENOENT' || !graph || !graph.length) {
106+
if (err && err.code !== 'ENOENT') {
103107
isContainer = true
104108
reject(err)
105109
} else {
@@ -110,7 +114,7 @@ class ACLChecker {
110114
})
111115
}))
112116
}, Promise.reject())
113-
return nearestACL.catch(e => { throw new Error('No ACL resource found') })
117+
return nearestACL.catch(e => { throw new Error(`No ACL resource found, searched in \n- ${possibleACLs.join('\n- ')}`) })
114118
}
115119

116120
// Gets all possible ACL paths that apply to the resource

test/integration/account-creation-oidc-test.js

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -183,39 +183,48 @@ describe('AccountManager (OIDC account creation tests)', function () {
183183
})
184184
}).timeout(20000)
185185

186-
it('should create a private settings container', function (done) {
187-
var subdomain = supertest('https://nicola.' + host)
188-
subdomain.head('/settings/')
189-
.expect(401)
190-
.end(function (err) {
191-
done(err)
192-
})
193-
})
186+
describe('after setting up account', () => {
187+
beforeEach(done => {
188+
var subdomain = supertest('https://nicola.' + host)
189+
subdomain.post('/api/accounts/new')
190+
.send('username=nicola&password=12345&acceptToc=true')
191+
.end(done)
192+
})
194193

195-
it('should create a private prefs file in the settings container', function (done) {
196-
var subdomain = supertest('https://nicola.' + host)
197-
subdomain.head('/inbox/prefs.ttl')
198-
.expect(401)
199-
.end(function (err) {
200-
done(err)
201-
})
202-
})
194+
it('should create a private settings container', function (done) {
195+
var subdomain = supertest('https://nicola.' + host)
196+
subdomain.head('/settings/')
197+
.expect(401)
198+
.end(function (err) {
199+
done(err)
200+
})
201+
})
203202

204-
it('should create a private inbox container', function (done) {
205-
var subdomain = supertest('https://nicola.' + host)
206-
subdomain.head('/inbox/')
207-
.expect(401)
208-
.end(function (err) {
209-
done(err)
210-
})
203+
it('should create a private prefs file in the settings container', function (done) {
204+
var subdomain = supertest('https://nicola.' + host)
205+
subdomain.head('/inbox/prefs.ttl')
206+
.expect(401)
207+
.end(function (err) {
208+
done(err)
209+
})
210+
})
211+
212+
it('should create a private inbox container', function (done) {
213+
var subdomain = supertest('https://nicola.' + host)
214+
subdomain.head('/inbox/')
215+
.expect(401)
216+
.end(function (err) {
217+
done(err)
218+
})
219+
})
211220
})
212221
})
213222
})
214223

215224
describe('Single User signup page', () => {
216225
const serverUri = 'https://localhost:7457'
217226
const port = 7457
218-
var ldpHttpsServer
227+
let ldpHttpsServer
219228
const rootDir = path.join(__dirname, '../resources/accounts/single-user/')
220229
const configPath = path.join(__dirname, '../resources/config')
221230
const ldp = ldnode.createServer({
@@ -231,7 +240,9 @@ describe('Single User signup page', () => {
231240
const server = supertest(serverUri)
232241

233242
before(function (done) {
234-
ldpHttpsServer = ldp.listen(port, done)
243+
ldpHttpsServer = ldp.listen(port, () => server.post('/api/accounts/new')
244+
.send('username=foo&password=12345&acceptToc=true')
245+
.end(done))
235246
})
236247

237248
after(function () {

0 commit comments

Comments
 (0)