@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,145 +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
|
-
|
|
9
|
-
|
|
10
|
-
({ pg, db, teardown } = await getConnections());
|
|
11
|
-
|
|
12
|
-
// verify auth schema exists
|
|
13
|
-
const authSchemaExists = await pg.any(
|
|
14
|
-
`SELECT EXISTS (
|
|
15
|
-
SELECT FROM information_schema.schemata
|
|
16
|
-
WHERE schema_name = 'auth'
|
|
17
|
-
) as exists`
|
|
18
|
-
);
|
|
19
|
-
expect(authSchemaExists[0].exists).toBe(true);
|
|
20
|
-
|
|
21
|
-
// grant access to auth schema for testing
|
|
22
|
-
await pg.any(
|
|
23
|
-
`GRANT USAGE ON SCHEMA auth TO public;
|
|
24
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO service_role;
|
|
25
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO authenticated;
|
|
26
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO anon;
|
|
27
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO service_role;
|
|
28
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO authenticated;
|
|
29
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO anon;`,
|
|
30
|
-
[]
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
// assert table exists
|
|
34
|
-
const exists = await pg.any(
|
|
35
|
-
`SELECT EXISTS (
|
|
36
|
-
SELECT FROM information_schema.tables
|
|
37
|
-
WHERE table_schema = 'auth' AND table_name = 'saml_relay_states'
|
|
38
|
-
) as exists`
|
|
39
|
-
);
|
|
40
|
-
expect(exists[0].exists).toBe(true);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
afterAll(async () => {
|
|
44
|
-
await teardown();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
beforeEach(async () => {
|
|
48
|
-
await db.beforeEach();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
afterEach(async () => {
|
|
52
|
-
await db.afterEach();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('tutorial: auth saml_relay_states table access', () => {
|
|
56
|
-
|
|
57
|
-
it('should verify saml_relay_states table exists', async () => {
|
|
58
|
-
db.setContext({ role: 'service_role' });
|
|
59
|
-
|
|
60
|
-
// verify table exists in information schema
|
|
61
|
-
const exists = await db.any(
|
|
62
|
-
`SELECT EXISTS (
|
|
63
|
-
SELECT FROM information_schema.tables
|
|
64
|
-
WHERE table_schema = 'auth' AND table_name = 'saml_relay_states'
|
|
65
|
-
) as exists`
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
expect(Array.isArray(exists)).toBe(true);
|
|
69
|
-
expect(exists[0].exists).toBe(true);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should verify service_role can query saml_relay_states structure', async () => {
|
|
73
|
-
db.setContext({ role: 'service_role' });
|
|
74
|
-
|
|
75
|
-
// query table column structure
|
|
76
|
-
const columns = await db.any(
|
|
77
|
-
`SELECT column_name, data_type
|
|
78
|
-
FROM information_schema.columns
|
|
79
|
-
WHERE table_schema = 'auth' AND table_name = 'saml_relay_states'
|
|
80
|
-
ORDER BY ordinal_position`
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
expect(Array.isArray(columns)).toBe(true);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should verify table has created_at timestamp column', async () => {
|
|
87
|
-
db.setContext({ role: 'service_role' });
|
|
88
|
-
|
|
89
|
-
// check for timestamp columns like created_at or expires_at
|
|
90
|
-
const timestampCols = await db.any(
|
|
91
|
-
`SELECT column_name
|
|
92
|
-
FROM information_schema.columns
|
|
93
|
-
WHERE table_schema = 'auth' AND table_name = 'saml_relay_states'
|
|
94
|
-
AND (column_name LIKE '%created_at%' OR column_name LIKE '%expires_at%')`
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
expect(Array.isArray(timestampCols)).toBe(true);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('should verify foreign key to sso_providers and indexes', async () => {
|
|
101
|
-
db.setContext({ role: 'service_role' });
|
|
102
|
-
const fks = await db.any(
|
|
103
|
-
`SELECT tc.constraint_name, ccu.table_name AS foreign_table_name
|
|
104
|
-
FROM information_schema.table_constraints AS tc
|
|
105
|
-
JOIN information_schema.constraint_column_usage AS ccu
|
|
106
|
-
ON ccu.constraint_name = tc.constraint_name
|
|
107
|
-
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
108
|
-
AND tc.table_schema = 'auth'
|
|
109
|
-
AND tc.table_name = 'saml_relay_states'
|
|
110
|
-
AND ccu.table_name = 'sso_providers'`
|
|
111
|
-
);
|
|
112
|
-
expect(Array.isArray(fks)).toBe(true);
|
|
113
|
-
const idx = await db.any(
|
|
114
|
-
`SELECT indexname, indexdef
|
|
115
|
-
FROM pg_indexes
|
|
116
|
-
WHERE schemaname = 'auth' AND tablename = 'saml_relay_states'`
|
|
117
|
-
);
|
|
118
|
-
expect(Array.isArray(idx)).toBe(true);
|
|
119
|
-
if (idx.length > 0) {
|
|
120
|
-
const defs = idx.map((r: any) => r.indexdef).join(' ');
|
|
121
|
-
expect(defs.toLowerCase().includes('sso_provider_id')).toBe(true);
|
|
122
|
-
expect(defs.toLowerCase().includes('for_email')).toBe(true);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('should verify anon access to saml_relay_states based on rls', async () => {
|
|
127
|
-
db.setContext({ role: 'service_role' });
|
|
128
|
-
const rlsStatus = await db.any(
|
|
129
|
-
`SELECT c.relrowsecurity
|
|
130
|
-
FROM pg_class c
|
|
131
|
-
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
132
|
-
WHERE n.nspname = 'auth' AND c.relname = 'saml_relay_states'`
|
|
133
|
-
);
|
|
134
|
-
expect(Array.isArray(rlsStatus)).toBe(true);
|
|
135
|
-
expect(rlsStatus.length).toBeGreaterThan(0);
|
|
136
|
-
|
|
137
|
-
db.clearContext();
|
|
138
|
-
const result = await db.any(`SELECT * FROM auth.saml_relay_states LIMIT 1`);
|
|
139
|
-
expect(Array.isArray(result)).toBe(true);
|
|
140
|
-
if (rlsStatus[0].relrowsecurity === true) {
|
|
141
|
-
expect(result.length).toBe(0);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
@@ -1,131 +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
|
-
|
|
11
|
-
|
|
12
|
-
({ pg, db, teardown } = await getConnections());
|
|
13
|
-
|
|
14
|
-
// verify auth schema exists
|
|
15
|
-
const authSchemaExists = await pg.any(
|
|
16
|
-
`SELECT EXISTS (
|
|
17
|
-
SELECT FROM information_schema.schemata
|
|
18
|
-
WHERE schema_name = 'auth'
|
|
19
|
-
) as exists`
|
|
20
|
-
);
|
|
21
|
-
expect(authSchemaExists[0].exists).toBe(true);
|
|
22
|
-
|
|
23
|
-
// grant access to auth schema for testing
|
|
24
|
-
await pg.any(
|
|
25
|
-
`GRANT USAGE ON SCHEMA auth TO public;
|
|
26
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO service_role;
|
|
27
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO authenticated;
|
|
28
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO anon;
|
|
29
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO service_role;
|
|
30
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO authenticated;
|
|
31
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO anon;`,
|
|
32
|
-
[]
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
// check if auth.schema_migrations table exists (using pg in beforeAll only)
|
|
36
|
-
const exists = await pg.any(
|
|
37
|
-
`SELECT EXISTS (
|
|
38
|
-
SELECT FROM information_schema.tables
|
|
39
|
-
WHERE table_schema = 'auth' AND table_name = 'schema_migrations'
|
|
40
|
-
) as exists`
|
|
41
|
-
);
|
|
42
|
-
tableExists = exists[0]?.exists === true;
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
afterAll(async () => {
|
|
46
|
-
await teardown();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
beforeEach(async () => {
|
|
50
|
-
await db.beforeEach();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
afterEach(async () => {
|
|
54
|
-
await db.afterEach();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('tutorial: auth schema_migrations table access', () => {
|
|
58
|
-
|
|
59
|
-
it('should verify schema_migrations table exists', async () => {
|
|
60
|
-
db.setContext({ role: 'service_role' });
|
|
61
|
-
|
|
62
|
-
// verify table exists in information schema
|
|
63
|
-
const exists = await db.any(
|
|
64
|
-
`SELECT EXISTS (
|
|
65
|
-
SELECT FROM information_schema.tables
|
|
66
|
-
WHERE table_schema = 'auth' AND table_name = 'schema_migrations'
|
|
67
|
-
) as exists`
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
expect(Array.isArray(exists)).toBe(true);
|
|
71
|
-
if (exists[0]?.exists === false) {
|
|
72
|
-
expect(exists[0].exists).toBe(false);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
expect(exists[0].exists).toBe(true);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should verify service_role can read migration versions', async () => {
|
|
79
|
-
if (!tableExists) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
db.setContext({ role: 'service_role' });
|
|
84
|
-
|
|
85
|
-
// service_role should be able to query migration versions
|
|
86
|
-
const migrations = await db.any(
|
|
87
|
-
`SELECT version FROM auth.schema_migrations ORDER BY version`
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
expect(Array.isArray(migrations)).toBe(true);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should verify table has primary key on version', async () => {
|
|
94
|
-
if (!tableExists) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
db.setContext({ role: 'service_role' });
|
|
99
|
-
|
|
100
|
-
// check for primary key constraint
|
|
101
|
-
const pk = await db.any(
|
|
102
|
-
`SELECT constraint_name
|
|
103
|
-
FROM information_schema.table_constraints
|
|
104
|
-
WHERE table_schema = 'auth' AND table_name = 'schema_migrations'
|
|
105
|
-
AND constraint_type = 'PRIMARY KEY'`
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
expect(Array.isArray(pk)).toBe(true);
|
|
109
|
-
if (pk.length > 0) {
|
|
110
|
-
expect(pk[0].constraint_name).toBeDefined();
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should prevent anon from accessing schema_migrations', async () => {
|
|
115
|
-
if (!tableExists) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// clear context to anon role
|
|
120
|
-
db.clearContext();
|
|
121
|
-
|
|
122
|
-
// anon should not be able to access schema_migrations (rls blocks)
|
|
123
|
-
const result = await db.any(
|
|
124
|
-
`SELECT * FROM auth.schema_migrations LIMIT 1`
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
// rls should block access, result should be empty
|
|
128
|
-
expect(result.length).toBe(0);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
@@ -1,140 +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
|
-
|
|
11
|
-
|
|
12
|
-
({ pg, db, teardown } = await getConnections());
|
|
13
|
-
|
|
14
|
-
// verify auth schema exists
|
|
15
|
-
const authSchemaExists = await pg.any(
|
|
16
|
-
`SELECT EXISTS (
|
|
17
|
-
SELECT FROM information_schema.schemata
|
|
18
|
-
WHERE schema_name = 'auth'
|
|
19
|
-
) as exists`
|
|
20
|
-
);
|
|
21
|
-
expect(authSchemaExists[0].exists).toBe(true);
|
|
22
|
-
|
|
23
|
-
// grant access to auth schema for testing
|
|
24
|
-
await pg.any(
|
|
25
|
-
`GRANT USAGE ON SCHEMA auth TO public;
|
|
26
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO service_role;
|
|
27
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO authenticated;
|
|
28
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO anon;
|
|
29
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO service_role;
|
|
30
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO authenticated;
|
|
31
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO anon;`,
|
|
32
|
-
[]
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
// check if auth.sessions table exists (using pg in beforeAll only)
|
|
36
|
-
const exists = await pg.any(
|
|
37
|
-
`SELECT EXISTS (
|
|
38
|
-
SELECT FROM information_schema.tables
|
|
39
|
-
WHERE table_schema = 'auth' AND table_name = 'sessions'
|
|
40
|
-
) as exists`
|
|
41
|
-
);
|
|
42
|
-
tableExists = exists[0]?.exists === true;
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
afterAll(async () => {
|
|
46
|
-
await teardown();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
beforeEach(async () => {
|
|
50
|
-
await db.beforeEach();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
afterEach(async () => {
|
|
54
|
-
await db.afterEach();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('tutorial: auth sessions table access', () => {
|
|
58
|
-
|
|
59
|
-
it('should verify sessions table exists', async () => {
|
|
60
|
-
db.setContext({ role: 'service_role' });
|
|
61
|
-
|
|
62
|
-
const exists = await db.any(
|
|
63
|
-
`SELECT EXISTS (
|
|
64
|
-
SELECT FROM information_schema.tables
|
|
65
|
-
WHERE table_schema = 'auth' AND table_name = 'sessions'
|
|
66
|
-
) as exists`
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
expect(Array.isArray(exists)).toBe(true);
|
|
70
|
-
if (exists[0]?.exists === false) {
|
|
71
|
-
// table doesn't exist in this supabase setup, skip test
|
|
72
|
-
expect(exists[0].exists).toBe(false);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
expect(exists[0].exists).toBe(true);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should verify service_role can read sessions', async () => {
|
|
79
|
-
db.setContext({ role: 'service_role' });
|
|
80
|
-
|
|
81
|
-
const sessions = await db.any(
|
|
82
|
-
`SELECT id, user_id, created_at, updated_at
|
|
83
|
-
FROM auth.sessions
|
|
84
|
-
LIMIT 10`
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
expect(Array.isArray(sessions)).toBe(true);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should verify table has foreign key to auth.users', async () => {
|
|
91
|
-
db.setContext({ role: 'service_role' });
|
|
92
|
-
|
|
93
|
-
const fks = await db.any(
|
|
94
|
-
`SELECT tc.constraint_name, ccu.table_name AS foreign_table_name
|
|
95
|
-
FROM information_schema.table_constraints AS tc
|
|
96
|
-
JOIN information_schema.constraint_column_usage AS ccu
|
|
97
|
-
ON ccu.constraint_name = tc.constraint_name
|
|
98
|
-
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
99
|
-
AND tc.table_schema = 'auth'
|
|
100
|
-
AND tc.table_name = 'sessions'
|
|
101
|
-
AND ccu.table_name = 'users'`
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
expect(Array.isArray(fks)).toBe(true);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should verify table has index on user_id', async () => {
|
|
108
|
-
db.setContext({ role: 'service_role' });
|
|
109
|
-
|
|
110
|
-
const indexes = await db.any(
|
|
111
|
-
`SELECT indexname
|
|
112
|
-
FROM pg_indexes
|
|
113
|
-
WHERE schemaname = 'auth' AND tablename = 'sessions'
|
|
114
|
-
AND indexname LIKE '%user_id%'`
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
expect(Array.isArray(indexes)).toBe(true);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should verify anon access to sessions based on rls', async () => {
|
|
121
|
-
// check rls status
|
|
122
|
-
db.setContext({ role: 'service_role' });
|
|
123
|
-
const rlsStatus = await db.any(
|
|
124
|
-
`SELECT c.relrowsecurity
|
|
125
|
-
FROM pg_class c
|
|
126
|
-
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
127
|
-
WHERE n.nspname = 'auth' AND c.relname = 'sessions'`
|
|
128
|
-
);
|
|
129
|
-
expect(Array.isArray(rlsStatus)).toBe(true);
|
|
130
|
-
expect(rlsStatus.length).toBeGreaterThan(0);
|
|
131
|
-
|
|
132
|
-
db.clearContext();
|
|
133
|
-
const result = await db.any(`SELECT * FROM auth.sessions LIMIT 1`);
|
|
134
|
-
expect(Array.isArray(result)).toBe(true);
|
|
135
|
-
if (rlsStatus[0].relrowsecurity === true) {
|
|
136
|
-
expect(result.length).toBe(0);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
@@ -1,137 +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
|
-
|
|
9
|
-
|
|
10
|
-
({ pg, db, teardown } = await getConnections());
|
|
11
|
-
|
|
12
|
-
// verify auth schema exists
|
|
13
|
-
const authSchemaExists = await pg.any(
|
|
14
|
-
`SELECT EXISTS (
|
|
15
|
-
SELECT FROM information_schema.schemata
|
|
16
|
-
WHERE schema_name = 'auth'
|
|
17
|
-
) as exists`
|
|
18
|
-
);
|
|
19
|
-
expect(authSchemaExists[0].exists).toBe(true);
|
|
20
|
-
|
|
21
|
-
// grant access to auth schema for testing
|
|
22
|
-
await pg.any(
|
|
23
|
-
`GRANT USAGE ON SCHEMA auth TO public;
|
|
24
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO service_role;
|
|
25
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO authenticated;
|
|
26
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO anon;
|
|
27
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO service_role;
|
|
28
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO authenticated;
|
|
29
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO anon;`,
|
|
30
|
-
[]
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
// assert table exists
|
|
34
|
-
const exists = await pg.any(
|
|
35
|
-
`SELECT EXISTS (
|
|
36
|
-
SELECT FROM information_schema.tables
|
|
37
|
-
WHERE table_schema = 'auth' AND table_name = 'sso_domains'
|
|
38
|
-
) as exists`
|
|
39
|
-
);
|
|
40
|
-
expect(exists[0].exists).toBe(true);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
afterAll(async () => {
|
|
44
|
-
await teardown();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
beforeEach(async () => {
|
|
48
|
-
await db.beforeEach();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
afterEach(async () => {
|
|
52
|
-
await db.afterEach();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('tutorial: auth sso_domains table access', () => {
|
|
56
|
-
|
|
57
|
-
it('should verify sso_domains table exists', async () => {
|
|
58
|
-
db.setContext({ role: 'service_role' });
|
|
59
|
-
|
|
60
|
-
// verify table exists in information schema
|
|
61
|
-
const exists = await db.any(
|
|
62
|
-
`SELECT EXISTS (
|
|
63
|
-
SELECT FROM information_schema.tables
|
|
64
|
-
WHERE table_schema = 'auth' AND table_name = 'sso_domains'
|
|
65
|
-
) as exists`
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
expect(Array.isArray(exists)).toBe(true);
|
|
69
|
-
expect(exists[0].exists).toBe(true);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should verify service_role can query sso_domains', async () => {
|
|
73
|
-
db.setContext({ role: 'service_role' });
|
|
74
|
-
|
|
75
|
-
// service_role should be able to query sso_domains
|
|
76
|
-
const domains = await db.any(
|
|
77
|
-
`SELECT id, sso_provider_id, domain, created_at, updated_at
|
|
78
|
-
FROM auth.sso_domains
|
|
79
|
-
LIMIT 10`
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
expect(Array.isArray(domains)).toBe(true);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should verify table has foreign key to sso_providers', async () => {
|
|
86
|
-
db.setContext({ role: 'service_role' });
|
|
87
|
-
|
|
88
|
-
// check for foreign key constraints to sso_providers
|
|
89
|
-
const fks = await db.any(
|
|
90
|
-
`SELECT tc.constraint_name, ccu.table_name AS foreign_table_name
|
|
91
|
-
FROM information_schema.table_constraints AS tc
|
|
92
|
-
JOIN information_schema.constraint_column_usage AS ccu
|
|
93
|
-
ON ccu.constraint_name = tc.constraint_name
|
|
94
|
-
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
95
|
-
AND tc.table_schema = 'auth'
|
|
96
|
-
AND tc.table_name = 'sso_domains'
|
|
97
|
-
AND ccu.table_name = 'sso_providers'`
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
expect(Array.isArray(fks)).toBe(true);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should verify indexes exist on sso_provider_id and unique lower(domain)', async () => {
|
|
104
|
-
db.setContext({ role: 'service_role' });
|
|
105
|
-
const idx = await db.any(
|
|
106
|
-
`SELECT indexname, indexdef
|
|
107
|
-
FROM pg_indexes
|
|
108
|
-
WHERE schemaname = 'auth' AND tablename = 'sso_domains'`
|
|
109
|
-
);
|
|
110
|
-
expect(Array.isArray(idx)).toBe(true);
|
|
111
|
-
if (idx.length > 0) {
|
|
112
|
-
const defs = idx.map((r: any) => r.indexdef).join(' ');
|
|
113
|
-
expect(defs.toLowerCase().includes('sso_provider_id')).toBe(true);
|
|
114
|
-
expect(defs.toLowerCase().includes('lower(domain)')).toBe(true);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('should verify anon access to sso_domains based on rls', async () => {
|
|
119
|
-
db.setContext({ role: 'service_role' });
|
|
120
|
-
const rlsStatus = await db.any(
|
|
121
|
-
`SELECT c.relrowsecurity
|
|
122
|
-
FROM pg_class c
|
|
123
|
-
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
124
|
-
WHERE n.nspname = 'auth' AND c.relname = 'sso_domains'`
|
|
125
|
-
);
|
|
126
|
-
expect(Array.isArray(rlsStatus)).toBe(true);
|
|
127
|
-
expect(rlsStatus.length).toBeGreaterThan(0);
|
|
128
|
-
|
|
129
|
-
db.clearContext();
|
|
130
|
-
const result = await db.any(`SELECT * FROM auth.sso_domains LIMIT 1`);
|
|
131
|
-
expect(Array.isArray(result)).toBe(true);
|
|
132
|
-
if (rlsStatus[0].relrowsecurity === true) {
|
|
133
|
-
expect(result.length).toBe(0);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
@@ -1,136 +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
|
-
|
|
9
|
-
|
|
10
|
-
({ pg, db, teardown } = await getConnections());
|
|
11
|
-
|
|
12
|
-
// verify auth schema exists
|
|
13
|
-
const authSchemaExists = await pg.any(
|
|
14
|
-
`SELECT EXISTS (
|
|
15
|
-
SELECT FROM information_schema.schemata
|
|
16
|
-
WHERE schema_name = 'auth'
|
|
17
|
-
) as exists`
|
|
18
|
-
);
|
|
19
|
-
expect(authSchemaExists[0].exists).toBe(true);
|
|
20
|
-
|
|
21
|
-
// grant access to auth schema for testing
|
|
22
|
-
await pg.any(
|
|
23
|
-
`GRANT USAGE ON SCHEMA auth TO public;
|
|
24
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO service_role;
|
|
25
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO authenticated;
|
|
26
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA auth TO anon;
|
|
27
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO service_role;
|
|
28
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO authenticated;
|
|
29
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA auth GRANT SELECT ON TABLES TO anon;`,
|
|
30
|
-
[]
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
// assert table exists
|
|
34
|
-
const exists = await pg.any(
|
|
35
|
-
`SELECT EXISTS (
|
|
36
|
-
SELECT FROM information_schema.tables
|
|
37
|
-
WHERE table_schema = 'auth' AND table_name = 'sso_providers'
|
|
38
|
-
) as exists`
|
|
39
|
-
);
|
|
40
|
-
expect(exists[0].exists).toBe(true);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
afterAll(async () => {
|
|
44
|
-
await teardown();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
beforeEach(async () => {
|
|
48
|
-
await db.beforeEach();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
afterEach(async () => {
|
|
52
|
-
await db.afterEach();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('tutorial: auth sso_providers table access', () => {
|
|
56
|
-
|
|
57
|
-
it('should verify sso_providers table exists', async () => {
|
|
58
|
-
db.setContext({ role: 'service_role' });
|
|
59
|
-
|
|
60
|
-
// verify table exists in information schema
|
|
61
|
-
const exists = await db.any(
|
|
62
|
-
`SELECT EXISTS (
|
|
63
|
-
SELECT FROM information_schema.tables
|
|
64
|
-
WHERE table_schema = 'auth' AND table_name = 'sso_providers'
|
|
65
|
-
) as exists`
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
expect(Array.isArray(exists)).toBe(true);
|
|
69
|
-
expect(exists[0].exists).toBe(true);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should verify service_role can read sso_providers', async () => {
|
|
73
|
-
db.setContext({ role: 'service_role' });
|
|
74
|
-
|
|
75
|
-
// service_role should be able to query sso_providers
|
|
76
|
-
const providers = await db.any(
|
|
77
|
-
`SELECT id, resource_id, created_at, updated_at
|
|
78
|
-
FROM auth.sso_providers
|
|
79
|
-
LIMIT 10`
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
expect(Array.isArray(providers)).toBe(true);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should verify table has primary key on id', async () => {
|
|
86
|
-
db.setContext({ role: 'service_role' });
|
|
87
|
-
|
|
88
|
-
// check for primary key constraint
|
|
89
|
-
const pk = await db.any(
|
|
90
|
-
`SELECT constraint_name
|
|
91
|
-
FROM information_schema.table_constraints
|
|
92
|
-
WHERE table_schema = 'auth' AND table_name = 'sso_providers'
|
|
93
|
-
AND constraint_type = 'PRIMARY KEY'`
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
expect(Array.isArray(pk)).toBe(true);
|
|
97
|
-
if (pk.length > 0) {
|
|
98
|
-
expect(pk[0].constraint_name).toBeDefined();
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should verify unique index on lower(resource_id) exists', async () => {
|
|
103
|
-
db.setContext({ role: 'service_role' });
|
|
104
|
-
// check for functional unique index on lower(resource_id)
|
|
105
|
-
const idx = await db.any(
|
|
106
|
-
`SELECT indexname, indexdef
|
|
107
|
-
FROM pg_indexes
|
|
108
|
-
WHERE schemaname = 'auth' AND tablename = 'sso_providers'
|
|
109
|
-
AND indexdef ILIKE '%lower(resource_id)%'`
|
|
110
|
-
);
|
|
111
|
-
expect(Array.isArray(idx)).toBe(true);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should verify anon access to sso_providers based on rls', async () => {
|
|
115
|
-
// check rls status
|
|
116
|
-
db.setContext({ role: 'service_role' });
|
|
117
|
-
const rlsStatus = await db.any(
|
|
118
|
-
`SELECT c.relrowsecurity
|
|
119
|
-
FROM pg_class c
|
|
120
|
-
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
121
|
-
WHERE n.nspname = 'auth' AND c.relname = 'sso_providers'`
|
|
122
|
-
);
|
|
123
|
-
expect(Array.isArray(rlsStatus)).toBe(true);
|
|
124
|
-
expect(rlsStatus.length).toBeGreaterThan(0);
|
|
125
|
-
|
|
126
|
-
// clear context to anon role
|
|
127
|
-
db.clearContext();
|
|
128
|
-
|
|
129
|
-
const result = await db.any(`SELECT * FROM auth.sso_providers LIMIT 1`);
|
|
130
|
-
expect(Array.isArray(result)).toBe(true);
|
|
131
|
-
if (rlsStatus[0].relrowsecurity === true) {
|
|
132
|
-
expect(result.length).toBe(0);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|