|
|
|
@ -5,102 +5,141 @@ |
|
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
|
|
*/ |
|
|
|
|
|
|
|
import { Permission, permissionsAllow } from './permission'; |
|
|
|
import { Permission } from './permission'; |
|
|
|
|
|
|
|
describe('Permission', () => { |
|
|
|
it('Should_return_true_if_given_and_requested_permission_have_wildcards', () => { |
|
|
|
it('should check when permissions are not equal', () => { |
|
|
|
const g = new Permission('app.contents'); |
|
|
|
const r = new Permission('app.assets'); |
|
|
|
|
|
|
|
expect(g.allows(r)).toBeFalsy(); |
|
|
|
|
|
|
|
expect(g.includes(r)).toBeFalsy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should check when permissions are equal with wildcards', () => { |
|
|
|
const g = new Permission('app.*'); |
|
|
|
const r = new Permission('app.*'); |
|
|
|
|
|
|
|
expect(g.allows(r)).toBeTruthy(); |
|
|
|
|
|
|
|
expect(g.includes(r)).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should_return_true_if_given_permission_equals_requested_permission', () => { |
|
|
|
it('should check when equal permissions', () => { |
|
|
|
const g = new Permission('app.contents'); |
|
|
|
const r = new Permission('app.contents'); |
|
|
|
|
|
|
|
expect(g.allows(r)).toBeTruthy(); |
|
|
|
|
|
|
|
expect(g.includes(r)).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should_return_true_if_given_permission_is_parent_of_requested_permission', () => { |
|
|
|
it('should check when given is parent of requested', () => { |
|
|
|
const g = new Permission('app'); |
|
|
|
const r = new Permission('app.contents'); |
|
|
|
|
|
|
|
expect(g.allows(r)).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should_return_true_if_given_permission_is_alternative_of_requested_permission', () => { |
|
|
|
const g = new Permission('app.contents|schemas'); |
|
|
|
const r = new Permission('app.contents'); |
|
|
|
|
|
|
|
expect(g.allows(r)).toBeTruthy(); |
|
|
|
expect(g.includes(r)).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should_return_true_if_given_permission_equals_alternative_requested_permission', () => { |
|
|
|
it('should check when requested is parent of given', () => { |
|
|
|
const g = new Permission('app.contents'); |
|
|
|
const r = new Permission('app.contents|schemas'); |
|
|
|
const r = new Permission('app'); |
|
|
|
|
|
|
|
expect(g.allows(r)).toBeTruthy(); |
|
|
|
expect(g.allows(r)).toBeFalsy(); |
|
|
|
|
|
|
|
expect(g.includes(r)).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should_return_true_if_given_permission_has_wildcard_for_requested_permission', () => { |
|
|
|
it('should check when given is wildcard of requested', () => { |
|
|
|
const g = new Permission('app.*'); |
|
|
|
const r = new Permission('app.contents'); |
|
|
|
|
|
|
|
expect(g.allows(r)).toBeTruthy(); |
|
|
|
|
|
|
|
expect(g.includes(r)).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should_return_false_if_given_permission_not_equals_requested_permission', () => { |
|
|
|
it('should check when requested is wildcard of given', () => { |
|
|
|
const g = new Permission('app.contents'); |
|
|
|
const r = new Permission('app.assets'); |
|
|
|
const r = new Permission('app.*'); |
|
|
|
|
|
|
|
expect(g.allows(r)).toBeFalsy(); |
|
|
|
|
|
|
|
expect(g.includes(r)).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should_return_false_if_given_permission_is_child_of_requested_permission', () => { |
|
|
|
const g = new Permission('app.contents'); |
|
|
|
const r = new Permission('app'); |
|
|
|
it('should check when given is has alternatives of requested', () => { |
|
|
|
const g = new Permission('app.contents|schemas'); |
|
|
|
const r = new Permission('app.contents'); |
|
|
|
|
|
|
|
expect(g.allows(r)).toBeFalsy(); |
|
|
|
expect(g.allows(r)).toBeTruthy(); |
|
|
|
|
|
|
|
expect(g.includes(r)).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should_return_false_if_given_permission_has_no_wildcard_but_requested_has', () => { |
|
|
|
it('should check when requested is has alternatives of given', () => { |
|
|
|
const g = new Permission('app.contents'); |
|
|
|
const r = new Permission('app.*'); |
|
|
|
const r = new Permission('app.contents|schemas'); |
|
|
|
|
|
|
|
expect(g.allows(r)).toBeFalsy(); |
|
|
|
expect(g.allows(r)).toBeTruthy(); |
|
|
|
|
|
|
|
expect(g.includes(r)).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should_return_false_if_given_requested_permission_is_null', () => { |
|
|
|
|
|
|
|
it('should check for requested is null', () => { |
|
|
|
const g = new Permission('app.contents'); |
|
|
|
|
|
|
|
expect(g.allows(null!)).toBeFalsy(); |
|
|
|
|
|
|
|
expect(g.includes(null!)).toBeFalsy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should return true if any permission gives permission to requested', () => { |
|
|
|
const set = [ |
|
|
|
new Permission('app.contents'), |
|
|
|
new Permission('app.assets') |
|
|
|
]; |
|
|
|
|
|
|
|
expect(new Permission('app.contents').allowedBy(set)).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should return true if any permission includes parent given', () => { |
|
|
|
const set = [ |
|
|
|
new Permission('app.contents'), |
|
|
|
new Permission('app.assets') |
|
|
|
]; |
|
|
|
|
|
|
|
expect(new Permission('app').includedIn(set)).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should_return_true_if_any_permission_gives_permission_to_request', () => { |
|
|
|
const sut = [ |
|
|
|
it('should return true if any permission includes child given', () => { |
|
|
|
const set = [ |
|
|
|
new Permission('app.contents'), |
|
|
|
new Permission('app.assets') |
|
|
|
]; |
|
|
|
|
|
|
|
expect(permissionsAllow(sut, new Permission('app.contents'))).toBeTruthy(); |
|
|
|
expect(new Permission('app.contents.read').includedIn(set)).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should_return_false_if_none_permission_gives_permission_to_request', () => { |
|
|
|
const sut = [ |
|
|
|
it('should return false if none permission gives permission to requested', () => { |
|
|
|
const set = [ |
|
|
|
new Permission('app.contents'), |
|
|
|
new Permission('app.assets') |
|
|
|
]; |
|
|
|
|
|
|
|
expect(permissionsAllow(sut, new Permission('app.schemas'))).toBeFalsy(); |
|
|
|
expect(new Permission('app.schemas').allowedBy(set)).toBeFalsy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should_return_false_if_permission_to_request_is_null', () => { |
|
|
|
const sut = [ |
|
|
|
it('should return false if none permission includes given', () => { |
|
|
|
const set = [ |
|
|
|
new Permission('app.contents'), |
|
|
|
new Permission('app.assets') |
|
|
|
]; |
|
|
|
|
|
|
|
expect(permissionsAllow(sut, null!)).toBeFalsy(); |
|
|
|
expect(new Permission('other').allowedBy(set)).toBeFalsy(); |
|
|
|
}); |
|
|
|
}); |