Skip to content

Commit 2a0ca11

Browse files
Pass in fetchGraph to ACLChecker/PermissionSet
1 parent aa3ff26 commit 2a0ca11

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

lib/acl-checker.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const PermissionSet = require('solid-permissions').PermissionSet
44
const rdf = require('rdflib')
55
const debug = require('./debug').ACL
66
const HTTPError = require('./http-error')
7+
const { promisify } = require('util')
78

89
const DEFAULT_ACL_SUFFIX = '.acl'
910

@@ -32,9 +33,11 @@ class ACLChecker {
3233
.then(acl => this.getPermissionSet(acl))
3334
}
3435

36+
const options = { fetchGraph: promisify(this.fetch) }
37+
3538
// Check the resource's permissions
3639
return this._permissionSet
37-
.then(acls => this.checkAccess(acls, user, mode))
40+
.then(acls => this.checkAccess(acls, user, mode, options))
3841
.catch(() => {
3942
if (!user) {
4043
throw new HTTPError(401, `Access to ${this.resource} requires authorization`)
@@ -87,7 +90,8 @@ class ACLChecker {
8790

8891
// Tests whether the permissions allow a given operation
8992
checkAccess (permissionSet, user, mode) {
90-
return permissionSet.checkAccess(this.resource, user, mode)
93+
const options = { fetchGraph: promisify(this.fetch) }
94+
return permissionSet.checkAccess(this.resource, user, mode, options)
9195
.then(hasAccess => {
9296
if (hasAccess) {
9397
return true

test/unit/acl-checker-test.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,41 @@ const chai = require('chai')
44
const { expect } = chai
55
chai.use(require('chai-as-promised'))
66

7+
const options = { fetch: (url, callback) => {} }
8+
79
describe('ACLChecker unit test', () => {
10+
let acl
11+
12+
beforeEach(() => {
13+
acl = new ACLChecker('http://ex.com/.acl', options)
14+
})
15+
816
describe('checkAccess', () => {
917
it('should callback with null on grant success', () => {
10-
let acl = new ACLChecker()
1118
let acls = { checkAccess: () => Promise.resolve(true) }
1219
return expect(acl.checkAccess(acls)).to.eventually.be.true
1320
})
1421
it('should callback with error on grant failure', () => {
15-
let acl = new ACLChecker()
1622
let acls = { checkAccess: () => Promise.resolve(false) }
1723
return expect(acl.checkAccess(acls))
1824
.to.be.rejectedWith('ACL file found but no matching policy found')
1925
})
2026
it('should callback with error on grant error', () => {
21-
let acl = new ACLChecker()
2227
let acls = { checkAccess: () => Promise.reject(new Error('my error')) }
2328
return expect(acl.checkAccess(acls)).to.be.rejectedWith('my error')
2429
})
2530
})
2631

2732
describe('getPossibleACLs', () => {
2833
it('returns all possible ACLs of the root', () => {
29-
const aclChecker = new ACLChecker('http://ex.org/')
34+
const aclChecker = new ACLChecker('http://ex.org/', options)
3035
expect(aclChecker.getPossibleACLs()).to.deep.equal([
3136
'http://ex.org/.acl'
3237
])
3338
})
3439

3540
it('returns all possible ACLs of a regular file', () => {
36-
const aclChecker = new ACLChecker('http://ex.org/abc/def/ghi')
41+
const aclChecker = new ACLChecker('http://ex.org/abc/def/ghi', options)
3742
expect(aclChecker.getPossibleACLs()).to.deep.equal([
3843
'http://ex.org/abc/def/ghi.acl',
3944
'http://ex.org/abc/def/.acl',
@@ -43,7 +48,7 @@ describe('ACLChecker unit test', () => {
4348
})
4449

4550
it('returns all possible ACLs of an ACL file', () => {
46-
const aclChecker = new ACLChecker('http://ex.org/abc/def/ghi.acl')
51+
const aclChecker = new ACLChecker('http://ex.org/abc/def/ghi.acl', options)
4752
expect(aclChecker.getPossibleACLs()).to.deep.equal([
4853
'http://ex.org/abc/def/ghi.acl',
4954
'http://ex.org/abc/def/.acl',
@@ -53,7 +58,7 @@ describe('ACLChecker unit test', () => {
5358
})
5459

5560
it('returns all possible ACLs of a directory', () => {
56-
const aclChecker = new ACLChecker('http://ex.org/abc/def/ghi/')
61+
const aclChecker = new ACLChecker('http://ex.org/abc/def/ghi/', options)
5762
expect(aclChecker.getPossibleACLs()).to.deep.equal([
5863
'http://ex.org/abc/def/ghi/.acl',
5964
'http://ex.org/abc/def/.acl',

0 commit comments

Comments
 (0)