@pgpm/supabase 0.5.0 → 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.
- package/LICENSE +2 -1
- package/Makefile +2 -3
- package/README.md +45 -32
- package/deploy/roles/anon.sql +15 -0
- package/deploy/schemas/supabase_integration/procedures/pre_request.sql +26 -0
- package/deploy/schemas/supabase_integration/schema.sql +9 -0
- package/package.json +27 -12
- package/pgpm-supabase.control +7 -0
- package/pgpm.plan +6 -3
- package/revert/roles/anon.sql +7 -0
- package/revert/schemas/supabase_integration/procedures/pre_request.sql +7 -0
- package/revert/schemas/supabase_integration/schema.sql +7 -0
- package/sql/pgpm-supabase--1.0.0.bundle.tar.gz +0 -0
- package/sql/pgpm-supabase--1.0.0.sql +32 -0
- package/verify/roles/anon.sql +12 -0
- package/verify/schemas/supabase_integration/procedures/pre_request.sql +19 -0
- package/verify/schemas/supabase_integration/schema.sql +18 -0
- package/__tests__/_realtime/_realtime-extensions.test.ts +0 -129
- package/__tests__/_realtime/_realtime-schema-migrations.test.ts +0 -160
- package/__tests__/_realtime/_realtime-tenants.test.ts +0 -163
- package/__tests__/auth/auth.audit-log-entries.test.ts +0 -148
- package/__tests__/auth/auth.flow-state.test.ts +0 -114
- package/__tests__/auth/auth.identities.test.ts +0 -149
- package/__tests__/auth/auth.instances.test.ts +0 -134
- package/__tests__/auth/auth.mfa-amr-claims.test.ts +0 -142
- package/__tests__/auth/auth.mfa-challenges.test.ts +0 -117
- package/__tests__/auth/auth.mfa-factors.test.ts +0 -118
- package/__tests__/auth/auth.oauth-authorizations.test.ts +0 -123
- package/__tests__/auth/auth.oauth-clients.test.ts +0 -120
- package/__tests__/auth/auth.oauth-consents.test.ts +0 -122
- package/__tests__/auth/auth.one-time-tokens.test.ts +0 -194
- package/__tests__/auth/auth.refresh-tokens.test.ts +0 -134
- package/__tests__/auth/auth.saml-providers.test.ts +0 -154
- package/__tests__/auth/auth.saml-relay-states.test.ts +0 -145
- package/__tests__/auth/auth.schema-migrations.test.ts +0 -131
- package/__tests__/auth/auth.sessions.test.ts +0 -140
- package/__tests__/auth/auth.sso-domains.test.ts +0 -137
- package/__tests__/auth/auth.sso-providers.test.ts +0 -136
- package/__tests__/auth/auth.users.test.ts +0 -314
- package/__tests__/conditional.test.ts +0 -229
- package/__tests__/functions.test.ts +0 -252
- package/__tests__/jsonb.test.ts +0 -237
- package/__tests__/net/net.http-request-queue.test.ts +0 -159
- package/__tests__/net/net.http-response.test.ts +0 -163
- package/__tests__/realtime/realtime.messages-2025-10-31.test.ts +0 -168
- package/__tests__/realtime/realtime.messages.test.ts +0 -162
- package/__tests__/realtime/realtime.schema-migrations.test.ts +0 -139
- package/__tests__/realtime/realtime.subscription.test.ts +0 -159
- package/__tests__/storage/storage.buckets-analytics.test.ts +0 -134
- package/__tests__/storage/storage.buckets.test.ts +0 -146
- package/__tests__/storage/storage.iceberg-namespaces.test.ts +0 -132
- package/__tests__/storage/storage.iceberg-tables.test.ts +0 -142
- package/__tests__/storage/storage.migrations.test.ts +0 -133
- package/__tests__/storage/storage.objects.test.ts +0 -160
- package/__tests__/storage/storage.prefixes.test.ts +0 -138
- package/__tests__/storage/storage.s3-multipart-uploads-parts.test.ts +0 -133
- package/__tests__/storage/storage.s3-multipart-uploads.test.ts +0 -128
- package/__tests__/supabase-functions/supabase.functions-hooks.test.ts +0 -125
- package/__tests__/supabase-functions/supabase.functions-migrations.test.ts +0 -213
- package/__tests__/temporal.test.ts +0 -225
- package/__tests__/vault-secrets.test.ts +0 -145
- package/deploy/LICENSE +0 -9
- package/deploy/supabase.sql +0 -2271
- package/jest.config.js +0 -15
- package/revert/supabase.sql +0 -3
- package/sql/supabase--0.0.1.sql +0 -1368
- package/src/index.ts +0 -3
- package/supabase.control +0 -7
- package/verify/supabase.sql +0 -3
|
@@ -1,163 +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
|
-
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.tenants 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 = 'tenants'
|
|
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 tenants table access', () => {
|
|
57
|
-
|
|
58
|
-
it('should verify tenants 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 = 'tenants'
|
|
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 tenants structure', async () => {
|
|
78
|
-
if (!tableExists) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
db.setContext({ role: 'service_role' });
|
|
83
|
-
|
|
84
|
-
// query table column structure
|
|
85
|
-
const columns = await db.any(
|
|
86
|
-
`SELECT column_name, data_type
|
|
87
|
-
FROM information_schema.columns
|
|
88
|
-
WHERE table_schema = '_realtime' AND table_name = 'tenants'
|
|
89
|
-
ORDER BY ordinal_position`
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
expect(Array.isArray(columns)).toBe(true);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should verify table has primary key constraint', async () => {
|
|
96
|
-
if (!tableExists) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
db.setContext({ role: 'service_role' });
|
|
101
|
-
|
|
102
|
-
// check for primary key constraint
|
|
103
|
-
const constraints = await db.any(
|
|
104
|
-
`SELECT constraint_name, constraint_type
|
|
105
|
-
FROM information_schema.table_constraints
|
|
106
|
-
WHERE table_schema = '_realtime' AND table_name = 'tenants'
|
|
107
|
-
AND constraint_type = 'PRIMARY KEY'`
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
expect(Array.isArray(constraints)).toBe(true);
|
|
111
|
-
if (constraints.length > 0) {
|
|
112
|
-
expect(constraints[0].constraint_name).toBeDefined();
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should prevent authenticated users from accessing tenants without proper permissions', async () => {
|
|
117
|
-
if (!tableExists) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// create a test user as admin using db with service_role context
|
|
122
|
-
// using auth.users (real supabase table) instead of rls_test.user_profiles (fake test table)
|
|
123
|
-
db.setContext({ role: 'service_role' });
|
|
124
|
-
const user = await db.one(
|
|
125
|
-
`INSERT INTO auth.users (id, email)
|
|
126
|
-
VALUES (gen_random_uuid(), $1)
|
|
127
|
-
RETURNING id`,
|
|
128
|
-
['realtime-tenants-test@example.com']
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
// set context to simulate authenticated user
|
|
132
|
-
db.setContext({
|
|
133
|
-
role: 'authenticated',
|
|
134
|
-
'request.jwt.claim.sub': user.id
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// authenticated users should not be able to access tenants (rls blocks)
|
|
138
|
-
const result = await db.any(
|
|
139
|
-
`SELECT * FROM _realtime.tenants LIMIT 1`
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
// rls should block access, result should be empty
|
|
143
|
-
expect(result.length).toBe(0);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('should prevent anon from accessing tenants', async () => {
|
|
147
|
-
if (!tableExists) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// clear context to anon role
|
|
152
|
-
db.clearContext();
|
|
153
|
-
|
|
154
|
-
// anon should not be able to access tenants (rls blocks)
|
|
155
|
-
const result = await db.any(
|
|
156
|
-
`SELECT * FROM _realtime.tenants LIMIT 1`
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
// rls should block access, result should be empty
|
|
160
|
-
expect(result.length).toBe(0);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
@@ -1,148 +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
|
-
// grant access to auth schema for testing
|
|
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 for this schema
|
|
32
|
-
const exists = await pg.any(
|
|
33
|
-
`SELECT EXISTS (
|
|
34
|
-
SELECT FROM information_schema.tables
|
|
35
|
-
WHERE table_schema = 'auth' AND table_name = 'audit_log_entries'
|
|
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 audit_log_entries table access', () => {
|
|
54
|
-
|
|
55
|
-
it('should verify audit_log_entries table exists', async () => {
|
|
56
|
-
db.setContext({ role: 'service_role' });
|
|
57
|
-
|
|
58
|
-
const exists = await db.any(
|
|
59
|
-
`SELECT EXISTS (
|
|
60
|
-
SELECT FROM information_schema.tables
|
|
61
|
-
WHERE table_schema = 'auth' AND table_name = 'audit_log_entries'
|
|
62
|
-
) as exists`
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
expect(Array.isArray(exists)).toBe(true);
|
|
66
|
-
expect(exists[0].exists).toBe(true);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should verify service_role can read audit log entries', async () => {
|
|
70
|
-
db.setContext({ role: 'service_role' });
|
|
71
|
-
|
|
72
|
-
const entries = await db.any(
|
|
73
|
-
`SELECT id, instance_id, payload, created_at
|
|
74
|
-
FROM auth.audit_log_entries
|
|
75
|
-
LIMIT 10`
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
expect(Array.isArray(entries)).toBe(true);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should verify table has expected columns', async () => {
|
|
82
|
-
db.setContext({ role: 'service_role' });
|
|
83
|
-
|
|
84
|
-
const columns = await db.any(
|
|
85
|
-
`SELECT column_name
|
|
86
|
-
FROM information_schema.columns
|
|
87
|
-
WHERE table_schema = 'auth' AND table_name = 'audit_log_entries'`
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
expect(Array.isArray(columns)).toBe(true);
|
|
91
|
-
const names = columns.map((r: any) => r.column_name);
|
|
92
|
-
expect(names).toEqual(expect.arrayContaining(['id', 'instance_id', 'payload', 'created_at']));
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should verify table has primary key on id', async () => {
|
|
96
|
-
db.setContext({ role: 'service_role' });
|
|
97
|
-
|
|
98
|
-
const pk = await db.any(
|
|
99
|
-
`SELECT constraint_name
|
|
100
|
-
FROM information_schema.table_constraints
|
|
101
|
-
WHERE table_schema = 'auth' AND table_name = 'audit_log_entries'
|
|
102
|
-
AND constraint_type = 'PRIMARY KEY'`
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
expect(Array.isArray(pk)).toBe(true);
|
|
106
|
-
if (pk.length > 0) {
|
|
107
|
-
expect(pk[0].constraint_name).toBeDefined();
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('should verify table has index on instance_id', async () => {
|
|
112
|
-
db.setContext({ role: 'service_role' });
|
|
113
|
-
|
|
114
|
-
const indexes = await db.any(
|
|
115
|
-
`SELECT indexname, indexdef
|
|
116
|
-
FROM pg_indexes
|
|
117
|
-
WHERE schemaname = 'auth' AND tablename = 'audit_log_entries'
|
|
118
|
-
AND indexname LIKE '%instance_id%'`
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
expect(Array.isArray(indexes)).toBe(true);
|
|
122
|
-
if (indexes.length > 0) {
|
|
123
|
-
const defs = indexes.map((r: any) => r.indexdef.toLowerCase()).join(' ');
|
|
124
|
-
expect(defs.includes('instance_id')).toBe(true);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('should verify anon access to audit logs based on rls', async () => {
|
|
129
|
-
// check rls status
|
|
130
|
-
db.setContext({ role: 'service_role' });
|
|
131
|
-
const rlsStatus = await db.any(
|
|
132
|
-
`SELECT c.relrowsecurity
|
|
133
|
-
FROM pg_class c
|
|
134
|
-
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
135
|
-
WHERE n.nspname = 'auth' AND c.relname = 'audit_log_entries'`
|
|
136
|
-
);
|
|
137
|
-
expect(Array.isArray(rlsStatus)).toBe(true);
|
|
138
|
-
expect(rlsStatus.length).toBeGreaterThan(0);
|
|
139
|
-
|
|
140
|
-
db.clearContext();
|
|
141
|
-
const result = await db.any(`SELECT * FROM auth.audit_log_entries LIMIT 1`);
|
|
142
|
-
expect(Array.isArray(result)).toBe(true);
|
|
143
|
-
if (rlsStatus[0].relrowsecurity === true) {
|
|
144
|
-
expect(result.length).toBe(0);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
@@ -1,114 +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
|
-
// grant access to auth schema for testing
|
|
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 auth.flow_state table exists (fail fast, no hiding)
|
|
32
|
-
const flowStateExists = await pg.any(
|
|
33
|
-
`SELECT EXISTS (
|
|
34
|
-
SELECT FROM information_schema.tables
|
|
35
|
-
WHERE table_schema = 'auth' AND table_name = 'flow_state'
|
|
36
|
-
) as exists`
|
|
37
|
-
);
|
|
38
|
-
expect(flowStateExists[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 flow_state table access', () => {
|
|
54
|
-
|
|
55
|
-
it('should verify flow_state table exists', async () => {
|
|
56
|
-
db.setContext({ role: 'service_role' });
|
|
57
|
-
const exists = await db.any(
|
|
58
|
-
`SELECT EXISTS (
|
|
59
|
-
SELECT FROM information_schema.tables
|
|
60
|
-
WHERE table_schema = 'auth' AND table_name = 'flow_state'
|
|
61
|
-
) as exists`
|
|
62
|
-
);
|
|
63
|
-
expect(Array.isArray(exists)).toBe(true);
|
|
64
|
-
expect(exists[0].exists).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should verify service_role can query flow_state structure', async () => {
|
|
68
|
-
db.setContext({ role: 'service_role' });
|
|
69
|
-
const columns = await db.any(
|
|
70
|
-
`SELECT column_name, data_type
|
|
71
|
-
FROM information_schema.columns
|
|
72
|
-
WHERE table_schema = 'auth' AND table_name = 'flow_state'
|
|
73
|
-
ORDER BY ordinal_position`
|
|
74
|
-
);
|
|
75
|
-
expect(Array.isArray(columns)).toBe(true);
|
|
76
|
-
expect(columns.length).toBeGreaterThan(0);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should verify table presence via pg_class', async () => {
|
|
80
|
-
db.setContext({ role: 'service_role' });
|
|
81
|
-
const tableInfo = await db.any(
|
|
82
|
-
`SELECT c.relname, n.nspname
|
|
83
|
-
FROM pg_class c
|
|
84
|
-
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
85
|
-
WHERE n.nspname = 'auth' AND c.relname = 'flow_state'`
|
|
86
|
-
);
|
|
87
|
-
expect(Array.isArray(tableInfo)).toBe(true);
|
|
88
|
-
expect(tableInfo.length).toBeGreaterThan(0);
|
|
89
|
-
expect(tableInfo[0].relname).toBe('flow_state');
|
|
90
|
-
expect(tableInfo[0].nspname).toBe('auth');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should verify anon access to flow_state based on rls', async () => {
|
|
94
|
-
// find rls status
|
|
95
|
-
db.setContext({ role: 'service_role' });
|
|
96
|
-
const rlsStatus = await db.any(
|
|
97
|
-
`SELECT c.relrowsecurity
|
|
98
|
-
FROM pg_class c
|
|
99
|
-
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
100
|
-
WHERE n.nspname = 'auth' AND c.relname = 'flow_state'`
|
|
101
|
-
);
|
|
102
|
-
expect(Array.isArray(rlsStatus)).toBe(true);
|
|
103
|
-
expect(rlsStatus.length).toBeGreaterThan(0);
|
|
104
|
-
|
|
105
|
-
// query as anon
|
|
106
|
-
db.clearContext();
|
|
107
|
-
const result = await db.any(`SELECT * FROM auth.flow_state LIMIT 1`);
|
|
108
|
-
expect(Array.isArray(result)).toBe(true);
|
|
109
|
-
if (rlsStatus[0].relrowsecurity === true) {
|
|
110
|
-
expect(result.length).toBe(0);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
@@ -1,149 +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
|
-
// grant access to auth schema for testing
|
|
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 identities table exists now (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 = 'identities'
|
|
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 identities table access', () => {
|
|
54
|
-
|
|
55
|
-
it('should verify identities table exists', async () => {
|
|
56
|
-
db.setContext({ role: 'service_role' });
|
|
57
|
-
const exists = await db.any(
|
|
58
|
-
`SELECT EXISTS (
|
|
59
|
-
SELECT FROM information_schema.tables
|
|
60
|
-
WHERE table_schema = 'auth' AND table_name = 'identities'
|
|
61
|
-
) as exists`
|
|
62
|
-
);
|
|
63
|
-
expect(Array.isArray(exists)).toBe(true);
|
|
64
|
-
expect(exists[0].exists).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should verify service_role can query identities table structure', async () => {
|
|
68
|
-
db.setContext({ role: 'service_role' });
|
|
69
|
-
const columns = await db.any(
|
|
70
|
-
`SELECT column_name, data_type
|
|
71
|
-
FROM information_schema.columns
|
|
72
|
-
WHERE table_schema = 'auth' AND table_name = 'identities'
|
|
73
|
-
ORDER BY ordinal_position`
|
|
74
|
-
);
|
|
75
|
-
expect(Array.isArray(columns)).toBe(true);
|
|
76
|
-
expect(columns.length).toBeGreaterThan(0);
|
|
77
|
-
const names = columns.map((c: any) => c.column_name);
|
|
78
|
-
expect(names).toContain('id');
|
|
79
|
-
expect(names).toContain('user_id');
|
|
80
|
-
expect(names).toContain('identity_data');
|
|
81
|
-
expect(names).toContain('provider');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should verify service_role can read identities', async () => {
|
|
85
|
-
db.setContext({ role: 'service_role' });
|
|
86
|
-
const identities = await db.any(`SELECT * FROM auth.identities LIMIT 10`);
|
|
87
|
-
expect(Array.isArray(identities)).toBe(true);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should verify foreign key to auth.users', async () => {
|
|
91
|
-
db.setContext({ role: 'service_role' });
|
|
92
|
-
const fks = await db.any(
|
|
93
|
-
`SELECT tc.constraint_name, ccu.table_name AS foreign_table_name
|
|
94
|
-
FROM information_schema.table_constraints AS tc
|
|
95
|
-
JOIN information_schema.constraint_column_usage AS ccu
|
|
96
|
-
ON ccu.constraint_name = tc.constraint_name AND ccu.table_schema = tc.table_schema
|
|
97
|
-
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
98
|
-
AND tc.table_schema = 'auth'
|
|
99
|
-
AND tc.table_name = 'identities'`
|
|
100
|
-
);
|
|
101
|
-
expect(Array.isArray(fks)).toBe(true);
|
|
102
|
-
if (fks.length > 0) {
|
|
103
|
-
const hasUsersFk = fks.some((r: any) => r.foreign_table_name === 'users');
|
|
104
|
-
expect(hasUsersFk).toBe(true);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should verify composite primary key (provider, id)', async () => {
|
|
109
|
-
db.setContext({ role: 'service_role' });
|
|
110
|
-
const pkCols = await db.any(
|
|
111
|
-
`SELECT kcu.column_name
|
|
112
|
-
FROM information_schema.table_constraints tc
|
|
113
|
-
JOIN information_schema.key_column_usage kcu
|
|
114
|
-
ON tc.constraint_name = kcu.constraint_name
|
|
115
|
-
AND tc.table_schema = kcu.table_schema
|
|
116
|
-
WHERE tc.table_schema = 'auth'
|
|
117
|
-
AND tc.table_name = 'identities'
|
|
118
|
-
AND tc.constraint_type = 'PRIMARY KEY'
|
|
119
|
-
ORDER BY kcu.ordinal_position`
|
|
120
|
-
);
|
|
121
|
-
expect(Array.isArray(pkCols)).toBe(true);
|
|
122
|
-
if (pkCols.length > 0) {
|
|
123
|
-
const cols = pkCols.map((r: any) => r.column_name);
|
|
124
|
-
expect(cols).toEqual(['provider', 'id']);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('should verify anon access to identities based on rls', async () => {
|
|
129
|
-
// get rls status
|
|
130
|
-
db.setContext({ role: 'service_role' });
|
|
131
|
-
const rlsStatus = await db.any(
|
|
132
|
-
`SELECT c.relrowsecurity
|
|
133
|
-
FROM pg_class c
|
|
134
|
-
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
135
|
-
WHERE n.nspname = 'auth' AND c.relname = 'identities'`
|
|
136
|
-
);
|
|
137
|
-
expect(Array.isArray(rlsStatus)).toBe(true);
|
|
138
|
-
expect(rlsStatus.length).toBeGreaterThan(0);
|
|
139
|
-
|
|
140
|
-
// query as anon
|
|
141
|
-
db.clearContext();
|
|
142
|
-
const result = await db.any(`SELECT * FROM auth.identities LIMIT 1`);
|
|
143
|
-
expect(Array.isArray(result)).toBe(true);
|
|
144
|
-
if (rlsStatus[0].relrowsecurity === true) {
|
|
145
|
-
expect(result.length).toBe(0);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
|
|
@@ -1,134 +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
|
-
// grant access to auth schema for testing
|
|
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 auth.instances 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 = 'instances'
|
|
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 instances table access', () => {
|
|
54
|
-
|
|
55
|
-
it('should verify instances table exists', async () => {
|
|
56
|
-
db.setContext({ role: 'service_role' });
|
|
57
|
-
|
|
58
|
-
const exists = await db.any(
|
|
59
|
-
`SELECT EXISTS (
|
|
60
|
-
SELECT FROM information_schema.tables
|
|
61
|
-
WHERE table_schema = 'auth' AND table_name = 'instances'
|
|
62
|
-
) as exists`
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
expect(Array.isArray(exists)).toBe(true);
|
|
66
|
-
expect(exists[0].exists).toBe(true);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should verify service_role can read instances', async () => {
|
|
70
|
-
db.setContext({ role: 'service_role' });
|
|
71
|
-
|
|
72
|
-
const instances = await db.any(
|
|
73
|
-
`SELECT id, uuid, created_at, updated_at
|
|
74
|
-
FROM auth.instances
|
|
75
|
-
LIMIT 10`
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
expect(Array.isArray(instances)).toBe(true);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should verify table has primary key on id', async () => {
|
|
82
|
-
db.setContext({ role: 'service_role' });
|
|
83
|
-
|
|
84
|
-
const pk = await db.any(
|
|
85
|
-
`SELECT constraint_name
|
|
86
|
-
FROM information_schema.table_constraints
|
|
87
|
-
WHERE table_schema = 'auth' AND table_name = 'instances'
|
|
88
|
-
AND constraint_type = 'PRIMARY KEY'`
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
expect(Array.isArray(pk)).toBe(true);
|
|
92
|
-
if (pk.length > 0) {
|
|
93
|
-
expect(pk[0].constraint_name).toBeDefined();
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should verify table columns match schema', async () => {
|
|
98
|
-
db.setContext({ role: 'service_role' });
|
|
99
|
-
|
|
100
|
-
const columns = await db.any(
|
|
101
|
-
`SELECT column_name
|
|
102
|
-
FROM information_schema.columns
|
|
103
|
-
WHERE table_schema = 'auth' AND table_name = 'instances'
|
|
104
|
-
AND column_name IN ('id', 'uuid', 'raw_base_config', 'created_at', 'updated_at')
|
|
105
|
-
ORDER BY column_name`
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
expect(Array.isArray(columns)).toBe(true);
|
|
109
|
-
const names = columns.map((c: any) => c.column_name);
|
|
110
|
-
expect(names).toEqual(['created_at','id','raw_base_config','updated_at','uuid']);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should verify anon access to instances based on rls', async () => {
|
|
114
|
-
// check rls status for instances
|
|
115
|
-
db.setContext({ role: 'service_role' });
|
|
116
|
-
const rlsStatus = await db.any(
|
|
117
|
-
`SELECT c.relrowsecurity
|
|
118
|
-
FROM pg_class c
|
|
119
|
-
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
120
|
-
WHERE n.nspname = 'auth' AND c.relname = 'instances'`
|
|
121
|
-
);
|
|
122
|
-
expect(Array.isArray(rlsStatus)).toBe(true);
|
|
123
|
-
expect(rlsStatus.length).toBeGreaterThan(0);
|
|
124
|
-
|
|
125
|
-
// query as anon
|
|
126
|
-
db.clearContext();
|
|
127
|
-
const result = await db.any(`SELECT * FROM auth.instances LIMIT 1`);
|
|
128
|
-
expect(Array.isArray(result)).toBe(true);
|
|
129
|
-
if (rlsStatus[0].relrowsecurity === true) {
|
|
130
|
-
expect(result.length).toBe(0);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|