From 600d9a7edf55709407d9fb705bafe37ccecc4594 Mon Sep 17 00:00:00 2001 From: luozihao <1165977584@qq.com> Date: Wed, 28 Apr 2021 16:36:51 +0800 Subject: [PATCH] Enable modify the owner of procedure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改测试用例名 --- src/common/backend/parser/gram.y | 8 ++++ .../input/procedure_privilege_test.source | 33 +++++++++++++ .../output/procedure_privilege_test.source | 47 +++++++++++++++++++ src/test/regress/parallel_schedule0 | 3 +- 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/test/regress/input/procedure_privilege_test.source create mode 100644 src/test/regress/output/procedure_privilege_test.source diff --git a/src/common/backend/parser/gram.y b/src/common/backend/parser/gram.y index c6b199af8..3523785da 100755 --- a/src/common/backend/parser/gram.y +++ b/src/common/backend/parser/gram.y @@ -9459,6 +9459,14 @@ privilege_target: n->objs = $2; $$ = n; } + | PROCEDURE function_with_argtypes_list + { + PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget)); + n->targtype = ACL_TARGET_OBJECT; + n->objtype = ACL_OBJECT_FUNCTION; + n->objs = $2; + $$ = n; + } | DATABASE name_list { PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget)); diff --git a/src/test/regress/input/procedure_privilege_test.source b/src/test/regress/input/procedure_privilege_test.source new file mode 100644 index 000000000..76753299e --- /dev/null +++ b/src/test/regress/input/procedure_privilege_test.source @@ -0,0 +1,33 @@ +DROP SCHEMA IF EXISTS test_sch; +DROP TABLE IF EXISTS test_sch.test_table; +CREATE SCHEMA test_sch; +CREATE TABLE test_sch.test_table(id1 int, id2 varchar(20)); +CREATE OR REPLACE PROCEDURE test_sch.test_pro(num1 integer, num2 varchar(20)) AS +BEGIN + INSERT INTO test_sch.test_table values(num1, num2); +END; +/ + +CALL test_sch.test_pro(1, 'initial'); + +DROP USER IF EXISTS test_owner CASCADE; +DROP USER IF EXISTS test_acl CASCADE; +CREATE USER test_owner WITH PASSWORD 'openGauss@123'; +CREATE USER test_acl WITH PASSWORD 'openGauss@123'; +GRANT ALL PRIVILEGES ON SCHEMA test_sch TO test_acl; +GRANT INSERT ON TABLE test_sch.test_table TO test_acl; +REVOKE ALL PRIVILEGES ON PROCEDURE test_sch.test_pro(num1 integer, num2 varchar(20)) FROM test_acl; + +\! @abs_bindir@/gsql -r -p @portstring@ -d regression -U test_acl -W 'openGauss@123' -c 'ALTER PROCEDURE test_sch.test_pro(num1 integer, num2 varchar(20)) RENAME TO new_test_pro;' + +ALTER PROCEDURE test_sch.test_pro(num1 integer, num2 varchar(20)) OWNER TO test_owner; +GRANT ALL PRIVILEGES ON PROCEDURE test_sch.test_pro(num1 integer, num2 varchar(20)) TO test_acl; + +SELECT p.proname, r.rolname FROM PG_PROC AS p, pg_roles AS r WHERE p.proowner=r.oid AND proname='test_pro'; +\! @abs_bindir@/gsql -r -p @portstring@ -d regression -U test_acl -W 'openGauss@123' -c 'ALTER PROCEDURE test_sch.test_pro(num1 integer, num2 varchar(20)) RENAME TO new_test_pro;' + +SELECT p.proname, r.rolname FROM PG_PROC AS p, pg_roles AS r WHERE p.proowner=r.oid AND proname='new_test_pro'; + +DROP TABLE IF EXISTS test_sch.test_table; +DROP USER IF EXISTS test_owner CASCADE; +DROP USER IF EXISTS test_acl CASCADE; diff --git a/src/test/regress/output/procedure_privilege_test.source b/src/test/regress/output/procedure_privilege_test.source new file mode 100644 index 000000000..619c2c3c8 --- /dev/null +++ b/src/test/regress/output/procedure_privilege_test.source @@ -0,0 +1,47 @@ +DROP SCHEMA IF EXISTS test_sch; +NOTICE: schema "test_sch" does not exist, skipping +DROP TABLE IF EXISTS test_sch.test_table; +ERROR: schema "test_sch" does not exist +CREATE SCHEMA test_sch; +CREATE TABLE test_sch.test_table(id1 int, id2 varchar(20)); +CREATE OR REPLACE PROCEDURE test_sch.test_pro(num1 integer, num2 varchar(20)) AS +BEGIN + INSERT INTO test_sch.test_table values(num1, num2); +END; +/ +CALL test_sch.test_pro(1, 'initial'); + test_pro +---------- + +(1 row) + +DROP USER IF EXISTS test_owner CASCADE; +NOTICE: role "test_owner" does not exist, skipping +DROP USER IF EXISTS test_acl CASCADE; +NOTICE: role "test_acl" does not exist, skipping +CREATE USER test_owner WITH PASSWORD 'openGauss@123'; +CREATE USER test_acl WITH PASSWORD 'openGauss@123'; +GRANT ALL PRIVILEGES ON SCHEMA test_sch TO test_acl; +GRANT INSERT ON TABLE test_sch.test_table TO test_acl; +REVOKE ALL PRIVILEGES ON PROCEDURE test_sch.test_pro(num1 integer, num2 varchar(20)) FROM test_acl; +\! @abs_bindir@/gsql -r -p @portstring@ -d regression -U test_acl -W 'openGauss@123' -c 'ALTER PROCEDURE test_sch.test_pro(num1 integer, num2 varchar(20)) RENAME TO new_test_pro;' +ERROR: permission denied for function test_sch.test_pro +ALTER PROCEDURE test_sch.test_pro(num1 integer, num2 varchar(20)) OWNER TO test_owner; +GRANT ALL PRIVILEGES ON PROCEDURE test_sch.test_pro(num1 integer, num2 varchar(20)) TO test_acl; +SELECT p.proname, r.rolname FROM PG_PROC AS p, pg_roles AS r WHERE p.proowner=r.oid AND proname='test_pro'; + proname | rolname +----------+------------ + test_pro | test_owner +(1 row) + +\! @abs_bindir@/gsql -r -p @portstring@ -d regression -U test_acl -W 'openGauss@123' -c 'ALTER PROCEDURE test_sch.test_pro(num1 integer, num2 varchar(20)) RENAME TO new_test_pro;' +ALTER FUNCTION +SELECT p.proname, r.rolname FROM PG_PROC AS p, pg_roles AS r WHERE p.proowner=r.oid AND proname='new_test_pro'; + proname | rolname +--------------+------------ + new_test_pro | test_owner +(1 row) + +DROP TABLE IF EXISTS test_sch.test_table; +DROP USER IF EXISTS test_owner CASCADE; +DROP USER IF EXISTS test_acl CASCADE; diff --git a/src/test/regress/parallel_schedule0 b/src/test/regress/parallel_schedule0 index 8d596d320..85e45a63f 100644 --- a/src/test/regress/parallel_schedule0 +++ b/src/test/regress/parallel_schedule0 @@ -760,4 +760,5 @@ test: leaky_function_operator #test: gs_guc test: smp -test: sequence_cache_test \ No newline at end of file +test: sequence_cache_test +test: procedure_privilege_test \ No newline at end of file