diff --git a/db/sql/00_msar.sql b/db/sql/00_msar.sql index 9aa2976a31..9633e0f710 100644 --- a/db/sql/00_msar.sql +++ b/db/sql/00_msar.sql @@ -1196,7 +1196,7 @@ CREATE OR REPLACE FUNCTION msar.build_grant_membership_expr(parent_rol_id regrole, g_roles oid[]) RETURNS TEXT AS $$ SELECT string_agg( format( - 'GRANT %1$s TO %2$s', + 'GRANT %1$I TO %2$I', msar.get_role_name(parent_rol_id), msar.get_role_name(rol_id) ), @@ -1210,7 +1210,7 @@ CREATE OR REPLACE FUNCTION msar.build_revoke_membership_expr(parent_rol_id regrole, r_roles oid[]) RETURNS TEXT AS $$ SELECT string_agg( format( - 'REVOKE %1$s FROM %2$s', + 'REVOKE %1$I FROM %2$I', msar.get_role_name(parent_rol_id), msar.get_role_name(rol_id) ), diff --git a/db/sql/test_00_msar.sql b/db/sql/test_00_msar.sql index ad2a7a3cad..3bf9e86f56 100644 --- a/db/sql/test_00_msar.sql +++ b/db/sql/test_00_msar.sql @@ -5440,3 +5440,33 @@ BEGIN ); END; $$ LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION test_build_grant_revoke_membership_expr() RETURNS SETOF TEXT AS $$ +BEGIN + CREATE USER "Alice"; + CREATE USER "Bob"; + CREATE USER carol; + RETURN NEXT is( + msar.build_grant_membership_expr('"Alice"'::regrole::oid, ARRAY['"Bob"'::regrole::oid]), + E'GRANT "Alice" TO "Bob";\n' + ); + RETURN NEXT is( + msar.build_grant_membership_expr( + '"Alice"'::regrole::oid, ARRAY['"Bob"'::regrole::oid, 'carol'::regrole::oid] + ), + E'GRANT "Alice" TO "Bob";\nGRANT "Alice" TO carol;\n' + ); + + RETURN NEXT is( + msar.build_revoke_membership_expr('"Alice"'::regrole::oid, ARRAY['"Bob"'::regrole::oid]), + E'REVOKE "Alice" FROM "Bob";\n' + ); + RETURN NEXT is( + msar.build_revoke_membership_expr( + '"Alice"'::regrole::oid, ARRAY['"Bob"'::regrole::oid, 'carol'::regrole::oid] + ), + E'REVOKE "Alice" FROM "Bob";\nREVOKE "Alice" FROM carol;\n' + ); +END; +$$ LANGUAGE plpgsql;