2022-07-22 13:31:37 +02:00
|
|
|
-- ========================================================
|
|
|
|
-- Some Tests
|
|
|
|
-- --------------------------------------------------------
|
|
|
|
|
|
|
|
|
2024-09-16 08:50:25 +02:00
|
|
|
select rbac.isGranted(rbac.findRoleId('administrators'), rbac.findRoleId('test.package#aaa00:OWNER'));
|
|
|
|
select rbac.isGranted(rbac.findRoleId('test.package#aaa00:OWNER'), rbac.findRoleId('administrators'));
|
|
|
|
-- call rbac.grantRoleToRole(findRoleId('test.package#aaa00:OWNER'), findRoleId('administrators'));
|
|
|
|
-- call rbac.grantRoleToRole(findRoleId('administrators'), findRoleId('test.package#aaa00:OWNER'));
|
2022-07-22 13:31:37 +02:00
|
|
|
|
|
|
|
select count(*)
|
2024-09-16 08:50:25 +02:00
|
|
|
FROM rbac.queryAllPermissionsOfSubjectIdForObjectUuids(rbac.findRbacSubject('superuser-fran@hostsharing.net'),
|
|
|
|
ARRAY(select uuid from test.customer where reference < 1100000));
|
2022-07-22 13:31:37 +02:00
|
|
|
select count(*)
|
2024-09-16 08:50:25 +02:00
|
|
|
FROM rbac.queryAllPermissionsOfSubjectId(findRbacSubject('superuser-fran@hostsharing.net'));
|
2022-07-22 13:31:37 +02:00
|
|
|
select *
|
2024-09-16 08:50:25 +02:00
|
|
|
FROM rbac.queryAllPermissionsOfSubjectId(findRbacSubject('alex@example.com'));
|
2022-07-22 13:31:37 +02:00
|
|
|
select *
|
2024-09-16 08:50:25 +02:00
|
|
|
FROM rbac.queryAllPermissionsOfSubjectId(findRbacSubject('rosa@example.com'));
|
2022-07-22 13:31:37 +02:00
|
|
|
|
|
|
|
select *
|
2024-09-14 10:34:11 +02:00
|
|
|
FROM rbac.queryAllRbacSubjectsWithPermissionsFor(rbac.findEffectivePermissionId('customer',
|
2024-09-16 08:50:25 +02:00
|
|
|
(SELECT uuid FROM rbac.RbacObject WHERE objectTable = 'customer' LIMIT 1),
|
2022-07-22 13:31:37 +02:00
|
|
|
'add-package'));
|
|
|
|
select *
|
2024-09-14 10:34:11 +02:00
|
|
|
FROM rbac.queryAllRbacSubjectsWithPermissionsFor(rbac.findEffectivePermissionId('package',
|
2024-09-16 08:50:25 +02:00
|
|
|
(SELECT uuid FROM rbac.RbacObject WHERE objectTable = 'package' LIMIT 1),
|
2024-03-11 12:30:43 +01:00
|
|
|
'DELETE'));
|
2022-07-22 13:31:37 +02:00
|
|
|
|
|
|
|
DO LANGUAGE plpgsql
|
|
|
|
$$
|
|
|
|
DECLARE
|
|
|
|
userId uuid;
|
|
|
|
result bool;
|
|
|
|
BEGIN
|
2024-09-16 09:15:03 +02:00
|
|
|
userId = rbac.findRbacSubject('superuser-alex@hostsharing.net');
|
2024-09-14 10:34:11 +02:00
|
|
|
result = (SELECT * FROM rbac.isPermissionGrantedToSubject(rbac.findPermissionId('package', 94928, 'add-package'), userId));
|
2022-07-22 13:31:37 +02:00
|
|
|
IF (result) THEN
|
|
|
|
RAISE EXCEPTION 'expected permission NOT to be granted, but it is';
|
|
|
|
end if;
|
|
|
|
|
2024-09-14 10:34:11 +02:00
|
|
|
result = (SELECT * FROM rbac.isPermissionGrantedToSubject(rbac.findPermissionId('package', 94928, 'SELECT'), userId));
|
2022-07-22 13:31:37 +02:00
|
|
|
IF (NOT result) THEN
|
|
|
|
RAISE EXCEPTION 'expected permission to be granted, but it is NOT';
|
|
|
|
end if;
|
|
|
|
|
|
|
|
RAISE LOG 'isPermissionGrantedToSubjectId test passed';
|
|
|
|
END;
|
|
|
|
$$;
|
|
|
|
|