Skip to content

Commit e3538d1

Browse files
committed
test: postgres_fdw
1 parent e346a7a commit e3538d1

File tree

2 files changed

+26
-44
lines changed

2 files changed

+26
-44
lines changed

nix/tests/expected/postgres_fdw.out

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
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
14+
set role postgres;
15+
-- postgres_fdw should be owned by the superuser
16+
select fdwowner::regrole from pg_foreign_data_wrapper where fdwname = 'postgres_fdw';
1817
CREATE FOREIGN DATA WRAPPER test_fdw_postgres_owned;
1918
-- Reset to original role for queries because the tests run under a superuser context
2019
RESET ROLE;

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)