-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91f4dcf
commit 61c7dd9
Showing
6 changed files
with
129 additions
and
50 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
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 |
---|---|---|
@@ -1,14 +1,12 @@ | ||
const _ = require('lodash') | ||
const { setupLogger } = require('@vimesh/logger') | ||
const { evaluatePermissionFormular } = require('../utils') | ||
const { evaluatePermissionFormular, empower } = require('../utils') | ||
|
||
setupLogger() | ||
|
||
it('normal cases', () => { | ||
let ownedPerms = { | ||
'user.view': true, | ||
'user.edit': true | ||
} | ||
let ownedPerms = empower(['user.view', 'user.edit']) | ||
expect(ownedPerms).toStrictEqual({ 'user.view': true, 'user.edit': true }) | ||
let result = evaluatePermissionFormular('user.view && user.edit', ownedPerms) | ||
expect(result).toBeTruthy() | ||
result = evaluatePermissionFormular('user.edit || user.delete', ownedPerms) | ||
|
@@ -21,19 +19,41 @@ it('normal cases', () => { | |
expect(result).toBeTruthy() | ||
}) | ||
|
||
it('normal cases @ scope', () => { | ||
let ownedPerms = empower(['user@{account}.edit', 'user@{account}.view'], { account: 1 }) | ||
expect(ownedPerms).toStrictEqual({ '[email protected]': true, '[email protected]': true }) | ||
let result = evaluatePermissionFormular('[email protected] && [email protected]', ownedPerms) | ||
expect(result).toBeTruthy() | ||
result = evaluatePermissionFormular('[email protected] && [email protected]', ownedPerms) | ||
expect(result).toBeFalsy() | ||
result = evaluatePermissionFormular('[email protected] || [email protected]', ownedPerms) | ||
expect(result).toBeTruthy() | ||
result = evaluatePermissionFormular('[email protected] && [email protected]', ownedPerms) | ||
expect(result).toBeFalsy() | ||
}) | ||
|
||
it('all allowed', () => { | ||
let ownedPerms = { | ||
'*.*': true | ||
} | ||
let ownedPerms = empower('*.*') | ||
expect(ownedPerms).toStrictEqual({ '*.*': true }) | ||
let result = evaluatePermissionFormular('user.edit && user.delete', ownedPerms) | ||
expect(result).toBeTruthy() | ||
}) | ||
|
||
it('evaluate permission @ scope', () => { | ||
let ownedPerms = empower(['user@{account}.edit', 'user@{account}.delete']) | ||
expect(ownedPerms).toStrictEqual({ 'user@{account}.edit': true, 'user@{account}.delete': true }) | ||
let result = evaluatePermissionFormular('user@{account}.edit && user@{account}.delete', ownedPerms, { account: 'account3' }) | ||
expect(result).toBeTruthy() | ||
|
||
ownedPerms = empower(['user@{account}.edit', 'user@{account}.delete'], { account: 'account3' }) | ||
expect(ownedPerms).toStrictEqual({ '[email protected]': true, '[email protected]': true }) | ||
result = evaluatePermissionFormular('user@{account}.edit && user@{account}.delete', ownedPerms, { account: 'account3' }) | ||
expect(result).toBeTruthy() | ||
}) | ||
|
||
it('all actions in a resource is allowed ', () => { | ||
let ownedPerms = { | ||
'user.*': true, | ||
'order.view': true | ||
} | ||
let ownedPerms = empower(['user.*', 'order.view']) | ||
expect(ownedPerms).toStrictEqual({ 'user.*': true, 'order.view': true }) | ||
let result = evaluatePermissionFormular('user.edit && order.view', ownedPerms) | ||
expect(result).toBeTruthy() | ||
result = evaluatePermissionFormular('user.edit && order.edit', ownedPerms) | ||
|
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