Skip to content

Commit 48da605

Browse files
kjetilkrubensworks
authored andcommitted
Fix wrong tests that gave access with default set
1 parent fd076a7 commit 48da605

File tree

3 files changed

+22
-42
lines changed

3 files changed

+22
-42
lines changed

lib/acl-checker.js

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ class ACLChecker {
5555
return this.aclCached[cacheKey]
5656
}
5757
// console.log('TEST', this.acl)
58-
const resource = rdf.sym(this.resource)
58+
let resource = rdf.sym(this.resource)
59+
if (this.resource.endsWith('/' + this.suffix)) {
60+
// Then, the ACL file is for a directory
61+
resource = rdf.sym(ACLChecker.getDirectory(this.resource))
62+
}
5963
// const directory = acl.isContainer ? this.resource : null
6064
const directory = acl.isContainer ? rdf.sym(ACLChecker.getDirectory(acl.acl)) : null
6165
// console.log(ACLChecker.getDirectory(acl.acl))
@@ -109,45 +113,21 @@ class ACLChecker {
109113
// let directory = null
110114
// Create a cascade of reject handlers (one for each possible ACL)
111115
const possibleACLs = this.getPossibleACLs()
112-
const acls = [...possibleACLs]
113-
let returnAcl = null
114-
while (possibleACLs.length > 0 && !returnAcl) {
115-
const acl = possibleACLs.shift()
116-
try {
117-
const graph = await this.fetch(acl)
118-
const relative = resource.replace(acl.replace(/[^/]+$/, ''), './')
119-
debug(`Using ACL ${acl} for ${relative}`)
120-
returnAcl = { acl, graph, isContainer }
121-
} catch (err) {
122-
if (err && (err.code === 'ENOENT' || err.status === 404)) {
123-
isContainer = true
124-
continue
125-
} else if (err) {
126-
console.error('ERROR IN getNearestACL', err.code, err)
127-
debug(err)
128-
throw err
129-
}
130-
}
131-
}
132-
if (!returnAcl) {
133-
throw new HTTPError(403, `No ACL found for ${resource}, searched in \n- ${acls.join('\n- ')}`)
134-
}
135-
return returnAcl
136-
// const nearestACL = possibleACLs.reduce((prevACL, acl) => {
137-
// return prevACL.catch(() => new Promise((resolve, reject) => {
138-
// this.fetch(acl, (err, graph) => {
139-
// if (err && err.code !== 'ENOENT') {
140-
// isContainer = true
141-
// reject(err)
142-
// } else {
143-
// const relative = resource.replace(acl.replace(/[^/]+$/, ''), './')
144-
// debug(`Using ACL ${acl} for ${relative}`)
145-
// resolve({ acl, graph, isContainer })
146-
// }
147-
// })
148-
// }))
149-
// }, Promise.reject())
150-
// return nearestACL.catch(e => { throw new Error(`No ACL resource found, searched in \n- ${possibleACLs.join('\n- ')}`) })
116+
const nearestACL = possibleACLs.reduce((prevACL, acl) => {
117+
return prevACL.catch(() => new Promise((resolve, reject) => {
118+
this.fetch(acl, (err, graph) => {
119+
if (err && err.code !== 'ENOENT') {
120+
isContainer = true
121+
reject(err)
122+
} else {
123+
const relative = resource.replace(acl.replace(/[^/]+$/, ''), './')
124+
debug(`Using ACL ${acl} for ${relative}`)
125+
resolve({ acl, graph, isContainer })
126+
}
127+
})
128+
}))
129+
}, Promise.reject())
130+
return nearestACL.catch(e => { throw new Error(`No ACL resource found, searched in \n- ${possibleACLs.join('\n- ')}`) })
151131
}
152132

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

test/integration/acl-oidc-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
247247
})
248248
})
249249

250-
describe.only('Origin', function () {
250+
describe('Origin', function () {
251251
before(function () {
252252
rm('/accounts-acl/tim.localhost/origin/test-folder/.acl')
253253
})
@@ -332,7 +332,6 @@ describe('ACL with WebID+OIDC over HTTP', function () {
332332
options.headers.origin = origin2
333333

334334
request.head(options, function (error, response, body) {
335-
console.log(response)
336335
assert.equal(error, null)
337336
assert.equal(response.statusCode, 403)
338337
assert.equal(response.statusMessage, 'Origin Unauthorized')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<#0>
22
a <http://www.w3.org/ns/auth/acl#Authorization>;
33
<http://www.w3.org/ns/auth/acl#default> <./> ;
4+
<http://www.w3.org/ns/auth/acl#accessTo> <./> ;
45
<http://www.w3.org/ns/auth/acl#agent> <https://tim.localhost:7777/profile/card#me> ;
56
<http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Write>, <http://www.w3.org/ns/auth/acl#Control>.

0 commit comments

Comments
 (0)