-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for authenticate_as_service_role (#13)
- Loading branch information
Showing
10 changed files
with
151 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.idea | ||
.idea | ||
.DS_Store | ||
supabase_test_helpers_pglet.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION | ||
\echo Use "CREATE EXTENSION supabase_test_helpers" to load this file. \quit | ||
|
||
/** | ||
* ### tests.authenticate_as_service_role() | ||
* Clears authentication object and sets role to service_role. | ||
* | ||
* Returns: | ||
* - `void` | ||
* | ||
* Example: | ||
* ```sql | ||
* SELECT tests.authenticate_as_service_role(); | ||
* ``` | ||
*/ | ||
CREATE OR REPLACE FUNCTION tests.authenticate_as_service_role () | ||
RETURNS void | ||
AS $$ | ||
BEGIN | ||
perform set_config('role', 'service_role', true); | ||
perform set_config('request.jwt.claims', null, true); | ||
END | ||
$$ LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
default_version = 0.0.2 | ||
comment = 'A collection of functions designed to make testing Supabase projects easier' | ||
relocatable = false | ||
requires = pgtap | ||
superuser = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
BEGIN; | ||
CREATE EXTENSION supabase_test_helpers; | ||
|
||
select plan(8); | ||
|
||
select tests.create_supabase_user('test'); | ||
|
||
select lives_ok($$ select tests.authenticate_as('test') $$, 'Successfully authenticated as test user'); | ||
select is((select tests.get_supabase_uid('test')), auth.uid(), 'Authenticates as the correct user'); | ||
select is((select current_role::text), 'authenticated', 'Sets the current role to authenticated'); | ||
|
||
select tests.authenticate_as_service_role(); | ||
|
||
select is((select current_role::text), 'service_role', 'Sets the current role to service_role'); | ||
select is((select auth.uid()), null, 'Clears out authentication'); | ||
|
||
select lives_ok($$ select tests.authenticate_as('test') $$, 'Successfully authenticated as test user'); | ||
select is((select tests.get_supabase_uid('test')), auth.uid(), 'Authenticates as the correct user'); | ||
select is((select current_role::text), 'authenticated', 'Sets the current role to authenticated'); | ||
|
||
|
||
|
||
select * from finish(); | ||
ROLLBACK; |
File renamed without changes.