forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacl-checker.js
More file actions
65 lines (63 loc) · 2.01 KB
/
Copy pathacl-checker.js
File metadata and controls
65 lines (63 loc) · 2.01 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
'use strict'
const proxyquire = require('proxyquire')
const assert = require('chai').assert
const debug = require('../lib/debug').ACL
class PermissionSetAlwaysGrant {
checkAccess () {
return Promise.resolve(true)
}
}
class PermissionSetNeverGrant {
checkAccess () {
return Promise.resolve(false)
}
}
class PermissionSetAlwaysError {
checkAccess () {
return Promise.reject(new Error('Error thrown during checkAccess()'))
}
}
describe('ACLChecker unit test', () => {
it('should callback with null on grant success', done => {
let ACLChecker = proxyquire('../lib/acl-checker', {
'solid-permissions': { PermissionSet: PermissionSetAlwaysGrant }
})
let graph = {}
let accessType = ''
let user, mode, resource, aclUrl
let acl = new ACLChecker({ debug })
acl.checkAccess(graph, user, mode, resource, accessType, aclUrl, (err) => {
assert.isUndefined(err,
'Granted permission should result in an empty callback!')
done()
})
})
it('should callback with error on grant failure', done => {
let ACLChecker = proxyquire('../lib/acl-checker', {
'solid-permissions': { PermissionSet: PermissionSetNeverGrant }
})
let graph = {}
let accessType = ''
let user, mode, resource, aclUrl
let acl = new ACLChecker({ debug })
acl.checkAccess(graph, user, mode, resource, accessType, aclUrl, (err) => {
assert.ok(err instanceof Error,
'Denied permission should result in an error callback!')
done()
})
})
it('should callback with error on grant error', done => {
let ACLChecker = proxyquire('../lib/acl-checker', {
'solid-permissions': { PermissionSet: PermissionSetAlwaysError }
})
let graph = {}
let accessType = ''
let user, mode, resource, aclUrl
let acl = new ACLChecker({ debug })
acl.checkAccess(graph, user, mode, resource, accessType, aclUrl, (err) => {
assert.ok(err instanceof Error,
'Error during checkAccess should result in an error callback!')
done()
})
})
})