Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions migrations/tests/storage/exists.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

-- Sanity test object existence in storage schema
--
-- Storage tables and functions (storage.buckets, storage.objects, ...) are
-- created by the Storage service's own migrations, not by this repo (#1911).
-- We only create the schema and the role Storage connects as.

select has_table('storage'::name, 'buckets'::name);
select has_table('storage'::name, 'objects'::name);
select has_table('storage'::name, 'migrations'::name);
select has_function('storage'::name, 'foldername'::name);
select has_function('storage'::name, 'filename'::name);
select has_function('storage'::name, 'extension'::name);
select has_function('storage'::name, 'search'::name);
select has_schema('storage'::name);
select has_role('supabase_storage_admin'::name);

select todo('This test should probably fail.'); select schema_privs_are('storage', 'anon', ARRAY['USAGE']);

12 changes: 11 additions & 1 deletion nix/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,18 @@
log info "CLI variant detected - skipping migrations tests"
else
log info "Running migrations tests"
log_cmd pg_prove -p ${pgPort} -U supabase_admin -h localhost -d postgres -v ${../migrations/tests}/test.sql
if ! log_cmd pg_prove -p ${pgPort} -U supabase_admin -h localhost -d postgres -v ${../migrations/tests}/test.sql; then
log error "Migrations tests failed"
exit 1
fi
log info "Migrations tests completed successfully"

log info "Running smoke tests"
if ! log_cmd pg_prove -p ${pgPort} -U supabase_admin -h localhost -d postgres -v ${./tests/smoke}/*.sql; then
log error "Smoke tests failed"
exit 1
fi
log info "Smoke tests completed successfully"
fi
'';
};
Expand Down
35 changes: 27 additions & 8 deletions nix/tests/smoke/0002-supautils.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
BEGIN;
SELECT plan(2);
SELECT plan(5);

-- the setting doesn't exist when supautils is not loaded
SELECT throws_ok($$
select current_setting('supautils.privileged_extensions', false)
$$);
-- supautils is loaded at session start via session_preload_libraries
SELECT ok(
current_setting('session_preload_libraries') ~ '\msupautils\M',
'supautils is in session_preload_libraries'
);

-- so its settings exist and are populated from supautils.conf
SELECT ok(
coalesce(current_setting('supautils.privileged_extensions', true), '') <> '',
'supautils.privileged_extensions is set and non-empty'
);

LOAD 'supautils';
-- spot-check a few stable entries rather than the whole list
SELECT ok(
string_to_array(replace(current_setting('supautils.privileged_extensions', true), ' ', ''), ',')
@> ARRAY['pg_cron']::text[],
'pg_cron is a privileged extension'
);

SELECT ok(
string_to_array(replace(current_setting('supautils.privileged_extensions', true), ' ', ''), ',')
@> ARRAY['pgsodium']::text[],
'pgsodium is a privileged extension'
);

-- now it does
SELECT ok(
current_setting('supautils.privileged_extensions', false) = ''
string_to_array(replace(current_setting('supautils.privileged_extensions', true), ' ', ''), ',')
@> ARRAY['vector']::text[],
'vector is a privileged extension'
);

SELECT * FROM finish();
Expand Down
16 changes: 12 additions & 4 deletions nix/tests/smoke/0003-pgsodium-vault.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
BEGIN;

select plan(3);
select plan(4);

select id as test_new_key_id from pgsodium.create_key(name:='test_new_key') \gset

select vault.create_secret (
's3kr3t_k3y', 'a_name', 'this is the foo secret key') test_secret_id \gset

-- supabase_vault 0.3.0+ ignores the key id argument (it is kept for backward
-- compatibility): every secret is encrypted with the internal key (key_id 0)
-- and the stored key_id is NULL.
select vault.create_secret (
's3kr3t_k3y_2', 'another_name', 'this is another foo key',
(select id from pgsodium.key where name = 'test_new_key')) test_secret_id_2 \gset
Expand All @@ -17,15 +20,20 @@ SELECT results_eq(
FROM vault.decrypted_secrets WHERE name = 'a_name';
$$,
$$VALUES (true, true)$$,
'can select from masking view with custom key');
'can select from masking view with default key');

SELECT results_eq(
$$
SELECT decrypted_secret = 's3kr3t_k3y_2', description = 'this is another foo key'
FROM vault.decrypted_secrets WHERE key_id = (select id from pgsodium.key where name = 'test_new_key');
FROM vault.decrypted_secrets WHERE name = 'another_name';
$$,
$$VALUES (true, true)$$,
'can select from masking view');
'can select from masking view for a secret created with a key id argument');

SELECT is(
(SELECT key_id FROM vault.secrets WHERE name = 'another_name'),
NULL,
'stored key_id is NULL since the key id argument is unused (vault 0.3.0+)');

SELECT lives_ok(
format($test$
Expand Down
Loading