Skip to content

Commit

Permalink
Add a config to our test suite for non owning users
Browse files Browse the repository at this point in the history
This would have found the bug that's fixed in #5441
  • Loading branch information
JelteF committed Jun 25, 2024
1 parent aaaf637 commit bb430fa
Show file tree
Hide file tree
Showing 37 changed files with 89 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
parallel_thread_amount = 1


def _run_pg_regress_on_port(config, port, schedule_name, extra_tests=""):
def _run_pg_regress_on_port(config, port, schedule_name, user, extra_tests=""):
return common.run_pg_regress_without_exit(
config.bindir,
config.pg_srcdir,
port,
schedule_name,
config.output_dir,
config.input_dir,
config.user,
user,
extra_tests,
)

Expand All @@ -54,12 +54,11 @@ def run_for_config(config, lock, sql_schedule_name):
common.initialize_citus_cluster(
config.bindir, config.datadir, config.settings, config
)
if config.user == cfg.REGULAR_USER_NAME:
common.create_role(
config.bindir,
config.node_name_to_ports.values(),
config.user,
)
common.create_role(
config.bindir,
config.node_name_to_ports.values(),
cfg.REGULAR_USER_NAME,
)

copy_copy_modified_binary(config.datadir)
copy_test_files(config)
Expand Down Expand Up @@ -91,20 +90,25 @@ def run_for_config(config, lock, sql_schedule_name):
)

exitCode |= _run_pg_regress_on_port(
config, config.coordinator_port(), cfg.CREATE_SCHEDULE
config, config.coordinator_port(), cfg.CREATE_SCHEDULE, config.owner_role
)
common.save_regression_diff("create", config.output_dir)

extra_tests = os.getenv("EXTRA_TESTS", "")
if config.is_mx and config.worker_amount > 0:
exitCode |= _run_pg_regress_on_port(
config, config.random_port(), sql_schedule_name, extra_tests=extra_tests
config,
config.random_port(),
sql_schedule_name,
config.user,
extra_tests=extra_tests,
)
else:
exitCode |= _run_pg_regress_on_port(
config,
config.coordinator_port(),
sql_schedule_name,
config.user,
extra_tests=extra_tests,
)

Expand Down
12 changes: 12 additions & 0 deletions src/test/regress/citus_tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ def __init__(self, arguments):
self.pg_srcdir = arguments["--pgxsdir"]
self.temp_dir = CITUS_ARBITRARY_TEST_DIR
self.worker_amount = 2
# User is that will execute the sql scripts
self.user = REGULAR_USER_NAME
# If owner_role is set to something else than None, that role will be
# used to execute all the xyz_create.sql scripts, so that the tables
# are owned by that role.
self.owner_role = None
self.dbname = DATABASE_NAME
self.is_mx = True
self.is_citus = True
Expand Down Expand Up @@ -129,6 +134,8 @@ def post_init(self):
self.output_file = os.path.join(self.datadir, "run.out")
if self.worker_amount > 0:
self.chosen_random_worker_port = self.random_worker_port()
if self.owner_role is None:
self.owner_role = self.user
self.settings.update(self.new_settings)

def coordinator_port(self):
Expand Down Expand Up @@ -177,6 +184,11 @@ def __init__(self, arguments):
"arbitrary_configs_alter_table_add_constraint_without_name",
]

class CitusGrantedPermissionsClusterConfig(CitusDefaultClusterConfig):
def __init__(self, arguments):
super().__init__(arguments)
self.owner_role = SUPER_USER_NAME


class CitusUpgradeConfig(CitusBaseClusterConfig):
def __init__(self, arguments, pre_tar, post_tar):
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/create_schedule
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test: auto_grant_all_to_regularuser
test: intermediate_result_pruning_create
test: prepared_statements_create_load ch_benchmarks_create_load
test: dropped_columns_create_load distributed_planning_create_load
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA truncate_cascade_tests_schema;
SET search_path TO truncate_cascade_tests_schema;
GRANT ALL ON SCHEMA truncate_cascade_tests_schema TO regularuser;
-- tables connected with foreign keys
CREATE TABLE table_with_pk(a bigint PRIMARY KEY);
CREATE TABLE table_with_fk_1(a bigint, b bigint, FOREIGN KEY (b) REFERENCES table_with_pk(a));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA truncate_tests_schema;
SET search_path TO truncate_tests_schema;
GRANT ALL ON SCHEMA truncate_tests_schema TO regularuser;
-- simple table
CREATE TABLE basic_table(a int);
-- partioned table
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA truncate_partition_tests_schema;
SET search_path TO truncate_partition_tests_schema;
GRANT ALL ON SCHEMA truncate_partition_tests_schema TO regularuser;
-- partioned table
CREATE TABLE partitioned_table(a int) PARTITION BY RANGE(a);
CREATE TABLE partitioned_table_0 PARTITION OF partitioned_table
Expand Down
5 changes: 5 additions & 0 deletions src/test/regress/expected/auto_grant_all_to_regularuser.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER DEFAULT PRIVILEGES GRANT ALL ON SCHEMAS TO regularuser; -- does not work with citus
ALTER DEFAULT PRIVILEGES GRANT ALL ON TABLES TO regularuser; -- does not work for views with citus
ALTER DEFAULT PRIVILEGES GRANT ALL ON TYPES TO regularuser;
ALTER DEFAULT PRIVILEGES GRANT ALL ON SEQUENCES TO regularuser;
ALTER DEFAULT PRIVILEGES GRANT ALL ON FUNCTIONS TO regularuser;
1 change: 1 addition & 0 deletions src/test/regress/expected/ch_benchmarks_create_load.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA "ch benchmarks";
SET search_path to "ch benchmarks";
GRANT ALL ON SCHEMA "ch benchmarks" TO regularuser;
CREATE TABLE order_line (
ol_w_id int NOT NULL,
ol_d_id int NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA "distributed planning";
SET search_path TO "distributed planning";
GRANT ALL ON SCHEMA "distributed planning" TO regularuser;
CREATE TABLE
date_part_table (event_time timestamp, event int, user_id int)
partition by range (event_time);
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/expected/dropped_columns_create_load.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA local_shard_execution_dropped_column;
SET search_path TO local_shard_execution_dropped_column;
GRANT ALL ON SCHEMA local_shard_execution_dropped_column TO regularuser;
CREATE TABLE t1 (a int, b int, c int UNIQUE, d int, e int);
ALTER TABLE t1 DROP COLUMN e;
SELECT create_distributed_table('t1', 'c');
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/expected/function_create.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
\set VERBOSITY terse
CREATE SCHEMA function_create;
SET search_path TO function_create;
GRANT ALL ON SCHEMA function_create TO regularuser;
-- helper function to verify the function of a coordinator is the same on all workers
CREATE OR REPLACE FUNCTION verify_function_is_same_on_workers(funcname text)
RETURNS bool
Expand Down
7 changes: 4 additions & 3 deletions src/test/regress/expected/index_create.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA index_create;
SET search_path TO index_create;
GRANT ALL ON SCHEMA index_create TO regularuser;
CREATE TABLE test_tbl (a INT NOT NULL PRIMARY KEY, b text, c BIGINT);
CREATE UNIQUE INDEX CONCURRENTLY a_index ON test_tbl (a);
SELECT create_distributed_table('test_tbl','a');
Expand Down Expand Up @@ -62,7 +63,7 @@ SELECT 'alter_idx_rename_test_3'::regclass, 'alter_idx_rename_test_idx_3'::regcl
(1 row)

SELECT 'alter_idx_rename_test_parted_3'::regclass, 'alter_idx_rename_test_parted_idx_3'::regclass;
regclass | regclass
regclass | regclass
---------------------------------------------------------------------
alter_idx_rename_test_parted_3 | alter_idx_rename_test_parted_idx_3
(1 row)
Expand Down Expand Up @@ -98,7 +99,7 @@ SELECT 'alter_idx_rename_test_3'::regclass, 'alter_idx_rename_test_idx_3'::regcl
(1 row)

SELECT 'alter_idx_rename_test_parted_3'::regclass, 'alter_idx_rename_test_parted_idx_3'::regclass;
regclass | regclass
regclass | regclass
---------------------------------------------------------------------
alter_idx_rename_test_parted_3 | alter_idx_rename_test_parted_idx_3
(1 row)
Expand All @@ -107,4 +108,4 @@ ALTER INDEX alter_idx_rename_test_idx_3 RENAME TO alter_idx_rename_test_idx_4;
DROP INDEX alter_idx_rename_test_idx_4;
DROP TABLE alter_idx_rename_test_3;
DROP INDEX alter_idx_rename_test_parted_idx_3;
DROP TABLE alter_idx_rename_test_parted_3;
DROP TABLE alter_idx_rename_test_parted_3;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA "intermediate result pruning";
SET search_path TO "intermediate result pruning";
GRANT ALL ON SCHEMA "intermediate result pruning" TO regularuser;
CREATE TABLE table_1 (key int, value text);
SELECT create_distributed_table('table_1', 'key');
create_distributed_table
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/expected/local_dist_join_load.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA local_dist_join_mixed;
SET search_path TO local_dist_join_mixed;
GRANT ALL ON SCHEMA local_dist_join_mixed TO regularuser;
CREATE TABLE distributed (key int, id bigserial PRIMARY KEY,
name text,
created_at timestamptz DEFAULT now(), b int);
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/expected/nested_execution_create.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA nested_execution;
SET search_path TO nested_execution;
GRANT ALL ON SCHEMA nested_execution TO regularuser;
-- some of the next_execution tests change for single shard
SET citus.shard_count TO 4;
CREATE TABLE distributed (key int, name text,
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/expected/partitioned_indexes_create.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA "partitioned indexes";
SET search_path TO "partitioned indexes";
GRANT ALL ON SCHEMA "partitioned indexes" TO regularuser;
-- test with proper table
CREATE TABLE dist_partitioned_table (dist_col int, another_col int, partition_col timestamp) PARTITION BY RANGE (partition_col);
SELECT create_distributed_table('dist_partitioned_table', 'dist_col');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA "prepared statements";
SET search_path TO "prepared statements";
GRANT ALL ON SCHEMA "prepared statements" TO regularuser;
CREATE TABLE repartition_prepared_test (a int, b int);
SELECT create_distributed_table('repartition_prepared_test', 'a');
create_distributed_table
Expand Down
4 changes: 4 additions & 0 deletions src/test/regress/expected/schemas_create.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
CREATE SCHEMA test_schema_1;
GRANT ALL ON SCHEMA test_schema_1 TO regularuser;
CREATE SCHEMA IF NOT EXISTS test_schema_2;
GRANT ALL ON SCHEMA test_schema_2 TO regularuser;
CREATE SCHEMA test_schema_3 CREATE TABLE test_table(a INT PRIMARY KEY);
GRANT ALL ON SCHEMA test_schema_3 TO regularuser;
SELECT create_distributed_table('test_schema_3.test_table','a');
create_distributed_table
---------------------------------------------------------------------
Expand All @@ -10,6 +13,7 @@ SELECT create_distributed_table('test_schema_3.test_table','a');
INSERT INTO test_schema_3.test_table VALUES (1), (2);
DROP SCHEMA test_schema_2;
CREATE SCHEMA test_schema_4;
GRANT ALL ON SCHEMA test_schema_4 TO regularuser;
ALTER TABLE test_schema_3.test_table SET SCHEMA test_schema_4;
ALTER SCHEMA test_schema_3 RENAME TO test_schema_3_renamed;
ALTER SCHEMA test_schema_4 RENAME TO test_schema_5;
1 change: 1 addition & 0 deletions src/test/regress/expected/sequences_create.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA sequences_schema;
SET search_path TO sequences_schema;
GRANT ALL ON SCHEMA sequences_schema TO regularuser;
CREATE SEQUENCE seq_0;
ALTER SEQUENCE seq_0 AS smallint;
CREATE SEQUENCE seq_1;
Expand Down
8 changes: 7 additions & 1 deletion src/test/regress/expected/views_create.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA views_create;
SET search_path TO views_create;
GRANT ALL ON SCHEMA views_create TO regularuser;
CREATE TABLE view_test_table(a INT NOT NULL PRIMARY KEY, b BIGINT, c text);
SELECT create_distributed_table('view_test_table', 'a');
create_distributed_table
Expand Down Expand Up @@ -62,7 +63,7 @@ SELECT COUNT(*) FROM select_all_matview;
(1 row)

SELECT * FROM select_filtered_matview;
a | b | c
a | b | c
---------------------------------------------------------------------
2 | 1 | views
(1 row)
Expand All @@ -88,10 +89,15 @@ CREATE TABLE local (id bigserial PRIMARY KEY,
title text);
SET client_min_messages TO ERROR;
CREATE VIEW "local regular view" AS SELECT * FROM local;
GRANT ALL ON TABLE "local regular view" TO regularuser;
CREATE VIEW dist_regular_view AS SELECT * FROM distributed;
GRANT ALL ON TABLE dist_regular_view TO regularuser;
CREATE VIEW local_regular_view2 as SELECT count(*) FROM distributed JOIN "local regular view" USING (id);
GRANT ALL ON TABLE local_regular_view2 TO regularuser;
CREATE VIEW local_regular_view3 as SELECT count(*) FROM local JOIN dist_regular_view USING (id);
GRANT ALL ON TABLE local_regular_view3 TO regularuser;
CREATE VIEW "local regular view4" as SELECT count(*) as "my cny" FROM dist_regular_view JOIN "local regular view" USING (id);
GRANT ALL ON TABLE "local regular view4" TO regularuser;
RESET client_min_messages;
-- these above restrictions brought us to the following schema
SELECT create_reference_table('reference');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA truncate_cascade_tests_schema;
SET search_path TO truncate_cascade_tests_schema;
GRANT ALL ON SCHEMA truncate_cascade_tests_schema TO regularuser;

-- tables connected with foreign keys
CREATE TABLE table_with_pk(a bigint PRIMARY KEY);
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/sql/arbitrary_configs_truncate_create.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA truncate_tests_schema;
SET search_path TO truncate_tests_schema;
GRANT ALL ON SCHEMA truncate_tests_schema TO regularuser;

-- simple table
CREATE TABLE basic_table(a int);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA truncate_partition_tests_schema;
SET search_path TO truncate_partition_tests_schema;
GRANT ALL ON SCHEMA truncate_partition_tests_schema TO regularuser;

-- partioned table
CREATE TABLE partitioned_table(a int) PARTITION BY RANGE(a);
Expand Down
5 changes: 5 additions & 0 deletions src/test/regress/sql/auto_grant_all_to_regularuser.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER DEFAULT PRIVILEGES GRANT ALL ON SCHEMAS TO regularuser; -- does not work with citus
ALTER DEFAULT PRIVILEGES GRANT ALL ON TABLES TO regularuser; -- does not work for views with citus
ALTER DEFAULT PRIVILEGES GRANT ALL ON TYPES TO regularuser;
ALTER DEFAULT PRIVILEGES GRANT ALL ON SEQUENCES TO regularuser;
ALTER DEFAULT PRIVILEGES GRANT ALL ON FUNCTIONS TO regularuser;
1 change: 1 addition & 0 deletions src/test/regress/sql/ch_benchmarks_create_load.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA "ch benchmarks";
SET search_path to "ch benchmarks";
GRANT ALL ON SCHEMA "ch benchmarks" TO regularuser;


CREATE TABLE order_line (
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/sql/distributed_planning_create_load.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA "distributed planning";
SET search_path TO "distributed planning";
GRANT ALL ON SCHEMA "distributed planning" TO regularuser;

CREATE TABLE
date_part_table (event_time timestamp, event int, user_id int)
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/sql/dropped_columns_create_load.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA local_shard_execution_dropped_column;
SET search_path TO local_shard_execution_dropped_column;
GRANT ALL ON SCHEMA local_shard_execution_dropped_column TO regularuser;

CREATE TABLE t1 (a int, b int, c int UNIQUE, d int, e int);
ALTER TABLE t1 DROP COLUMN e;
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/sql/function_create.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
\set VERBOSITY terse
CREATE SCHEMA function_create;
SET search_path TO function_create;
GRANT ALL ON SCHEMA function_create TO regularuser;

-- helper function to verify the function of a coordinator is the same on all workers
CREATE OR REPLACE FUNCTION verify_function_is_same_on_workers(funcname text)
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/sql/index_create.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA index_create;
SET search_path TO index_create;
GRANT ALL ON SCHEMA index_create TO regularuser;

CREATE TABLE test_tbl (a INT NOT NULL PRIMARY KEY, b text, c BIGINT);
CREATE UNIQUE INDEX CONCURRENTLY a_index ON test_tbl (a);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA "intermediate result pruning";
SET search_path TO "intermediate result pruning";
GRANT ALL ON SCHEMA "intermediate result pruning" TO regularuser;

CREATE TABLE table_1 (key int, value text);
SELECT create_distributed_table('table_1', 'key');
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/sql/local_dist_join_load.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA local_dist_join_mixed;
SET search_path TO local_dist_join_mixed;
GRANT ALL ON SCHEMA local_dist_join_mixed TO regularuser;



Expand Down
1 change: 1 addition & 0 deletions src/test/regress/sql/nested_execution_create.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA nested_execution;
SET search_path TO nested_execution;
GRANT ALL ON SCHEMA nested_execution TO regularuser;

-- some of the next_execution tests change for single shard
SET citus.shard_count TO 4;
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/sql/partitioned_indexes_create.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA "partitioned indexes";
SET search_path TO "partitioned indexes";
GRANT ALL ON SCHEMA "partitioned indexes" TO regularuser;

-- test with proper table
CREATE TABLE dist_partitioned_table (dist_col int, another_col int, partition_col timestamp) PARTITION BY RANGE (partition_col);
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/sql/prepared_statements_create_load.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA "prepared statements";
SET search_path TO "prepared statements";
GRANT ALL ON SCHEMA "prepared statements" TO regularuser;

CREATE TABLE repartition_prepared_test (a int, b int);
SELECT create_distributed_table('repartition_prepared_test', 'a');
Expand Down
4 changes: 4 additions & 0 deletions src/test/regress/sql/schemas_create.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
CREATE SCHEMA test_schema_1;
GRANT ALL ON SCHEMA test_schema_1 TO regularuser;
CREATE SCHEMA IF NOT EXISTS test_schema_2;
GRANT ALL ON SCHEMA test_schema_2 TO regularuser;
CREATE SCHEMA test_schema_3 CREATE TABLE test_table(a INT PRIMARY KEY);
GRANT ALL ON SCHEMA test_schema_3 TO regularuser;

SELECT create_distributed_table('test_schema_3.test_table','a');
INSERT INTO test_schema_3.test_table VALUES (1), (2);

DROP SCHEMA test_schema_2;
CREATE SCHEMA test_schema_4;
GRANT ALL ON SCHEMA test_schema_4 TO regularuser;

ALTER TABLE test_schema_3.test_table SET SCHEMA test_schema_4;
ALTER SCHEMA test_schema_3 RENAME TO test_schema_3_renamed;
Expand Down
Loading

0 comments on commit bb430fa

Please sign in to comment.