@pgpm/supabase 0.5.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/LICENSE +2 -1
  2. package/Makefile +2 -3
  3. package/README.md +45 -59
  4. package/deploy/roles/anon.sql +15 -0
  5. package/deploy/schemas/supabase_integration/procedures/pre_request.sql +26 -0
  6. package/deploy/schemas/supabase_integration/schema.sql +9 -0
  7. package/package.json +27 -12
  8. package/pgpm-supabase.control +7 -0
  9. package/pgpm.plan +6 -3
  10. package/revert/roles/anon.sql +7 -0
  11. package/revert/schemas/supabase_integration/procedures/pre_request.sql +7 -0
  12. package/revert/schemas/supabase_integration/schema.sql +7 -0
  13. package/sql/pgpm-supabase--1.0.0.bundle.tar.gz +0 -0
  14. package/sql/pgpm-supabase--1.0.0.sql +32 -0
  15. package/verify/roles/anon.sql +12 -0
  16. package/verify/schemas/supabase_integration/procedures/pre_request.sql +19 -0
  17. package/verify/schemas/supabase_integration/schema.sql +18 -0
  18. package/__tests__/_realtime/_realtime-extensions.test.ts +0 -129
  19. package/__tests__/_realtime/_realtime-schema-migrations.test.ts +0 -160
  20. package/__tests__/_realtime/_realtime-tenants.test.ts +0 -163
  21. package/__tests__/auth/auth.audit-log-entries.test.ts +0 -148
  22. package/__tests__/auth/auth.flow-state.test.ts +0 -114
  23. package/__tests__/auth/auth.identities.test.ts +0 -149
  24. package/__tests__/auth/auth.instances.test.ts +0 -134
  25. package/__tests__/auth/auth.mfa-amr-claims.test.ts +0 -142
  26. package/__tests__/auth/auth.mfa-challenges.test.ts +0 -117
  27. package/__tests__/auth/auth.mfa-factors.test.ts +0 -118
  28. package/__tests__/auth/auth.oauth-authorizations.test.ts +0 -123
  29. package/__tests__/auth/auth.oauth-clients.test.ts +0 -120
  30. package/__tests__/auth/auth.oauth-consents.test.ts +0 -122
  31. package/__tests__/auth/auth.one-time-tokens.test.ts +0 -194
  32. package/__tests__/auth/auth.refresh-tokens.test.ts +0 -134
  33. package/__tests__/auth/auth.saml-providers.test.ts +0 -154
  34. package/__tests__/auth/auth.saml-relay-states.test.ts +0 -145
  35. package/__tests__/auth/auth.schema-migrations.test.ts +0 -131
  36. package/__tests__/auth/auth.sessions.test.ts +0 -140
  37. package/__tests__/auth/auth.sso-domains.test.ts +0 -137
  38. package/__tests__/auth/auth.sso-providers.test.ts +0 -136
  39. package/__tests__/auth/auth.users.test.ts +0 -314
  40. package/__tests__/conditional.test.ts +0 -229
  41. package/__tests__/functions.test.ts +0 -252
  42. package/__tests__/jsonb.test.ts +0 -237
  43. package/__tests__/net/net.http-request-queue.test.ts +0 -159
  44. package/__tests__/net/net.http-response.test.ts +0 -163
  45. package/__tests__/realtime/realtime.messages-2025-10-31.test.ts +0 -168
  46. package/__tests__/realtime/realtime.messages.test.ts +0 -162
  47. package/__tests__/realtime/realtime.schema-migrations.test.ts +0 -139
  48. package/__tests__/realtime/realtime.subscription.test.ts +0 -159
  49. package/__tests__/storage/storage.buckets-analytics.test.ts +0 -134
  50. package/__tests__/storage/storage.buckets.test.ts +0 -146
  51. package/__tests__/storage/storage.iceberg-namespaces.test.ts +0 -132
  52. package/__tests__/storage/storage.iceberg-tables.test.ts +0 -142
  53. package/__tests__/storage/storage.migrations.test.ts +0 -133
  54. package/__tests__/storage/storage.objects.test.ts +0 -160
  55. package/__tests__/storage/storage.prefixes.test.ts +0 -138
  56. package/__tests__/storage/storage.s3-multipart-uploads-parts.test.ts +0 -133
  57. package/__tests__/storage/storage.s3-multipart-uploads.test.ts +0 -128
  58. package/__tests__/supabase-functions/supabase.functions-hooks.test.ts +0 -125
  59. package/__tests__/supabase-functions/supabase.functions-migrations.test.ts +0 -213
  60. package/__tests__/temporal.test.ts +0 -225
  61. package/__tests__/vault-secrets.test.ts +0 -145
  62. package/deploy/LICENSE +0 -9
  63. package/deploy/supabase.sql +0 -2271
  64. package/jest.config.js +0 -15
  65. package/revert/supabase.sql +0 -3
  66. package/sql/supabase--0.0.1.sql +0 -1368
  67. package/src/index.ts +0 -3
  68. package/supabase.control +0 -7
  69. package/verify/supabase.sql +0 -3
@@ -1,142 +0,0 @@
1
- import { getConnections, PgTestClient } from 'supabase-test';
2
-
3
- let pg: PgTestClient;
4
- let db: PgTestClient;
5
- let teardown: () => Promise<void>;
6
-
7
- beforeAll(async () => {
8
- ({ pg, db, teardown } = await getConnections());
9
-
10
- // verify auth schema exists
11
- const authSchemaExists = await pg.any(
12
- `SELECT EXISTS (
13
- SELECT FROM information_schema.schemata
14
- WHERE schema_name = 'auth'
15
- ) as exists`
16
- );
17
- expect(authSchemaExists[0].exists).toBe(true);
18
-
19
- // grants
20
- await pg.any(
21
- `GRANT USAGE ON SCHEMA auth TO public;
22
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO service_role;
23
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO authenticated;
24
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO anon;
25
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO service_role;
26
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO authenticated;
27
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO anon;`,
28
- []
29
- );
30
-
31
- // assert exists
32
- const exists = await pg.any(
33
- `SELECT EXISTS (
34
- SELECT FROM information_schema.tables
35
- WHERE table_schema = 'auth' AND table_name = 'mfa_amr_claims'
36
- ) as exists`
37
- );
38
- expect(exists[0].exists).toBe(true);
39
- });
40
-
41
- afterAll(async () => {
42
- await teardown();
43
- });
44
-
45
- beforeEach(async () => {
46
- await db.beforeEach();
47
- });
48
-
49
- afterEach(async () => {
50
- await db.afterEach();
51
- });
52
-
53
- describe('tutorial: auth mfa_amr_claims table access', () => {
54
-
55
- it('should verify mfa_amr_claims table exists', async () => {
56
- db.setContext({ role: 'service_role' });
57
-
58
- // verify table exists in information schema
59
- const exists = await db.any(
60
- `SELECT EXISTS (
61
- SELECT FROM information_schema.tables
62
- WHERE table_schema = 'auth' AND table_name = 'mfa_amr_claims'
63
- ) as exists`
64
- );
65
-
66
- expect(Array.isArray(exists)).toBe(true);
67
- expect(exists[0].exists).toBe(true);
68
- });
69
-
70
- it('should verify service_role can query mfa_amr_claims structure', async () => {
71
- db.setContext({ role: 'service_role' });
72
- const columns = await db.any(
73
- `SELECT column_name, data_type
74
- FROM information_schema.columns
75
- WHERE table_schema = 'auth' AND table_name = 'mfa_amr_claims'
76
- ORDER BY ordinal_position`
77
- );
78
- expect(Array.isArray(columns)).toBe(true);
79
- expect(columns.length).toBeGreaterThan(0);
80
- const names = columns.map((c: any) => c.column_name);
81
- expect(names).toContain('session_id');
82
- expect(names).toContain('authentication_method');
83
- });
84
-
85
- it('should verify foreign key to auth.sessions', async () => {
86
- db.setContext({ role: 'service_role' });
87
- const fks = await db.any(
88
- `SELECT tc.constraint_name, ccu.table_name AS foreign_table_name
89
- FROM information_schema.table_constraints AS tc
90
- JOIN information_schema.constraint_column_usage AS ccu
91
- ON ccu.constraint_name = tc.constraint_name AND ccu.table_schema = tc.table_schema
92
- WHERE tc.constraint_type = 'FOREIGN KEY'
93
- AND tc.table_schema = 'auth'
94
- AND tc.table_name = 'mfa_amr_claims'`
95
- );
96
- expect(Array.isArray(fks)).toBe(true);
97
- if (fks.length > 0) {
98
- const hasSessionsFk = fks.some((r: any) => r.foreign_table_name === 'sessions');
99
- expect(hasSessionsFk).toBe(true);
100
- }
101
- });
102
-
103
- it('should verify unique composite key (session_id, authentication_method)', async () => {
104
- db.setContext({ role: 'service_role' });
105
- const uniqueCols = await db.any(
106
- `SELECT kcu.column_name
107
- FROM information_schema.table_constraints tc
108
- JOIN information_schema.key_column_usage kcu
109
- ON tc.constraint_name = kcu.constraint_name
110
- AND tc.table_schema = kcu.table_schema
111
- WHERE tc.table_schema = 'auth'
112
- AND tc.table_name = 'mfa_amr_claims'
113
- AND tc.constraint_type = 'UNIQUE'
114
- ORDER BY kcu.ordinal_position`
115
- );
116
- expect(Array.isArray(uniqueCols)).toBe(true);
117
- if (uniqueCols.length > 0) {
118
- const cols = uniqueCols.map((r: any) => r.column_name);
119
- expect(cols).toEqual(['session_id','authentication_method']);
120
- }
121
- });
122
-
123
- it('should verify anon access to mfa_amr_claims based on rls', async () => {
124
- db.setContext({ role: 'service_role' });
125
- const rlsStatus = await db.any(
126
- `SELECT c.relrowsecurity
127
- FROM pg_class c
128
- JOIN pg_namespace n ON n.oid = c.relnamespace
129
- WHERE n.nspname = 'auth' AND c.relname = 'mfa_amr_claims'`
130
- );
131
- expect(Array.isArray(rlsStatus)).toBe(true);
132
- expect(rlsStatus.length).toBeGreaterThan(0);
133
-
134
- db.clearContext();
135
- const result = await db.any(`SELECT * FROM auth.mfa_amr_claims LIMIT 1`);
136
- expect(Array.isArray(result)).toBe(true);
137
- if (rlsStatus[0].relrowsecurity === true) {
138
- expect(result.length).toBe(0);
139
- }
140
- });
141
- });
142
-
@@ -1,117 +0,0 @@
1
- import { getConnections, PgTestClient } from 'supabase-test';
2
-
3
- let pg: PgTestClient;
4
- let db: PgTestClient;
5
- let teardown: () => Promise<void>;
6
-
7
- beforeAll(async () => {
8
- ({ pg, db, teardown } = await getConnections());
9
-
10
- // verify auth schema exists
11
- const authSchemaExists = await pg.any(
12
- `SELECT EXISTS (
13
- SELECT FROM information_schema.schemata
14
- WHERE schema_name = 'auth'
15
- ) as exists`
16
- );
17
- expect(authSchemaExists[0].exists).toBe(true);
18
-
19
- // grants
20
- await pg.any(
21
- `GRANT USAGE ON SCHEMA auth TO public;
22
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO service_role;
23
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO authenticated;
24
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO anon;
25
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO service_role;
26
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO authenticated;
27
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO anon;`,
28
- []
29
- );
30
-
31
- // assert exists
32
- const exists = await pg.any(
33
- `SELECT EXISTS (
34
- SELECT FROM information_schema.tables
35
- WHERE table_schema = 'auth' AND table_name = 'mfa_challenges'
36
- ) as exists`
37
- );
38
- expect(exists[0].exists).toBe(true);
39
- });
40
-
41
- afterAll(async () => {
42
- await teardown();
43
- });
44
-
45
- beforeEach(async () => {
46
- await db.beforeEach();
47
- });
48
-
49
- afterEach(async () => {
50
- await db.afterEach();
51
- });
52
-
53
- describe('tutorial: auth mfa_challenges table access', () => {
54
-
55
- it('should verify mfa_challenges table exists', async () => {
56
- db.setContext({ role: 'service_role' });
57
-
58
- // verify table exists in information schema
59
- const exists = await db.any(
60
- `SELECT EXISTS (
61
- SELECT FROM information_schema.tables
62
- WHERE table_schema = 'auth' AND table_name = 'mfa_challenges'
63
- ) as exists`
64
- );
65
-
66
- expect(Array.isArray(exists)).toBe(true);
67
- expect(exists[0].exists).toBe(true);
68
- });
69
-
70
- it('should verify service_role can query mfa_challenges', async () => {
71
- db.setContext({ role: 'service_role' });
72
-
73
- // service_role should be able to query mfa_challenges
74
- const challenges = await db.any(
75
- `SELECT id, factor_id, ip_address, verified_at, created_at
76
- FROM auth.mfa_challenges
77
- LIMIT 10`
78
- );
79
-
80
- expect(Array.isArray(challenges)).toBe(true);
81
- });
82
-
83
- it('should verify table has index on factor_id', async () => {
84
- db.setContext({ role: 'service_role' });
85
-
86
- // check for indexes on factor_id column
87
- const indexes = await db.any(
88
- `SELECT indexname
89
- FROM pg_indexes
90
- WHERE schemaname = 'auth' AND tablename = 'mfa_challenges'
91
- AND indexname LIKE '%factor_id%'`
92
- );
93
-
94
- expect(Array.isArray(indexes)).toBe(true);
95
- });
96
-
97
- it('should verify anon access to mfa_challenges based on rls', async () => {
98
- // rls status
99
- db.setContext({ role: 'service_role' });
100
- const rlsStatus = await db.any(
101
- `SELECT c.relrowsecurity
102
- FROM pg_class c
103
- JOIN pg_namespace n ON n.oid = c.relnamespace
104
- WHERE n.nspname = 'auth' AND c.relname = 'mfa_challenges'`
105
- );
106
- expect(Array.isArray(rlsStatus)).toBe(true);
107
- expect(rlsStatus.length).toBeGreaterThan(0);
108
-
109
- db.clearContext();
110
- const result = await db.any(`SELECT * FROM auth.mfa_challenges LIMIT 1`);
111
- expect(Array.isArray(result)).toBe(true);
112
- if (rlsStatus[0].relrowsecurity === true) {
113
- expect(result.length).toBe(0);
114
- }
115
- });
116
- });
117
-
@@ -1,118 +0,0 @@
1
- import { getConnections, PgTestClient } from 'supabase-test';
2
-
3
- let pg: PgTestClient;
4
- let db: PgTestClient;
5
- let teardown: () => Promise<void>;
6
-
7
- beforeAll(async () => {
8
- ({ pg, db, teardown } = await getConnections());
9
-
10
- // verify auth schema exists
11
- const authSchemaExists = await pg.any(
12
- `SELECT EXISTS (
13
- SELECT FROM information_schema.schemata
14
- WHERE schema_name = 'auth'
15
- ) as exists`
16
- );
17
- expect(authSchemaExists[0].exists).toBe(true);
18
-
19
- // grants for reads
20
- await pg.any(
21
- `GRANT USAGE ON SCHEMA auth TO public;
22
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO service_role;
23
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO authenticated;
24
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO anon;
25
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO service_role;
26
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO authenticated;
27
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO anon;`,
28
- []
29
- );
30
-
31
- // assert mfa_factors exists (fail fast)
32
- const exists = await pg.any(
33
- `SELECT EXISTS (
34
- SELECT FROM information_schema.tables
35
- WHERE table_schema = 'auth' AND table_name = 'mfa_factors'
36
- ) as exists`
37
- );
38
- expect(exists[0].exists).toBe(true);
39
- });
40
-
41
- afterAll(async () => {
42
- await teardown();
43
- });
44
-
45
- beforeEach(async () => {
46
- await db.beforeEach();
47
- });
48
-
49
- afterEach(async () => {
50
- await db.afterEach();
51
- });
52
-
53
- describe('tutorial: auth mfa_factors table access', () => {
54
-
55
- it('should verify mfa_factors table exists', async () => {
56
- db.setContext({ role: 'service_role' });
57
-
58
- // verify table exists in information schema
59
- const exists = await db.any(
60
- `SELECT EXISTS (
61
- SELECT FROM information_schema.tables
62
- WHERE table_schema = 'auth' AND table_name = 'mfa_factors'
63
- ) as exists`
64
- );
65
-
66
- expect(Array.isArray(exists)).toBe(true);
67
- expect(exists[0].exists).toBe(true);
68
- });
69
-
70
- it('should verify service_role can read mfa_factors', async () => {
71
- db.setContext({ role: 'service_role' });
72
-
73
- // service_role should be able to query mfa_factors
74
- const factors = await db.any(
75
- `SELECT id, user_id, friendly_name, factor_type
76
- FROM auth.mfa_factors
77
- LIMIT 10`
78
- );
79
-
80
- expect(Array.isArray(factors)).toBe(true);
81
- });
82
-
83
- it('should verify unique index on (friendly_name, user_id)', async () => {
84
- db.setContext({ role: 'service_role' });
85
- const indexes = await db.any(
86
- `SELECT indexname
87
- FROM pg_indexes
88
- WHERE schemaname = 'auth' AND tablename = 'mfa_factors'`
89
- );
90
- expect(Array.isArray(indexes)).toBe(true);
91
- if (indexes.length > 0) {
92
- const hasUniqueIdx = indexes.some((r: any) => r.indexname === 'mfa_factors_user_friendly_name_unique');
93
- expect(typeof hasUniqueIdx).toBe('boolean');
94
- }
95
- });
96
-
97
- it('should verify anon access to mfa_factors based on rls', async () => {
98
- // check rls status
99
- db.setContext({ role: 'service_role' });
100
- const rlsStatus = await db.any(
101
- `SELECT c.relrowsecurity
102
- FROM pg_class c
103
- JOIN pg_namespace n ON n.oid = c.relnamespace
104
- WHERE n.nspname = 'auth' AND c.relname = 'mfa_factors'`
105
- );
106
- expect(Array.isArray(rlsStatus)).toBe(true);
107
- expect(rlsStatus.length).toBeGreaterThan(0);
108
-
109
- // anon query
110
- db.clearContext();
111
- const result = await db.any(`SELECT * FROM auth.mfa_factors LIMIT 1`);
112
- expect(Array.isArray(result)).toBe(true);
113
- if (rlsStatus[0].relrowsecurity === true) {
114
- expect(result.length).toBe(0);
115
- }
116
- });
117
- });
118
-
@@ -1,123 +0,0 @@
1
- import { getConnections, PgTestClient } from 'supabase-test';
2
-
3
- let pg: PgTestClient;
4
- let db: PgTestClient;
5
- let teardown: () => Promise<void>;
6
-
7
- beforeAll(async () => {
8
- ({ pg, db, teardown } = await getConnections());
9
-
10
- // verify auth schema exists
11
- const authSchemaExists = await pg.any(
12
- `SELECT EXISTS (
13
- SELECT FROM information_schema.schemata
14
- WHERE schema_name = 'auth'
15
- ) as exists`
16
- );
17
- expect(authSchemaExists[0].exists).toBe(true);
18
-
19
- // grants
20
- await pg.any(
21
- `GRANT USAGE ON SCHEMA auth TO public;
22
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO service_role;
23
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO authenticated;
24
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO anon;
25
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO service_role;
26
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO authenticated;
27
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO anon;`,
28
- []
29
- );
30
-
31
- // assert table exists
32
- const exists = await pg.any(
33
- `SELECT EXISTS (
34
- SELECT FROM information_schema.tables
35
- WHERE table_schema = 'auth' AND table_name = 'oauth_authorizations'
36
- ) as exists`
37
- );
38
- expect(exists[0].exists).toBe(true);
39
- });
40
-
41
- afterAll(async () => {
42
- await teardown();
43
- });
44
-
45
- beforeEach(async () => {
46
- await db.beforeEach();
47
- });
48
-
49
- afterEach(async () => {
50
- await db.afterEach();
51
- });
52
-
53
- describe('tutorial: auth oauth_authorizations table access', () => {
54
-
55
- it('should verify oauth_authorizations table exists', async () => {
56
- db.setContext({ role: 'service_role' });
57
-
58
- // verify table exists in information schema
59
- const exists = await db.any(
60
- `SELECT EXISTS (
61
- SELECT FROM information_schema.tables
62
- WHERE table_schema = 'auth' AND table_name = 'oauth_authorizations'
63
- ) as exists`
64
- );
65
-
66
- expect(Array.isArray(exists)).toBe(true);
67
- expect(exists[0].exists).toBe(true);
68
- });
69
-
70
- it('should verify service_role can query oauth_authorizations structure', async () => {
71
- db.setContext({ role: 'service_role' });
72
- const columns = await db.any(
73
- `SELECT column_name, data_type
74
- FROM information_schema.columns
75
- WHERE table_schema = 'auth' AND table_name = 'oauth_authorizations'
76
- ORDER BY ordinal_position`
77
- );
78
- expect(Array.isArray(columns)).toBe(true);
79
- expect(columns.length).toBeGreaterThan(0);
80
- const names = columns.map((c: any) => c.column_name);
81
- expect(names).toContain('id');
82
- expect(names).toContain('client_id');
83
- expect(names).toContain('authorization_id');
84
- expect(names).toContain('status');
85
- expect(names).toContain('expires_at');
86
- });
87
-
88
- it('should verify unique constraints and indexes', async () => {
89
- db.setContext({ role: 'service_role' });
90
- const uniques = await db.any(
91
- `SELECT constraint_name
92
- FROM information_schema.table_constraints
93
- WHERE table_schema = 'auth' AND table_name = 'oauth_authorizations' AND constraint_type = 'UNIQUE'`
94
- );
95
- expect(Array.isArray(uniques)).toBe(true);
96
- const indexes = await db.any(
97
- `SELECT indexname
98
- FROM pg_indexes
99
- WHERE schemaname = 'auth' AND tablename = 'oauth_authorizations'`
100
- );
101
- expect(Array.isArray(indexes)).toBe(true);
102
- });
103
-
104
- it('should verify anon access to oauth_authorizations based on rls', async () => {
105
- db.setContext({ role: 'service_role' });
106
- const rlsStatus = await db.any(
107
- `SELECT c.relrowsecurity
108
- FROM pg_class c
109
- JOIN pg_namespace n ON n.oid = c.relnamespace
110
- WHERE n.nspname = 'auth' AND c.relname = 'oauth_authorizations'`
111
- );
112
- expect(Array.isArray(rlsStatus)).toBe(true);
113
- expect(rlsStatus.length).toBeGreaterThan(0);
114
-
115
- db.clearContext();
116
- const result = await db.any(`SELECT * FROM auth.oauth_authorizations LIMIT 1`);
117
- expect(Array.isArray(result)).toBe(true);
118
- if (rlsStatus[0].relrowsecurity === true) {
119
- expect(result.length).toBe(0);
120
- }
121
- });
122
- });
123
-
@@ -1,120 +0,0 @@
1
- import { getConnections, PgTestClient } from 'supabase-test';
2
-
3
- let pg: PgTestClient;
4
- let db: PgTestClient;
5
- let teardown: () => Promise<void>;
6
-
7
- beforeAll(async () => {
8
- ({ pg, db, teardown } = await getConnections());
9
-
10
- // verify auth schema exists
11
- const authSchemaExists = await pg.any(
12
- `SELECT EXISTS (
13
- SELECT FROM information_schema.schemata
14
- WHERE schema_name = 'auth'
15
- ) as exists`
16
- );
17
- expect(authSchemaExists[0].exists).toBe(true);
18
-
19
- // grants for reads
20
- await pg.any(
21
- `GRANT USAGE ON SCHEMA auth TO public;
22
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO service_role;
23
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO authenticated;
24
- GRANT SELECT ON ALL TABLES IN SCHEMA auth TO anon;
25
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO service_role;
26
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO authenticated;
27
- ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO anon;`,
28
- []
29
- );
30
-
31
- // assert table exists (fail fast)
32
- const exists = await pg.any(
33
- `SELECT EXISTS (
34
- SELECT FROM information_schema.tables
35
- WHERE table_schema = 'auth' AND table_name = 'oauth_clients'
36
- ) as exists`
37
- );
38
- expect(exists[0].exists).toBe(true);
39
- });
40
-
41
- afterAll(async () => {
42
- await teardown();
43
- });
44
-
45
- beforeEach(async () => {
46
- await db.beforeEach();
47
- });
48
-
49
- afterEach(async () => {
50
- await db.afterEach();
51
- });
52
-
53
- describe('tutorial: auth oauth_clients table access', () => {
54
-
55
- it('should verify oauth_clients table exists', async () => {
56
- db.setContext({ role: 'service_role' });
57
-
58
- // verify table exists in information schema
59
- const exists = await db.any(
60
- `SELECT EXISTS (
61
- SELECT FROM information_schema.tables
62
- WHERE table_schema = 'auth' AND table_name = 'oauth_clients'
63
- ) as exists`
64
- );
65
-
66
- expect(Array.isArray(exists)).toBe(true);
67
- expect(exists[0].exists).toBe(true);
68
- });
69
-
70
- it('should verify service_role can read oauth_clients', async () => {
71
- db.setContext({ role: 'service_role' });
72
-
73
- // service_role should be able to query oauth_clients
74
- const clients = await db.any(
75
- `SELECT id, client_id, client_secret_hash, client_name, created_at, updated_at
76
- FROM auth.oauth_clients
77
- LIMIT 10`
78
- );
79
-
80
- expect(Array.isArray(clients)).toBe(true);
81
- });
82
-
83
- it('should verify table has unique constraint on client_id', async () => {
84
- db.setContext({ role: 'service_role' });
85
-
86
- // check for unique constraint on client_id via constraints
87
- const constraints = await db.any(
88
- `SELECT constraint_name
89
- FROM information_schema.table_constraints
90
- WHERE table_schema = 'auth' AND table_name = 'oauth_clients' AND constraint_type = 'UNIQUE'`
91
- );
92
- expect(Array.isArray(constraints)).toBe(true);
93
- // and the index exists
94
- const indexes = await db.any(
95
- `SELECT indexname FROM pg_indexes WHERE schemaname = 'auth' AND tablename = 'oauth_clients'`
96
- );
97
- expect(Array.isArray(indexes)).toBe(true);
98
- });
99
-
100
- it('should verify anon access to oauth_clients based on rls', async () => {
101
- // rls status
102
- db.setContext({ role: 'service_role' });
103
- const rlsStatus = await db.any(
104
- `SELECT c.relrowsecurity
105
- FROM pg_class c
106
- JOIN pg_namespace n ON n.oid = c.relnamespace
107
- WHERE n.nspname = 'auth' AND c.relname = 'oauth_clients'`
108
- );
109
- expect(Array.isArray(rlsStatus)).toBe(true);
110
- expect(rlsStatus.length).toBeGreaterThan(0);
111
-
112
- db.clearContext();
113
- const result = await db.any(`SELECT * FROM auth.oauth_clients LIMIT 1`);
114
- expect(Array.isArray(result)).toBe(true);
115
- if (rlsStatus[0].relrowsecurity === true) {
116
- expect(result.length).toBe(0);
117
- }
118
- });
119
- });
120
-