hs.hsadmin.ng/sql/rbac-tests.sql

51 lines
2.3 KiB
MySQL
Raw Normal View History

2022-07-22 13:31:37 +02:00
-- ========================================================
-- Some Tests
-- --------------------------------------------------------
select isGranted(findRoleId('administrators'), findRoleId('test_package#aaa00:OWNER'));
select isGranted(findRoleId('test_package#aaa00:OWNER'), findRoleId('administrators'));
-- call grantRoleToRole(findRoleId('test_package#aaa00:OWNER'), findRoleId('administrators'));
-- call grantRoleToRole(findRoleId('administrators'), findRoleId('test_package#aaa00:OWNER'));
2022-07-22 13:31:37 +02:00
select count(*)
2024-09-13 17:23:35 +02:00
FROM queryAllPermissionsOfSubjectIdForObjectUuids(findRbacSubject('superuser-fran@hostsharing.net'),
2022-07-22 13:31:37 +02:00
ARRAY(select uuid from customer where reference < 1100000));
select count(*)
2024-09-13 17:23:35 +02:00
FROM queryAllPermissionsOfSubjectId(findRbacSubject('superuser-fran@hostsharing.net'));
2022-07-22 13:31:37 +02:00
select *
2024-09-13 17:23:35 +02:00
FROM queryAllPermissionsOfSubjectId(findRbacSubject('alex@example.com'));
2022-07-22 13:31:37 +02:00
select *
2024-09-13 17:23:35 +02:00
FROM queryAllPermissionsOfSubjectId(findRbacSubject('rosa@example.com'));
2022-07-22 13:31:37 +02:00
select *
2024-09-13 17:23:35 +02:00
FROM queryAllRbacSubjectsWithPermissionsFor(findEffectivePermissionId('customer',
2022-07-22 13:31:37 +02:00
(SELECT uuid FROM RbacObject WHERE objectTable = 'customer' LIMIT 1),
'add-package'));
select *
2024-09-13 17:23:35 +02:00
FROM queryAllRbacSubjectsWithPermissionsFor(findEffectivePermissionId('package',
2022-07-22 13:31:37 +02:00
(SELECT uuid FROM RbacObject WHERE objectTable = 'package' LIMIT 1),
'DELETE'));
2022-07-22 13:31:37 +02:00
DO LANGUAGE plpgsql
$$
DECLARE
userId uuid;
result bool;
BEGIN
2024-09-13 17:23:35 +02:00
userId = findRbacSubject('superuser-alex@hostsharing.net');
result = (SELECT * FROM isPermissionGrantedToSubject(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;
result = (SELECT * FROM isPermissionGrantedToSubject(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;
$$;