Created
July 9, 2017 02:44
-
-
Save OR13/a9b49cece38c32d67166c2eb56a87494 to your computer and use it in GitHub Desktop.
canRoleActionResource
This file contains hidden or 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
| describe('canRoleActionResource(role, action, resource) congruity to can(role).action(resource)', () => { | |
| it('for defined permissions', async () => { | |
| // We start by granting an admin create:any for event store | |
| let grantAdminCreateAnyEventStore = { role: 'admin', resource: 'grant', action: 'create:any', attributes: ['*'] } | |
| ac.setGrants([grantAdminCreateAnyEventStore]) | |
| // A defined permission in Node | |
| let acAdminCreateAnyEventStorePerm = ac.can('admin').createAny('grant') | |
| assert(acAdminCreateAnyEventStorePerm.granted, "expect admin can create any grant") | |
| // Now we do the same in Ethereum | |
| let tx = await tac.setGrant('admin', 'grant', 'create:any', ['*'], { | |
| from: accounts[0] | |
| }) | |
| let grantFromTxEvent = grantItemFromEvent(tx.logs[0].args) | |
| let lastGrantIndex = (await tac.grantCount.call()).toNumber() - 1 | |
| let grantValues = await tac.getGrant.call(lastGrantIndex) | |
| let grantFromMethodCall = grantItemFromValues(grantValues) | |
| assert(_.isEqual(grantAdminCreateAnyEventStore, grantFromTxEvent)) | |
| assert(_.isEqual(grantFromTxEvent, grantFromMethodCall)) | |
| // A defined permission in Ethereum | |
| let permissionValues = await tac.canRoleActionResource.call('admin', 'create:any', 'grant') | |
| let tacAdminCreateAnyGrantPerm = permissionFromCanRoleActionResourceValues(permissionValues) | |
| assert( | |
| relaxedPermsAreEqual(acAdminCreateAnyEventStorePerm, tacAdminCreateAnyGrantPerm), | |
| 'expect ac & tac to agree that admins can create any grant' | |
| ); | |
| }) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment