Skip to content

Commit 1b46e8d

Browse files
committed
test: postgres_fdw
1 parent e346a7a commit 1b46e8d

File tree

2 files changed

+40
-74
lines changed

2 files changed

+40
-74
lines changed
Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,33 @@
11
/*
22

3-
Test to verify supautils (v3.0.0+) allows non-superuser postgres role to own FDWs.
3+
Test to verify supautils (v3.0.0+) allows non-superuser postgres role to use postgres_fdw.
44

5-
This test ensures that the supautils extension properly handles FDW ownership
5+
This test ensures that the supautils extension properly handles FDW usage
66
for the privileged postgres role without requiring temporary superuser privileges.
77

88
This verifies the fix that eliminated the need for:
9-
ansible/files/postgresql_extension_custom_scripts/postgres_fdw/after-create.sql (removed)
9+
https://github.com/supabase/postgres/blob/a638c6fce0baf90b654e762eddcdac1bc8df01ee/ansible/files/postgresql_extension_custom_scripts/postgres_fdw/after-create.sql (removed)
1010

1111
*/
12-
BEGIN;
12+
begin;
1313
-- Switch to the postgres role (non-superuser) to test supautils behavior
14-
SET ROLE postgres;
15-
-- Test 1: Create a custom FDW directly (this is what supautils v3.0.0 fixes)
16-
-- Before v3.0.0, this would fail because only superusers can create FDWs
17-
-- With v3.0.0, supautils allows postgres (privileged role) to create and own FDWs
18-
CREATE FOREIGN DATA WRAPPER test_fdw_postgres_owned;
19-
-- Reset to original role for queries because the tests run under a superuser context
20-
RESET ROLE;
21-
-- Verify that the custom FDW is owned by postgres (non-superuser)
22-
SELECT
23-
fdw.fdwname as fdw_name,
24-
owner.rolname as owner_name,
25-
owner.rolsuper as owner_is_superuser
26-
FROM
27-
pg_foreign_data_wrapper fdw
28-
JOIN pg_roles owner ON fdw.fdwowner = owner.oid
29-
WHERE
30-
fdw.fdwname = 'test_fdw_postgres_owned';
31-
fdw_name | owner_name | owner_is_superuser
32-
-------------------------+------------+--------------------
33-
test_fdw_postgres_owned | postgres | f
34-
(1 row)
14+
set role postgres;
3515

36-
-- Verify the postgres role's superuser status
37-
-- The key test: postgres should NOT be a superuser, yet can own the FDW
38-
SELECT
39-
rolname,
40-
rolsuper as is_superuser
41-
FROM
42-
pg_roles
43-
WHERE
44-
rolname = 'postgres';
45-
rolname | is_superuser
46-
----------+--------------
47-
postgres | f
16+
-- postgres_fdw should be owned by the superuser
17+
select fdwowner::regrole from pg_foreign_data_wrapper where fdwname = 'postgres_fdw';
18+
fdwowner
19+
----------------
20+
supabase_admin
4821
(1 row)
4922

50-
ROLLBACK;
23+
-- Verify that `postgres` can use the FDW despite not owning it
24+
create server s
25+
foreign data wrapper postgres_fdw
26+
options (
27+
host '127.0.0.1',
28+
port '5432',
29+
dbname 'postgres'
30+
);
31+
CREATE SERVER
32+
33+
rollback;

nix/tests/sql/postgres_fdw.sql

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,30 @@
11
/*
22
3-
Test to verify supautils (v3.0.0+) allows non-superuser postgres role to own FDWs.
3+
Test to verify supautils (v3.0.0+) allows non-superuser postgres role to use postgres_fdw.
44
5-
This test ensures that the supautils extension properly handles FDW ownership
5+
This test ensures that the supautils extension properly handles FDW usage
66
for the privileged postgres role without requiring temporary superuser privileges.
77
88
This verifies the fix that eliminated the need for:
9-
ansible/files/postgresql_extension_custom_scripts/postgres_fdw/after-create.sql (removed)
9+
https://github.com/supabase/postgres/blob/a638c6fce0baf90b654e762eddcdac1bc8df01ee/ansible/files/postgresql_extension_custom_scripts/postgres_fdw/after-create.sql (removed)
1010
1111
*/
1212

13-
BEGIN;
13+
begin;
1414

1515
-- Switch to the postgres role (non-superuser) to test supautils behavior
16-
SET ROLE postgres;
17-
18-
-- Test 1: Create a custom FDW directly (this is what supautils v3.0.0 fixes)
19-
-- Before v3.0.0, this would fail because only superusers can create FDWs
20-
-- With v3.0.0, supautils allows postgres (privileged role) to create and own FDWs
21-
CREATE FOREIGN DATA WRAPPER test_fdw_postgres_owned;
22-
23-
-- Reset to original role for queries because the tests run under a superuser context
24-
RESET ROLE;
25-
26-
-- Verify that the custom FDW is owned by postgres (non-superuser)
27-
SELECT
28-
fdw.fdwname as fdw_name,
29-
owner.rolname as owner_name,
30-
owner.rolsuper as owner_is_superuser
31-
FROM
32-
pg_foreign_data_wrapper fdw
33-
JOIN pg_roles owner ON fdw.fdwowner = owner.oid
34-
WHERE
35-
fdw.fdwname = 'test_fdw_postgres_owned';
36-
37-
-- Verify the postgres role's superuser status
38-
-- The key test: postgres should NOT be a superuser, yet can own the FDW
39-
SELECT
40-
rolname,
41-
rolsuper as is_superuser
42-
FROM
43-
pg_roles
44-
WHERE
45-
rolname = 'postgres';
46-
47-
ROLLBACK;
16+
set role postgres;
17+
18+
-- postgres_fdw should be owned by the superuser
19+
select fdwowner::regrole from pg_foreign_data_wrapper where fdwname = 'postgres_fdw';
20+
21+
-- Verify that `postgres` can use the FDW despite not owning it
22+
create server s
23+
foreign data wrapper postgres_fdw
24+
options (
25+
host '127.0.0.1',
26+
port '5432',
27+
dbname 'postgres'
28+
);
29+
30+
rollback;

0 commit comments

Comments
 (0)