mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
feat: Add permissions package (no-changelog) (#7650)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
116
packages/@n8n/permissions/test/hasScope.test.ts
Normal file
116
packages/@n8n/permissions/test/hasScope.test.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import { hasScope } from '@/hasScope';
|
||||
import type { Scope } from '@/types';
|
||||
|
||||
const ownerPermissions: Scope[] = [
|
||||
'workflow:create',
|
||||
'workflow:read',
|
||||
'workflow:update',
|
||||
'workflow:delete',
|
||||
'workflow:list',
|
||||
'user:create',
|
||||
'user:read',
|
||||
'user:update',
|
||||
'user:delete',
|
||||
'user:list',
|
||||
'credential:create',
|
||||
'credential:read',
|
||||
'credential:update',
|
||||
'credential:delete',
|
||||
'credential:list',
|
||||
'variable:create',
|
||||
'variable:read',
|
||||
'variable:update',
|
||||
'variable:delete',
|
||||
'variable:list',
|
||||
];
|
||||
const memberPermissions: Scope[] = ['user:list', 'variable:list', 'variable:read'];
|
||||
|
||||
describe('hasScope', () => {
|
||||
test('should work with a single permission on both modes with only global scopes', () => {
|
||||
expect(
|
||||
hasScope(
|
||||
'user:list',
|
||||
{
|
||||
global: memberPermissions,
|
||||
},
|
||||
{ mode: 'oneOf' },
|
||||
),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
hasScope(
|
||||
'user:list',
|
||||
{
|
||||
global: memberPermissions,
|
||||
},
|
||||
{ mode: 'allOf' },
|
||||
),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
hasScope(
|
||||
'workflow:read',
|
||||
{
|
||||
global: memberPermissions,
|
||||
},
|
||||
{ mode: 'oneOf' },
|
||||
),
|
||||
).toBe(false);
|
||||
|
||||
expect(
|
||||
hasScope(
|
||||
'workflow:read',
|
||||
{
|
||||
global: memberPermissions,
|
||||
},
|
||||
{ mode: 'allOf' },
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
test('should work with oneOf mode', () => {
|
||||
expect(
|
||||
hasScope(['workflow:create', 'workflow:read'], {
|
||||
global: ownerPermissions,
|
||||
}),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
hasScope(['workflow:create', 'workflow:read'], {
|
||||
global: memberPermissions,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
test('should work with allOf mode', () => {
|
||||
expect(
|
||||
hasScope(
|
||||
['workflow:create', 'workflow:read'],
|
||||
{
|
||||
global: ownerPermissions,
|
||||
},
|
||||
{ mode: 'allOf' },
|
||||
),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
hasScope(
|
||||
['workflow:create', 'workflow:read'],
|
||||
{
|
||||
global: memberPermissions,
|
||||
},
|
||||
{ mode: 'allOf' },
|
||||
),
|
||||
).toBe(false);
|
||||
|
||||
expect(
|
||||
hasScope(
|
||||
['workflow:create', 'user:list'],
|
||||
{
|
||||
global: memberPermissions,
|
||||
},
|
||||
{ mode: 'allOf' },
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user