This repository has been archived by the owner on Jan 3, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add hasPermissions methods * Add tests, update coverage scripts
- Loading branch information
Showing
14 changed files
with
173 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ dist/ | |
.python-version | ||
*.log | ||
.nyc_output | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: '@istanbuljs/nyc-config-typescript', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
const test = require('tape'); | ||
const { CapabilitiesController } = require('../dist'); | ||
const clone = require('clone'); | ||
|
||
function noop () {} | ||
|
||
const domain1 = 'foo.com'; | ||
const domain2 = 'bar.io'; | ||
|
||
const method1 = 'restricted'; | ||
const method2 = 'restricted2'; | ||
|
||
const domains = { | ||
[domain1]: { | ||
permissions: [ | ||
{ | ||
parentCapability: method1, | ||
id: 'abc', | ||
}, | ||
], | ||
}, | ||
[domain2]: { | ||
permissions: [ | ||
{ | ||
parentCapability: method2, | ||
id: 'xyz', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
test('hasPermissions returns false if no permissions', (t) => { | ||
const ctrl = new CapabilitiesController({ | ||
requestUserApproval: noop, | ||
}); | ||
|
||
t.equal(ctrl.hasPermissions(domain1), false, 'should return false'); | ||
t.end(); | ||
}); | ||
|
||
test('hasPermission returns false if no permissions', (t) => { | ||
const ctrl = new CapabilitiesController({ | ||
requestUserApproval: noop, | ||
}); | ||
|
||
t.equal(ctrl.hasPermissions(domain1, method1), false, 'should return false'); | ||
t.end(); | ||
}); | ||
|
||
test('hasPermissions returns true with permissions', (t) => { | ||
const ctrl = new CapabilitiesController({ | ||
requestUserApproval: noop, | ||
}, | ||
{ | ||
domains: clone(domains), | ||
}); | ||
|
||
t.equal(ctrl.hasPermissions(domain1), true, 'should return true for domain1'); | ||
t.equal(ctrl.hasPermissions(domain2), true, 'should return true for domain2'); | ||
t.end(); | ||
}); | ||
|
||
test('hasPermission returns true with permissions and correct method', (t) => { | ||
const ctrl = new CapabilitiesController({ | ||
requestUserApproval: noop, | ||
}, | ||
{ | ||
domains: clone(domains), | ||
}); | ||
|
||
t.equal( | ||
ctrl.hasPermission(domain1, method1), | ||
true, | ||
'should return true for domain1 and method1' | ||
); | ||
t.equal( | ||
ctrl.hasPermission(domain2, method2), | ||
true, | ||
'should return true for domain2 and method2' | ||
); | ||
t.end(); | ||
}); | ||
|
||
test('hasPermissions returns with permissions but wrong domain', (t) => { | ||
const ctrl = new CapabilitiesController({ | ||
requestUserApproval: noop, | ||
}, | ||
{ | ||
domains: { | ||
[domain1]: clone(domains[domain1]), | ||
}, | ||
}); | ||
|
||
t.equal(ctrl.hasPermissions(domain1), true, 'should return true for domain1'); | ||
t.equal(ctrl.hasPermissions(domain2), false, 'should return false for domain2'); | ||
t.end(); | ||
}); | ||
|
||
test('hasPermission returns false with permissions but wrong method', (t) => { | ||
const ctrl = new CapabilitiesController({ | ||
requestUserApproval: noop, | ||
}, | ||
{ | ||
domains: clone(domains), | ||
}); | ||
|
||
t.equal( | ||
ctrl.hasPermission(domain1, method2), | ||
false, | ||
'should return false for domain1 and method2' | ||
); | ||
t.equal( | ||
ctrl.hasPermission(domain2, method1), | ||
false, | ||
'should return false for domain2 and method1' | ||
); | ||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters