@pgpm/supabase 0.4.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 (57) hide show
  1. package/LICENSE +21 -0
  2. package/Makefile +7 -0
  3. package/README.md +37 -0
  4. package/__tests__/_realtime/_realtime-extensions.test.ts +129 -0
  5. package/__tests__/_realtime/_realtime-schema-migrations.test.ts +160 -0
  6. package/__tests__/_realtime/_realtime-tenants.test.ts +163 -0
  7. package/__tests__/auth/auth.audit-log-entries.test.ts +148 -0
  8. package/__tests__/auth/auth.flow-state.test.ts +114 -0
  9. package/__tests__/auth/auth.identities.test.ts +149 -0
  10. package/__tests__/auth/auth.instances.test.ts +134 -0
  11. package/__tests__/auth/auth.mfa-amr-claims.test.ts +142 -0
  12. package/__tests__/auth/auth.mfa-challenges.test.ts +117 -0
  13. package/__tests__/auth/auth.mfa-factors.test.ts +118 -0
  14. package/__tests__/auth/auth.oauth-authorizations.test.ts +123 -0
  15. package/__tests__/auth/auth.oauth-clients.test.ts +120 -0
  16. package/__tests__/auth/auth.oauth-consents.test.ts +122 -0
  17. package/__tests__/auth/auth.one-time-tokens.test.ts +194 -0
  18. package/__tests__/auth/auth.refresh-tokens.test.ts +134 -0
  19. package/__tests__/auth/auth.saml-providers.test.ts +154 -0
  20. package/__tests__/auth/auth.saml-relay-states.test.ts +145 -0
  21. package/__tests__/auth/auth.schema-migrations.test.ts +131 -0
  22. package/__tests__/auth/auth.sessions.test.ts +140 -0
  23. package/__tests__/auth/auth.sso-domains.test.ts +137 -0
  24. package/__tests__/auth/auth.sso-providers.test.ts +136 -0
  25. package/__tests__/auth/auth.users.test.ts +314 -0
  26. package/__tests__/conditional.test.ts +229 -0
  27. package/__tests__/functions.test.ts +252 -0
  28. package/__tests__/jsonb.test.ts +237 -0
  29. package/__tests__/net/net.http-request-queue.test.ts +159 -0
  30. package/__tests__/net/net.http-response.test.ts +163 -0
  31. package/__tests__/realtime/realtime.messages-2025-10-31.test.ts +168 -0
  32. package/__tests__/realtime/realtime.messages.test.ts +162 -0
  33. package/__tests__/realtime/realtime.schema-migrations.test.ts +139 -0
  34. package/__tests__/realtime/realtime.subscription.test.ts +159 -0
  35. package/__tests__/storage/storage.buckets-analytics.test.ts +134 -0
  36. package/__tests__/storage/storage.buckets.test.ts +146 -0
  37. package/__tests__/storage/storage.iceberg-namespaces.test.ts +132 -0
  38. package/__tests__/storage/storage.iceberg-tables.test.ts +142 -0
  39. package/__tests__/storage/storage.migrations.test.ts +133 -0
  40. package/__tests__/storage/storage.objects.test.ts +160 -0
  41. package/__tests__/storage/storage.prefixes.test.ts +138 -0
  42. package/__tests__/storage/storage.s3-multipart-uploads-parts.test.ts +133 -0
  43. package/__tests__/storage/storage.s3-multipart-uploads.test.ts +128 -0
  44. package/__tests__/supabase-functions/supabase.functions-hooks.test.ts +125 -0
  45. package/__tests__/supabase-functions/supabase.functions-migrations.test.ts +213 -0
  46. package/__tests__/temporal.test.ts +225 -0
  47. package/__tests__/vault-secrets.test.ts +145 -0
  48. package/deploy/LICENSE +9 -0
  49. package/deploy/supabase.sql +2271 -0
  50. package/jest.config.js +15 -0
  51. package/launchql.plan +4 -0
  52. package/package.json +23 -0
  53. package/revert/supabase.sql +3 -0
  54. package/sql/supabase--0.0.1.sql +1368 -0
  55. package/src/index.ts +3 -0
  56. package/supabase.control +7 -0
  57. package/verify/supabase.sql +3 -0
@@ -0,0 +1,168 @@
1
+ import { getConnections, PgTestClient } from 'supabase-test';
2
+
3
+ let pg: PgTestClient;
4
+ let db: PgTestClient;
5
+ let teardown: () => Promise<void>;
6
+
7
+ let tableExists = false;
8
+
9
+ beforeAll(async () => {
10
+ ({ pg, db, teardown } = await getConnections());
11
+
12
+ // verify realtime schema exists (optional schema)
13
+ const realtimeSchemaExists = await pg.any(
14
+ `SELECT EXISTS (
15
+ SELECT FROM information_schema.schemata
16
+ WHERE schema_name = 'realtime'
17
+ ) as exists`
18
+ );
19
+
20
+ if (realtimeSchemaExists[0]?.exists === true) {
21
+ // grant access to realtime schema for testing
22
+ await pg.any(
23
+ `GRANT USAGE ON SCHEMA realtime TO public;
24
+ GRANT SELECT ON ALL TABLES IN SCHEMA realtime TO service_role;
25
+ GRANT SELECT ON ALL TABLES IN SCHEMA realtime TO authenticated;
26
+ GRANT SELECT ON ALL TABLES IN SCHEMA realtime TO anon;
27
+ ALTER DEFAULT PRIVILEGES IN SCHEMA realtime GRANT SELECT ON TABLES TO service_role;
28
+ ALTER DEFAULT PRIVILEGES IN SCHEMA realtime GRANT SELECT ON TABLES TO authenticated;
29
+ ALTER DEFAULT PRIVILEGES IN SCHEMA realtime GRANT SELECT ON TABLES TO anon;`,
30
+ []
31
+ );
32
+
33
+ // check if realtime.messages_2025_10_31 partition table exists (using pg in beforeAll only)
34
+ const exists = await pg.any(
35
+ `SELECT EXISTS (
36
+ SELECT FROM information_schema.tables
37
+ WHERE table_schema = 'realtime' AND table_name = 'messages_2025_10_31'
38
+ ) as exists`
39
+ );
40
+ tableExists = exists[0]?.exists === true;
41
+ }
42
+ });
43
+
44
+ afterAll(async () => {
45
+ await teardown();
46
+ });
47
+
48
+ beforeEach(async () => {
49
+ await db.beforeEach();
50
+ });
51
+
52
+ afterEach(async () => {
53
+ await db.afterEach();
54
+ });
55
+
56
+ describe('tutorial: realtime messages partition table access', () => {
57
+
58
+ it('should verify messages partition table exists', async () => {
59
+ db.setContext({ role: 'service_role' });
60
+
61
+ // verify partition table exists in information schema
62
+ const exists = await db.any(
63
+ `SELECT EXISTS (
64
+ SELECT FROM information_schema.tables
65
+ WHERE table_schema = 'realtime' AND table_name = 'messages_2025_10_31'
66
+ ) as exists`
67
+ );
68
+
69
+ expect(Array.isArray(exists)).toBe(true);
70
+ if (exists[0]?.exists === false) {
71
+ expect(exists[0].exists).toBe(false);
72
+ return;
73
+ }
74
+ expect(exists[0].exists).toBe(true);
75
+ });
76
+
77
+ it('should verify service_role can query partition table', async () => {
78
+ if (!tableExists) {
79
+ return;
80
+ }
81
+
82
+ db.setContext({ role: 'service_role' });
83
+
84
+ // service_role should be able to query partition table directly
85
+ const messages = await db.any(
86
+ `SELECT id, channel, payload
87
+ FROM realtime.messages_2025_10_31
88
+ LIMIT 10`
89
+ );
90
+
91
+ expect(Array.isArray(messages)).toBe(true);
92
+ });
93
+
94
+ it('should verify partition inherits from parent table structure', async () => {
95
+ if (!tableExists) {
96
+ return;
97
+ }
98
+
99
+ db.setContext({ role: 'service_role' });
100
+
101
+ // partition tables inherit column structure from parent table
102
+ // verify columns match between parent and partition
103
+ const parentColumns = await db.any(
104
+ `SELECT column_name
105
+ FROM information_schema.columns
106
+ WHERE table_schema = 'realtime' AND table_name = 'messages'
107
+ ORDER BY ordinal_position`
108
+ );
109
+
110
+ const partitionColumns = await db.any(
111
+ `SELECT column_name
112
+ FROM information_schema.columns
113
+ WHERE table_schema = 'realtime' AND table_name = 'messages_2025_10_31'
114
+ ORDER BY ordinal_position`
115
+ );
116
+
117
+ expect(Array.isArray(parentColumns)).toBe(true);
118
+ expect(Array.isArray(partitionColumns)).toBe(true);
119
+ });
120
+
121
+ it('should prevent authenticated users from accessing partition table without proper permissions', async () => {
122
+ if (!tableExists) {
123
+ return;
124
+ }
125
+
126
+ // create a test user as admin using db with service_role context
127
+ // using auth.users (real supabase table) instead of rls_test.user_profiles (fake test table)
128
+ db.setContext({ role: 'service_role' });
129
+ const user = await db.one(
130
+ `INSERT INTO auth.users (id, email)
131
+ VALUES (gen_random_uuid(), $1)
132
+ RETURNING id`,
133
+ ['realtime-partition-test@example.com']
134
+ );
135
+
136
+ // set context to simulate authenticated user
137
+ db.setContext({
138
+ role: 'authenticated',
139
+ 'request.jwt.claim.sub': user.id
140
+ });
141
+
142
+ // authenticated users should not be able to access partition table (rls blocks)
143
+ const result = await db.any(
144
+ `SELECT * FROM realtime.messages_2025_10_31 LIMIT 1`
145
+ );
146
+
147
+ // rls should block access, result should be empty
148
+ expect(result.length).toBe(0);
149
+ });
150
+
151
+ it('should prevent anon from accessing partition table', async () => {
152
+ if (!tableExists) {
153
+ return;
154
+ }
155
+
156
+ // clear context to anon role
157
+ db.clearContext();
158
+
159
+ // anon should not be able to access partition table (rls blocks)
160
+ const result = await db.any(
161
+ `SELECT * FROM realtime.messages_2025_10_31 LIMIT 1`
162
+ );
163
+
164
+ // rls should block access, result should be empty
165
+ expect(result.length).toBe(0);
166
+ });
167
+ });
168
+
@@ -0,0 +1,162 @@
1
+ import { getConnections, PgTestClient } from 'supabase-test';
2
+
3
+ let pg: PgTestClient;
4
+ let db: PgTestClient;
5
+ let teardown: () => Promise<void>;
6
+
7
+ let tableExists = false;
8
+
9
+ beforeAll(async () => {
10
+ ({ pg, db, teardown } = await getConnections());
11
+
12
+ // verify realtime schema exists (optional schema)
13
+ const realtimeSchemaExists = await pg.any(
14
+ `SELECT EXISTS (
15
+ SELECT FROM information_schema.schemata
16
+ WHERE schema_name = 'realtime'
17
+ ) as exists`
18
+ );
19
+
20
+ if (realtimeSchemaExists[0]?.exists === true) {
21
+ // grant access to realtime schema for testing
22
+ await pg.any(
23
+ `GRANT USAGE ON SCHEMA realtime TO public;
24
+ GRANT SELECT ON ALL TABLES IN SCHEMA realtime TO service_role;
25
+ GRANT SELECT ON ALL TABLES IN SCHEMA realtime TO authenticated;
26
+ GRANT SELECT ON ALL TABLES IN SCHEMA realtime TO anon;
27
+ ALTER DEFAULT PRIVILEGES IN SCHEMA realtime GRANT SELECT ON TABLES TO service_role;
28
+ ALTER DEFAULT PRIVILEGES IN SCHEMA realtime GRANT SELECT ON TABLES TO authenticated;
29
+ ALTER DEFAULT PRIVILEGES IN SCHEMA realtime GRANT SELECT ON TABLES TO anon;`,
30
+ []
31
+ );
32
+
33
+ // check if realtime.messages table exists (using pg in beforeAll only)
34
+ const exists = await pg.any(
35
+ `SELECT EXISTS (
36
+ SELECT FROM information_schema.tables
37
+ WHERE table_schema = 'realtime' AND table_name = 'messages'
38
+ ) as exists`
39
+ );
40
+ tableExists = exists[0]?.exists === true;
41
+ }
42
+ });
43
+
44
+ afterAll(async () => {
45
+ await teardown();
46
+ });
47
+
48
+ beforeEach(async () => {
49
+ await db.beforeEach();
50
+ });
51
+
52
+ afterEach(async () => {
53
+ await db.afterEach();
54
+ });
55
+
56
+ describe('tutorial: realtime messages table access', () => {
57
+
58
+ it('should verify messages table exists', async () => {
59
+ db.setContext({ role: 'service_role' });
60
+
61
+ // verify table exists in information schema
62
+ const exists = await db.any(
63
+ `SELECT EXISTS (
64
+ SELECT FROM information_schema.tables
65
+ WHERE table_schema = 'realtime' AND table_name = 'messages'
66
+ ) as exists`
67
+ );
68
+
69
+ expect(Array.isArray(exists)).toBe(true);
70
+ if (exists[0]?.exists === false) {
71
+ expect(exists[0].exists).toBe(false);
72
+ return;
73
+ }
74
+ expect(exists[0].exists).toBe(true);
75
+ });
76
+
77
+ it('should verify service_role can query messages', async () => {
78
+ if (!tableExists) {
79
+ return;
80
+ }
81
+
82
+ db.setContext({ role: 'service_role' });
83
+
84
+ // service_role should be able to query messages
85
+ const messages = await db.any(
86
+ `SELECT id, channel, payload, inserted_at
87
+ FROM realtime.messages
88
+ LIMIT 10`
89
+ );
90
+
91
+ expect(Array.isArray(messages)).toBe(true);
92
+ });
93
+
94
+ it('should verify table is partitioned or has partition inheritance', async () => {
95
+ if (!tableExists) {
96
+ return;
97
+ }
98
+
99
+ db.setContext({ role: 'service_role' });
100
+
101
+ // realtime.messages uses table partitioning for time-based data management
102
+ // check for partition inheritance in pg_class
103
+ const partitionInfo = await db.any(
104
+ `SELECT c.relname, c.relkind
105
+ FROM pg_class c
106
+ JOIN pg_namespace n ON n.oid = c.relnamespace
107
+ WHERE n.nspname = 'realtime'
108
+ AND c.relname LIKE 'messages%'
109
+ AND (c.relkind = 'r' OR c.relkind = 'p')`
110
+ );
111
+
112
+ expect(Array.isArray(partitionInfo)).toBe(true);
113
+ });
114
+
115
+ it('should prevent authenticated users from accessing messages without proper permissions', async () => {
116
+ if (!tableExists) {
117
+ return;
118
+ }
119
+
120
+ // create a test user as admin using db with service_role context
121
+ // using auth.users (real supabase table) instead of rls_test.user_profiles (fake test table)
122
+ db.setContext({ role: 'service_role' });
123
+ const user = await db.one(
124
+ `INSERT INTO auth.users (id, email)
125
+ VALUES (gen_random_uuid(), $1)
126
+ RETURNING id`,
127
+ ['realtime-messages-test@example.com']
128
+ );
129
+
130
+ // set context to simulate authenticated user
131
+ db.setContext({
132
+ role: 'authenticated',
133
+ 'request.jwt.claim.sub': user.id
134
+ });
135
+
136
+ // authenticated users should not be able to access messages (rls blocks)
137
+ const result = await db.any(
138
+ `SELECT * FROM realtime.messages LIMIT 1`
139
+ );
140
+
141
+ // rls should block access, result should be empty
142
+ expect(result.length).toBe(0);
143
+ });
144
+
145
+ it('should prevent anon from accessing messages', async () => {
146
+ if (!tableExists) {
147
+ return;
148
+ }
149
+
150
+ // clear context to anon role
151
+ db.clearContext();
152
+
153
+ // anon should not be able to access messages (rls blocks)
154
+ const result = await db.any(
155
+ `SELECT * FROM realtime.messages LIMIT 1`
156
+ );
157
+
158
+ // rls should block access, result should be empty
159
+ expect(result.length).toBe(0);
160
+ });
161
+ });
162
+
@@ -0,0 +1,139 @@
1
+ import { getConnections, PgTestClient } from 'supabase-test';
2
+
3
+ let pg: PgTestClient;
4
+ let db: PgTestClient;
5
+ let teardown: () => Promise<void>;
6
+
7
+ let tableExists = false;
8
+
9
+ beforeAll(async () => {
10
+ ({ pg, db, teardown } = await getConnections());
11
+
12
+ // verify realtime schema exists (optional schema)
13
+ const realtimeSchemaExists = await pg.any(
14
+ `SELECT EXISTS (
15
+ SELECT FROM information_schema.schemata
16
+ WHERE schema_name = 'realtime'
17
+ ) as exists`
18
+ );
19
+
20
+ if (realtimeSchemaExists[0]?.exists === true) {
21
+ // grant access to realtime schema for testing
22
+ await pg.any(
23
+ `GRANT USAGE ON SCHEMA realtime TO public;
24
+ GRANT SELECT ON ALL TABLES IN SCHEMA realtime TO service_role;
25
+ GRANT SELECT ON ALL TABLES IN SCHEMA realtime TO authenticated;
26
+ GRANT SELECT ON ALL TABLES IN SCHEMA realtime TO anon;
27
+ ALTER DEFAULT PRIVILEGES IN SCHEMA realtime GRANT SELECT ON TABLES TO service_role;
28
+ ALTER DEFAULT PRIVILEGES IN SCHEMA realtime GRANT SELECT ON TABLES TO authenticated;
29
+ ALTER DEFAULT PRIVILEGES IN SCHEMA realtime GRANT SELECT ON TABLES TO anon;`,
30
+ []
31
+ );
32
+
33
+ // check if realtime.schema_migrations table exists (using pg in beforeAll only)
34
+ const exists = await pg.any(
35
+ `SELECT EXISTS (
36
+ SELECT FROM information_schema.tables
37
+ WHERE table_schema = 'realtime' AND table_name = 'schema_migrations'
38
+ ) as exists`
39
+ );
40
+ tableExists = exists[0]?.exists === true;
41
+ }
42
+ });
43
+
44
+ afterAll(async () => {
45
+ await teardown();
46
+ });
47
+
48
+ beforeEach(async () => {
49
+ await db.beforeEach();
50
+ });
51
+
52
+ afterEach(async () => {
53
+ await db.afterEach();
54
+ });
55
+
56
+ describe('tutorial: realtime schema_migrations table access', () => {
57
+
58
+ it('should verify schema_migrations table exists', async () => {
59
+ db.setContext({ role: 'service_role' });
60
+
61
+ // verify table exists in information schema
62
+ const exists = await db.any(
63
+ `SELECT EXISTS (
64
+ SELECT FROM information_schema.tables
65
+ WHERE table_schema = 'realtime' AND table_name = 'schema_migrations'
66
+ ) as exists`
67
+ );
68
+
69
+ expect(Array.isArray(exists)).toBe(true);
70
+ if (exists[0]?.exists === false) {
71
+ expect(exists[0].exists).toBe(false);
72
+ return;
73
+ }
74
+ expect(exists[0].exists).toBe(true);
75
+ });
76
+
77
+ it('should verify service_role can read migration versions', async () => {
78
+ if (!tableExists) {
79
+ return;
80
+ }
81
+
82
+ db.setContext({ role: 'service_role' });
83
+
84
+ // service_role should be able to query migration versions
85
+ const migrations = await db.any(
86
+ `SELECT version FROM realtime.schema_migrations ORDER BY version`
87
+ );
88
+
89
+ expect(Array.isArray(migrations)).toBe(true);
90
+ });
91
+
92
+ it('should prevent authenticated users from accessing schema_migrations without proper permissions', async () => {
93
+ if (!tableExists) {
94
+ return;
95
+ }
96
+
97
+ // create a test user as admin using db with service_role context
98
+ // using auth.users (real supabase table) instead of rls_test.user_profiles (fake test table)
99
+ db.setContext({ role: 'service_role' });
100
+ const user = await db.one(
101
+ `INSERT INTO auth.users (id, email)
102
+ VALUES (gen_random_uuid(), $1)
103
+ RETURNING id`,
104
+ ['realtime-schema-migrations-test@example.com']
105
+ );
106
+
107
+ // set context to simulate authenticated user
108
+ db.setContext({
109
+ role: 'authenticated',
110
+ 'request.jwt.claim.sub': user.id
111
+ });
112
+
113
+ // authenticated users should not be able to access schema_migrations (rls blocks)
114
+ const result = await db.any(
115
+ `SELECT * FROM realtime.schema_migrations LIMIT 1`
116
+ );
117
+
118
+ // rls should block access, result should be empty
119
+ expect(result.length).toBe(0);
120
+ });
121
+
122
+ it('should prevent anon from accessing schema_migrations', async () => {
123
+ if (!tableExists) {
124
+ return;
125
+ }
126
+
127
+ // clear context to anon role
128
+ db.clearContext();
129
+
130
+ // anon should not be able to access schema_migrations (rls blocks)
131
+ const result = await db.any(
132
+ `SELECT * FROM realtime.schema_migrations LIMIT 1`
133
+ );
134
+
135
+ // rls should block access, result should be empty
136
+ expect(result.length).toBe(0);
137
+ });
138
+ });
139
+
@@ -0,0 +1,159 @@
1
+ import { getConnections, PgTestClient } from 'supabase-test';
2
+
3
+ let pg: PgTestClient;
4
+ let db: PgTestClient;
5
+ let teardown: () => Promise<void>;
6
+
7
+ let tableExists = false;
8
+
9
+ beforeAll(async () => {
10
+ ({ pg, db, teardown } = await getConnections());
11
+
12
+ // verify realtime schema exists (optional schema)
13
+ const realtimeSchemaExists = await pg.any(
14
+ `SELECT EXISTS (
15
+ SELECT FROM information_schema.schemata
16
+ WHERE schema_name = 'realtime'
17
+ ) as exists`
18
+ );
19
+
20
+ if (realtimeSchemaExists[0]?.exists === true) {
21
+ // grant access to realtime schema for testing
22
+ await pg.any(
23
+ `GRANT USAGE ON SCHEMA realtime TO public;
24
+ GRANT SELECT ON ALL TABLES IN SCHEMA realtime TO service_role;
25
+ GRANT SELECT ON ALL TABLES IN SCHEMA realtime TO authenticated;
26
+ GRANT SELECT ON ALL TABLES IN SCHEMA realtime TO anon;
27
+ ALTER DEFAULT PRIVILEGES IN SCHEMA realtime GRANT SELECT ON TABLES TO service_role;
28
+ ALTER DEFAULT PRIVILEGES IN SCHEMA realtime GRANT SELECT ON TABLES TO authenticated;
29
+ ALTER DEFAULT PRIVILEGES IN SCHEMA realtime GRANT SELECT ON TABLES TO anon;`,
30
+ []
31
+ );
32
+
33
+ // check if realtime.subscription table exists (using pg in beforeAll only)
34
+ const exists = await pg.any(
35
+ `SELECT EXISTS (
36
+ SELECT FROM information_schema.tables
37
+ WHERE table_schema = 'realtime' AND table_name = 'subscription'
38
+ ) as exists`
39
+ );
40
+ tableExists = exists[0]?.exists === true;
41
+ }
42
+ });
43
+
44
+ afterAll(async () => {
45
+ await teardown();
46
+ });
47
+
48
+ beforeEach(async () => {
49
+ await db.beforeEach();
50
+ });
51
+
52
+ afterEach(async () => {
53
+ await db.afterEach();
54
+ });
55
+
56
+ describe('tutorial: realtime subscription table access', () => {
57
+
58
+ it('should verify subscription table exists', async () => {
59
+ db.setContext({ role: 'service_role' });
60
+
61
+ // verify table exists in information schema
62
+ const exists = await db.any(
63
+ `SELECT EXISTS (
64
+ SELECT FROM information_schema.tables
65
+ WHERE table_schema = 'realtime' AND table_name = 'subscription'
66
+ ) as exists`
67
+ );
68
+
69
+ expect(Array.isArray(exists)).toBe(true);
70
+ if (exists[0]?.exists === false) {
71
+ expect(exists[0].exists).toBe(false);
72
+ return;
73
+ }
74
+ expect(exists[0].exists).toBe(true);
75
+ });
76
+
77
+ it('should verify service_role can query subscription', async () => {
78
+ if (!tableExists) {
79
+ return;
80
+ }
81
+
82
+ db.setContext({ role: 'service_role' });
83
+
84
+ // service_role should be able to query subscription
85
+ const subscriptions = await db.any(
86
+ `SELECT id, entity, filters, created_at
87
+ FROM realtime.subscription
88
+ LIMIT 10`
89
+ );
90
+
91
+ expect(Array.isArray(subscriptions)).toBe(true);
92
+ });
93
+
94
+ it('should verify table structure via information_schema', async () => {
95
+ if (!tableExists) {
96
+ return;
97
+ }
98
+
99
+ db.setContext({ role: 'service_role' });
100
+
101
+ // query table column structure
102
+ const columns = await db.any(
103
+ `SELECT column_name, data_type
104
+ FROM information_schema.columns
105
+ WHERE table_schema = 'realtime' AND table_name = 'subscription'
106
+ ORDER BY ordinal_position`
107
+ );
108
+
109
+ expect(Array.isArray(columns)).toBe(true);
110
+ });
111
+
112
+ it('should prevent authenticated users from accessing subscription without proper permissions', async () => {
113
+ if (!tableExists) {
114
+ return;
115
+ }
116
+
117
+ // create a test user as admin using db with service_role context
118
+ // using auth.users (real supabase table) instead of rls_test.user_profiles (fake test table)
119
+ db.setContext({ role: 'service_role' });
120
+ const user = await db.one(
121
+ `INSERT INTO auth.users (id, email)
122
+ VALUES (gen_random_uuid(), $1)
123
+ RETURNING id`,
124
+ ['realtime-subscription-test@example.com']
125
+ );
126
+
127
+ // set context to simulate authenticated user
128
+ db.setContext({
129
+ role: 'authenticated',
130
+ 'request.jwt.claim.sub': user.id
131
+ });
132
+
133
+ // authenticated users should not be able to access subscription (rls blocks)
134
+ const result = await db.any(
135
+ `SELECT * FROM realtime.subscription LIMIT 1`
136
+ );
137
+
138
+ // rls should block access, result should be empty
139
+ expect(result.length).toBe(0);
140
+ });
141
+
142
+ it('should prevent anon from accessing subscription', async () => {
143
+ if (!tableExists) {
144
+ return;
145
+ }
146
+
147
+ // clear context to anon role
148
+ db.clearContext();
149
+
150
+ // anon should not be able to access subscription (rls blocks)
151
+ const result = await db.any(
152
+ `SELECT * FROM realtime.subscription LIMIT 1`
153
+ );
154
+
155
+ // rls should block access, result should be empty
156
+ expect(result.length).toBe(0);
157
+ });
158
+ });
159
+