Skip to content

Commit fa8add9

Browse files
committed
test: regression for auth schema
tests the following aspects: * auth schema * auth tables with owners * auth functions with owners * auth indexes with owners * roles which have USAGE and CREATE on the auth schema * attributes of the supabase_auth_admin role
1 parent 21431e8 commit fa8add9

File tree

2 files changed

+289
-0
lines changed

2 files changed

+289
-0
lines changed

Diff for: nix/tests/expected/auth.out

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
-- auth schema owner
2+
select
3+
n.nspname as schema_name,
4+
r.rolname as owner
5+
from
6+
pg_namespace n
7+
join
8+
pg_roles r on n.nspowner = r.oid
9+
where
10+
n.nspname = 'auth';
11+
schema_name | owner
12+
-------------+----------------
13+
auth | supabase_admin
14+
(1 row)
15+
16+
-- attributes of the supabase_auth_admin
17+
select
18+
rolcreaterole ,
19+
rolcanlogin ,
20+
rolsuper ,
21+
rolinherit ,
22+
rolcreatedb ,
23+
rolreplication ,
24+
rolconnlimit ,
25+
rolbypassrls ,
26+
rolvaliduntil
27+
from pg_roles r
28+
where r.rolname = 'supabase_auth_admin';
29+
rolcreaterole | rolcanlogin | rolsuper | rolinherit | rolcreatedb | rolreplication | rolconnlimit | rolbypassrls | rolvaliduntil
30+
---------------+-------------+----------+------------+-------------+----------------+--------------+--------------+---------------
31+
t | t | f | f | f | f | -1 | f |
32+
(1 row)
33+
34+
select
35+
rolconfig
36+
from pg_roles r
37+
where r.rolname = 'supabase_auth_admin';
38+
rolconfig
39+
---------------------------------------------------------------------------------
40+
{search_path=auth,idle_in_transaction_session_timeout=60000,log_statement=none}
41+
(1 row)
42+
43+
-- auth schema tables with owners
44+
select
45+
n.nspname as schema_name,
46+
c.relname as table_name,
47+
r.rolname as owner
48+
from
49+
pg_class c
50+
join
51+
pg_namespace n on c.relnamespace = n.oid
52+
join
53+
pg_roles r on c.relowner = r.oid
54+
where
55+
c.relkind in ('r') -- 'r' for regular tables
56+
and n.nspname = 'auth'
57+
order by
58+
c.relname;
59+
schema_name | table_name | owner
60+
-------------+-------------------+---------------------
61+
auth | audit_log_entries | supabase_auth_admin
62+
auth | instances | supabase_auth_admin
63+
auth | refresh_tokens | supabase_auth_admin
64+
auth | schema_migrations | supabase_auth_admin
65+
auth | users | supabase_auth_admin
66+
(5 rows)
67+
68+
-- auth indexes with owners
69+
select
70+
ns.nspname as table_schema,
71+
t.relname as table_name,
72+
i.relname as index_name,
73+
r.rolname as index_owner
74+
from
75+
pg_class t
76+
join
77+
pg_namespace ns on t.relnamespace = ns.oid
78+
join
79+
pg_index idx on t.oid = idx.indrelid
80+
join
81+
pg_class i on idx.indexrelid = i.oid
82+
join
83+
pg_roles r on i.relowner = r.oid
84+
where
85+
ns.nspname = 'auth'
86+
order by
87+
t.relname, i.relname;
88+
table_schema | table_name | index_name | index_owner
89+
--------------+-------------------+----------------------------------------+---------------------
90+
auth | audit_log_entries | audit_log_entries_pkey | supabase_auth_admin
91+
auth | audit_log_entries | audit_logs_instance_id_idx | supabase_auth_admin
92+
auth | instances | instances_pkey | supabase_auth_admin
93+
auth | refresh_tokens | refresh_tokens_instance_id_idx | supabase_auth_admin
94+
auth | refresh_tokens | refresh_tokens_instance_id_user_id_idx | supabase_auth_admin
95+
auth | refresh_tokens | refresh_tokens_pkey | supabase_auth_admin
96+
auth | refresh_tokens | refresh_tokens_token_idx | supabase_auth_admin
97+
auth | schema_migrations | schema_migrations_pkey | supabase_auth_admin
98+
auth | users | users_email_key | supabase_auth_admin
99+
auth | users | users_instance_id_email_idx | supabase_auth_admin
100+
auth | users | users_instance_id_idx | supabase_auth_admin
101+
auth | users | users_pkey | supabase_auth_admin
102+
(12 rows)
103+
104+
-- auth schema functions with owners
105+
select
106+
n.nspname as schema_name,
107+
p.proname as function_name,
108+
r.rolname as owner
109+
from
110+
pg_proc p
111+
join
112+
pg_namespace n on p.pronamespace = n.oid
113+
join
114+
pg_roles r on p.proowner = r.oid
115+
where
116+
n.nspname = 'auth'
117+
order by
118+
p.proname;
119+
schema_name | function_name | owner
120+
-------------+---------------+---------------------
121+
auth | email | supabase_auth_admin
122+
auth | role | supabase_auth_admin
123+
auth | uid | supabase_auth_admin
124+
(3 rows)
125+
126+
-- roles which have USAGE on the auth schema
127+
select
128+
n.nspname as schema_name,
129+
r.rolname as role_name,
130+
a.privilege_type
131+
from
132+
pg_namespace n
133+
cross join lateral aclexplode(n.nspacl) as a
134+
join
135+
pg_roles r on a.grantee = r.oid
136+
where
137+
n.nspname = 'auth'
138+
and a.privilege_type = 'USAGE'
139+
order by
140+
r.rolname;
141+
schema_name | role_name | privilege_type
142+
-------------+---------------------+----------------
143+
auth | anon | USAGE
144+
auth | authenticated | USAGE
145+
auth | dashboard_user | USAGE
146+
auth | postgres | USAGE
147+
auth | service_role | USAGE
148+
auth | supabase_admin | USAGE
149+
auth | supabase_auth_admin | USAGE
150+
(7 rows)
151+
152+
-- roles which have CREATE on the auth schema
153+
select
154+
n.nspname as schema_name,
155+
r.rolname as role_name,
156+
a.privilege_type
157+
from
158+
pg_namespace n
159+
cross join lateral aclexplode(n.nspacl) as a
160+
join
161+
pg_roles r on a.grantee = r.oid
162+
where
163+
n.nspname = 'auth'
164+
and a.privilege_type = 'CREATE'
165+
order by
166+
r.rolname;
167+
schema_name | role_name | privilege_type
168+
-------------+---------------------+----------------
169+
auth | dashboard_user | CREATE
170+
auth | postgres | CREATE
171+
auth | supabase_admin | CREATE
172+
auth | supabase_auth_admin | CREATE
173+
(4 rows)
174+

