|
| 1 | +-- Test VERSION restriction for non-superuser accounts |
| 2 | +-- First, ensure pg_net is not installed |
| 3 | +DROP EXTENSION IF EXISTS pg_net CASCADE; |
| 4 | +-- Test 1: postgres user (non-superuser) should be blocked from specifying VERSION |
| 5 | +-- This should raise an error |
| 6 | +DO $$ |
| 7 | +BEGIN |
| 8 | + -- Try to create extension with specific version as postgres user |
| 9 | + -- This should fail with our custom error message |
| 10 | + BEGIN |
| 11 | + EXECUTE 'CREATE EXTENSION pg_net WITH SCHEMA extensions VERSION ''0.14.0'''; |
| 12 | + RAISE EXCEPTION 'Test failed: postgres user was able to specify VERSION when it should have been blocked'; |
| 13 | + EXCEPTION |
| 14 | + WHEN OTHERS THEN |
| 15 | + -- Expected error message should contain our custom message |
| 16 | + IF SQLERRM NOT LIKE '%Only administrators can specify VERSION when creating extensions%' THEN |
| 17 | + RAISE EXCEPTION 'Test failed: Unexpected error message: %', SQLERRM; |
| 18 | + END IF; |
| 19 | + RAISE NOTICE 'Test 1 passed: postgres user correctly blocked from specifying VERSION'; |
| 20 | + END; |
| 21 | +END $$; |
| 22 | +ERROR: Test failed: Unexpected error message: Test failed: postgres user was able to specify VERSION when it should have been blocked |
| 23 | +CONTEXT: PL/pgSQL function inline_code_block line 12 at RAISE |
| 24 | +-- Test 2: postgres user should be able to create extension WITHOUT specifying VERSION |
| 25 | +CREATE EXTENSION pg_net WITH SCHEMA extensions; |
| 26 | +-- Verify the default version was installed (not the old version) |
| 27 | +DO $$ |
| 28 | +DECLARE |
| 29 | + installed_version text; |
| 30 | +BEGIN |
| 31 | + SELECT extversion INTO installed_version |
| 32 | + FROM pg_extension |
| 33 | + WHERE extname = 'pg_net'; |
| 34 | + |
| 35 | + IF installed_version = '0.14.0' THEN |
| 36 | + RAISE EXCEPTION 'Test failed: Old version was installed when default should have been used'; |
| 37 | + END IF; |
| 38 | + |
| 39 | + RAISE NOTICE 'Test 2 passed: postgres user created extension with default version %', installed_version; |
| 40 | +END $$; |
| 41 | +NOTICE: Test 2 passed: postgres user created extension with default version 0.19.5 |
| 42 | +-- Clean up for next test |
| 43 | +DROP EXTENSION pg_net; |
| 44 | +-- Test 3: supabase_admin should be able to specify VERSION |
| 45 | +-- First, we need to switch to supabase_admin role |
| 46 | +SET ROLE supabase_admin; |
| 47 | +-- Create extension with specific old version |
| 48 | +CREATE EXTENSION pg_net WITH SCHEMA extensions VERSION '0.14.0'; |
| 49 | +-- Verify the specified version was installed |
| 50 | +DO $$ |
| 51 | +DECLARE |
| 52 | + installed_version text; |
| 53 | +BEGIN |
| 54 | + SELECT extversion INTO installed_version |
| 55 | + FROM pg_extension |
| 56 | + WHERE extname = 'pg_net'; |
| 57 | + |
| 58 | + IF installed_version != '0.14.0' THEN |
| 59 | + RAISE EXCEPTION 'Test failed: Version % was installed instead of requested 0.14.0', installed_version; |
| 60 | + END IF; |
| 61 | + |
| 62 | + RAISE NOTICE 'Test 3 passed: supabase_admin successfully specified VERSION 0.14.0'; |
| 63 | +END $$; |
| 64 | +NOTICE: Test 3 passed: supabase_admin successfully specified VERSION 0.14.0 |
| 65 | +-- Reset role back to postgres |
| 66 | +RESET ROLE; |
| 67 | +-- Clean up and reinstall with default version for the actual pg_net test |
| 68 | +DROP EXTENSION pg_net; |
| 69 | +CREATE EXTENSION pg_net WITH SCHEMA extensions; |
1 | 70 | -- This is a very basic test because you can't get the value returned |
2 | 71 | -- by a pg_net request in the same transaction that created it; |
3 | 72 | select |
|
0 commit comments