From 2149e3f716a16f0026057f9c1c01f0273253f22c Mon Sep 17 00:00:00 2001 From: Hou Zhijie Date: Mon, 11 Sep 2023 11:10:04 +0800 Subject: [PATCH 2/2] add a test to verify the change of runasowner take effect in apply worker --- .../subscription/t/033_run_as_table_owner.pl | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/test/subscription/t/033_run_as_table_owner.pl b/src/test/subscription/t/033_run_as_table_owner.pl index 9de3c04a0c..a40b6f5162 100644 --- a/src/test/subscription/t/033_run_as_table_owner.pl +++ b/src/test/subscription/t/033_run_as_table_owner.pl @@ -193,6 +193,33 @@ GRANT regress_alice TO regress_admin WITH INHERIT TRUE, SET FALSE; expect_replication("alice.unpartitioned", 3, 7, 13, "with INHERIT but not SET ROLE can replicate"); +# Remove all privileges again. +$node_subscriber->safe_psql( + 'postgres', qq( +SET SESSION AUTHORIZATION regress_alice; +REVOKE ALL PRIVILEGES ON alice.unpartitioned FROM regress_admin; +RESET SESSION AUTHORIZATION; +GRANT regress_alice TO regress_admin WITH INHERIT FALSE, SET TRUE; +)); + +# We can't yet replicate an INSERT because we revoked all privileges. +publish_insert("alice.unpartitioned", 14); +expect_failure( + "alice.unpartitioned", + 3, + 7, + 13, + qr/ERROR: ( [A-Z0-9]+:)? permission denied for table unpartitioned/msi, + "with no privileges cannot replicate"); + +$node_subscriber->safe_psql( + 'postgres', qq( +ALTER SUBSCRIPTION admin_sub SET (run_as_owner = false); +)); + +expect_replication("alice.unpartitioned", 4, 7, 14, + "can replicate after setting run_as_owner to false"); + # Remove the subscrition and truncate the table for the initial data sync # tests. $node_subscriber->safe_psql( @@ -222,7 +249,7 @@ ALTER SUBSCRIPTION admin_sub ENABLE; # Because the initial data sync is working as the table owner, all # data should be copied. $node_subscriber->wait_for_subscription_sync($node_publisher, 'admin_sub'); -expect_replication("alice.unpartitioned", 3, 7, 13, +expect_replication("alice.unpartitioned", 4, 7, 14, "table owner can do the initial data copy"); done_testing(); -- 2.30.0.windows.2