Diff for: nix/tests/sql/auth.sql

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
-- auth schema owner
2+
select
3+
n.nspname as schema_name,
4+
r.rolname as owner
5+
from
6+
pg_namespace n
7+
join
8+
pg_roles r on n.nspowner = r.oid
9+
where
10+
n.nspname = 'auth';
11+
12+
-- attributes of the supabase_auth_admin
13+
select
14+
rolcreaterole ,
15+
rolcanlogin ,
16+
rolsuper ,
17+
rolinherit ,
18+
rolcreatedb ,
19+
rolreplication ,
20+
rolconnlimit ,
21+
rolbypassrls ,
22+
rolvaliduntil
23+
from pg_roles r
24+
where r.rolname = 'supabase_auth_admin';
25+
26+
select
27+
rolconfig
28+
from pg_roles r
29+
where r.rolname = 'supabase_auth_admin';
30+
31+
-- auth schema tables with owners
32+
select
33+
n.nspname as schema_name,
34+
c.relname as table_name,
35+
r.rolname as owner
36+
from
37+
pg_class c
38+
join
39+
pg_namespace n on c.relnamespace = n.oid
40+
join
41+
pg_roles r on c.relowner = r.oid
42+
where
43+
c.relkind in ('r') -- 'r' for regular tables
44+
and n.nspname = 'auth'
45+
order by
46+
c.relname;
47+
48+
-- auth indexes with owners
49+
select
50+
ns.nspname as table_schema,
51+
t.relname as table_name,
52+
i.relname as index_name,
53+
r.rolname as index_owner
54+
from
55+
pg_class t
56+
join
57+
pg_namespace ns on t.relnamespace = ns.oid
58+
join
59+
pg_index idx on t.oid = idx.indrelid
60+
join
61+
pg_class i on idx.indexrelid = i.oid
62+
join
63+
pg_roles r on i.relowner = r.oid
64+
where
65+
ns.nspname = 'auth'
66+
order by
67+
t.relname, i.relname;
68+
69+
-- auth schema functions with owners
70+
select
71+
n.nspname as schema_name,
72+
p.proname as function_name,
73+
r.rolname as owner
74+
from
75+
pg_proc p
76+
join
77+
pg_namespace n on p.pronamespace = n.oid
78+
join
79+
pg_roles r on p.proowner = r.oid
80+
where
81+
n.nspname = 'auth'
82+
order by
83+
p.proname;
84+
85+
-- roles which have USAGE on the auth schema
86+
select
87+
n.nspname as schema_name,
88+
r.rolname as role_name,
89+
a.privilege_type
90+
from
91+
pg_namespace n
92+
cross join lateral aclexplode(n.nspacl) as a
93+
join
94+
pg_roles r on a.grantee = r.oid
95+
where
96+
n.nspname = 'auth'
97+
and a.privilege_type = 'USAGE'
98+
order by
99+
r.rolname;
100+
101+
-- roles which have CREATE on the auth schema
102+
select
103+
n.nspname as schema_name,
104+
r.rolname as role_name,
105+
a.privilege_type
106+
from
107+
pg_namespace n
108+
cross join lateral aclexplode(n.nspacl) as a
109+
join
110+
pg_roles r on a.grantee = r.oid
111+
where
112+
n.nspname = 'auth'
113+
and a.privilege_type = 'CREATE'
114+
order by
115+
r.rolname;

0 commit comments

Comments
 (0)