test(io): move fixtures to fixtures/ directory
Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
(cherry picked from commit 35de13eebd)
This commit is contained in:
committed by
Steve Chavez
parent
c9c617cce1
commit
05074f41c2
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,122 @@
|
||||
CREATE ROLE db_config_authenticator LOGIN NOINHERIT;
|
||||
|
||||
-- reloadable config options
|
||||
-- these settings will override the values in configs/no-defaults.config, so they must be different
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_aggregates_enabled = 'false';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_anon_role = 'anonymous';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_extra_search_path = 'public, extensions';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_max_rows = '500';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_plan_enabled = 'false';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_pre_config = 'postgrest.preconf';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_pre_request = 'test.custom_headers';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_prepared_statements = 'false';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_root_spec = 'root';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_schemas = 'test, tenant1, tenant2';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_tx_end = 'commit-allow-override';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.jwt_aud = 'https://example.org';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.jwt_cache_max_entries = '86400';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.jwt_role_claim_key = '."a"."role"';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.jwt_secret = 'REALLY=REALLY=REALLY=REALLY=VERY=SAFE';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.jwt_secret_is_base64 = 'false';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.not_existing = 'should be ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.openapi_server_proxy_uri = 'https://example.org/api';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.server_cors_allowed_origins = 'http://origin.com';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.server_timing_enabled = 'false';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.server_trace_header = 'CF-Ray';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_hoisted_tx_settings = 'autovacuum_work_mem';
|
||||
|
||||
-- override with database specific setting
|
||||
ALTER ROLE db_config_authenticator IN DATABASE :DBNAME SET pgrst.db_extra_search_path = 'public, extensions, private';
|
||||
ALTER ROLE db_config_authenticator IN DATABASE :DBNAME SET pgrst.jwt_secret = 'OVERRIDE=REALLY=REALLY=REALLY=REALLY=VERY=SAFE';
|
||||
ALTER ROLE db_config_authenticator IN DATABASE :DBNAME SET pgrst.not_existing = 'should be ignored';
|
||||
|
||||
-- other database settings that should be ignored
|
||||
CREATE DATABASE other;
|
||||
ALTER ROLE db_config_authenticator IN DATABASE other SET pgrst.db_max_rows = '1111';
|
||||
|
||||
-- non-reloadable configs
|
||||
ALTER ROLE db_config_authenticator SET pgrst.admin_server_host = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.admin_server_port = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_channel = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_channel_enabled = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_config = 'true';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_pool = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_pool_acquisition_timeout = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_pool_timeout = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_pool_max_idletime = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_pool_max_lifetime = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.db_uri = 'postgresql://ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.log_level = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.log_query = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.server_host = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.server_port = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.server_unix_socket = 'ignored';
|
||||
ALTER ROLE db_config_authenticator SET pgrst.server_unix_socket_mode = 'ignored';
|
||||
|
||||
-- other authenticator reloadable config options
|
||||
-- these settings will override the values in configs/no-defaults.config, so they must be different
|
||||
CREATE ROLE other_authenticator LOGIN NOINHERIT;
|
||||
ALTER ROLE other_authenticator SET pgrst.db_aggregates_enabled = 'false';
|
||||
ALTER ROLE other_authenticator SET pgrst.db_extra_search_path = 'public, extensions, other';
|
||||
ALTER ROLE other_authenticator SET pgrst.db_max_rows = '100';
|
||||
ALTER ROLE other_authenticator SET pgrst.db_plan_enabled = 'true';
|
||||
ALTER ROLE other_authenticator SET pgrst.db_pre_config = 'postgrest.other_preconf';
|
||||
ALTER ROLE other_authenticator SET pgrst.db_pre_request = 'test.other_custom_headers';
|
||||
ALTER ROLE other_authenticator SET pgrst.db_prepared_statements = 'false';
|
||||
ALTER ROLE other_authenticator SET pgrst.db_root_spec = 'other_root';
|
||||
ALTER ROLE other_authenticator SET pgrst.db_schemas = 'test, other_tenant1, other_tenant2';
|
||||
ALTER ROLE other_authenticator SET pgrst.jwt_aud = 'https://otherexample.org';
|
||||
ALTER ROLE other_authenticator SET pgrst.jwt_secret = 'ODERREALLYREALLYREALLYREALLYVERYSAFE';
|
||||
ALTER ROLE other_authenticator SET pgrst.jwt_secret_is_base64 = 'false';
|
||||
ALTER ROLE other_authenticator SET pgrst.jwt_cache_max_entries = '86400';
|
||||
ALTER ROLE other_authenticator SET pgrst.openapi_mode = 'disabled';
|
||||
ALTER ROLE other_authenticator SET pgrst.openapi_security_active = 'false';
|
||||
ALTER ROLE other_authenticator SET pgrst.openapi_server_proxy_uri = 'https://otherexample.org/api';
|
||||
ALTER ROLE other_authenticator SET pgrst.server_cors_allowed_origins = 'http://otherorigin.com';
|
||||
ALTER ROLE other_authenticator SET pgrst.server_timing_enabled = 'true';
|
||||
ALTER ROLE other_authenticator SET pgrst.server_trace_header = 'traceparent';
|
||||
ALTER ROLE other_authenticator SET pgrst.db_hoisted_tx_settings = 'maintenance_work_mem';
|
||||
|
||||
create schema postgrest;
|
||||
grant usage on schema postgrest to db_config_authenticator;
|
||||
grant usage on schema postgrest to other_authenticator;
|
||||
|
||||
-- pre-config hook
|
||||
create or replace function postgrest.pre_config()
|
||||
returns void as $$
|
||||
begin
|
||||
if current_user = 'other_authenticator' then
|
||||
perform
|
||||
set_config('pgrst.jwt_role_claim_key', '."other"."pre_config_role"', true)
|
||||
, set_config('pgrst.db_anon_role', 'pre_config_role', true)
|
||||
, set_config('pgrst.db_schemas', 'will be overriden with the above ALTER ROLE.. db_schemas', true)
|
||||
, set_config('pgrst.db_tx_end', 'rollback-allow-override', true);
|
||||
else
|
||||
null;
|
||||
end if;
|
||||
end $$ language plpgsql;
|
||||
|
||||
create or replace function postgrest.preconf()
|
||||
returns void as $$
|
||||
begin
|
||||
null;
|
||||
end $$ language plpgsql;
|
||||
|
||||
create or replace function postgrest.other_preconf()
|
||||
returns void as $$
|
||||
begin
|
||||
perform postgrest.pre_config();
|
||||
end $$ language plpgsql;
|
||||
|
||||
-- authenticator used for tests that manipulate statement timeout
|
||||
CREATE ROLE timeout_authenticator LOGIN NOINHERIT;
|
||||
|
||||
create function set_statement_timeout(role text, milliseconds int) returns void as $_$
|
||||
begin
|
||||
execute format($$
|
||||
alter role %I set statement_timeout to %L;
|
||||
$$, role, milliseconds);
|
||||
end $_$ volatile security definer language plpgsql;
|
||||
|
||||
-- authenticator used for test-independent database manipulation
|
||||
CREATE ROLE meta_authenticator LOGIN NOINHERIT;
|
||||
@@ -0,0 +1,239 @@
|
||||
cli:
|
||||
# success: valid commands
|
||||
- name: help long
|
||||
args: ['--help']
|
||||
- name: help short
|
||||
args: ['-h']
|
||||
- name: version long
|
||||
args: ['--version']
|
||||
- name: version short
|
||||
args: ['-v']
|
||||
- name: example long
|
||||
args: ['--example']
|
||||
- name: example short
|
||||
args: ['-e']
|
||||
- name: dump config
|
||||
args: ['--dump-config']
|
||||
- name: dump schema
|
||||
args: ['--dump-schema']
|
||||
use_defaultenv: true
|
||||
- name: no config
|
||||
# failures: config files
|
||||
- name: non-existant config file
|
||||
expect: error
|
||||
args: ['does_not_exist.conf']
|
||||
- name: invalid config file
|
||||
expect: error
|
||||
args: ['test/io-tests/configs/invalid.yaml']
|
||||
# failures: wrong config values
|
||||
- name: invalid server-unix-socket-mode not octal
|
||||
expect: error
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_SERVER_UNIX_SOCKET_MODE: '800'
|
||||
- name: invalid server-unix-socket-mode < 600
|
||||
expect: error
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_SERVER_UNIX_SOCKET_MODE: '599'
|
||||
- name: invalid server-unix-socket-mode > 777
|
||||
expect: error
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_SERVER_UNIX_SOCKET_MODE: '778'
|
||||
- name: invalid jwt-aud
|
||||
expect: error
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_JWT_AUD: 'http://%%localhorst.invalid'
|
||||
- name: invalid log-level
|
||||
expect: error
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_LOG_LEVEL: never
|
||||
- name: invalid db-tx-end
|
||||
expect: error
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_DB_TX_END: random
|
||||
- name: invalid openapi-server-proxy-uri
|
||||
expect: error
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_OPENAPI_SERVER_PROXY_URI: 'htp:/@@localhorst.invalid'
|
||||
- name: invalid jwt-secret not base64
|
||||
expect: error
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_JWT_SECRET_IS_BASE64: 'true'
|
||||
PGRST_JWT_SECRET: 'no base-64!'
|
||||
# success: parsing config values
|
||||
- name: log-level=
|
||||
expect: 'log-level = "error"'
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_LOG_LEVEL: ""
|
||||
- name: log-level=crit
|
||||
expect: 'log-level = "crit"'
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_LOG_LEVEL: crit
|
||||
- name: log-level=error
|
||||
expect: 'log-level = "error"'
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_LOG_LEVEL: error
|
||||
- name: log-level=warn
|
||||
expect: 'log-level = "warn"'
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_LOG_LEVEL: warn
|
||||
- name: log-level=info
|
||||
expect: 'log-level = "info"'
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_LOG_LEVEL: info
|
||||
- name: db-tx-end=
|
||||
expect: 'db-tx-end = "commit"'
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_DB_TX_END: ""
|
||||
- name: db-tx-end=commit
|
||||
expect: 'db-tx-end = "commit"'
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_DB_TX_END: commit
|
||||
- name: db-tx-end=commit-allow-override
|
||||
expect: 'db-tx-end = "commit-allow-override"'
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_DB_TX_END: commit-allow-override
|
||||
- name: db-tx-end=rollback-allow-override
|
||||
expect: 'db-tx-end = "rollback-allow-override"'
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_DB_TX_END: rollback-allow-override
|
||||
- name: db-tx-end=rollback
|
||||
expect: 'db-tx-end = "rollback"'
|
||||
use_defaultenv: true
|
||||
env:
|
||||
PGRST_DB_TX_END: rollback
|
||||
|
||||
roleclaims:
|
||||
- key: '.postgrest.a_role'
|
||||
data:
|
||||
postgrest:
|
||||
a_role: postgrest_test_author
|
||||
other: claims
|
||||
expected_status: 200
|
||||
- key: '.customObject.manyRoles[1]'
|
||||
data:
|
||||
customObject:
|
||||
manyRoles:
|
||||
- other
|
||||
- postgrest_test_author
|
||||
other: {}
|
||||
expected_status: 200
|
||||
- key: '."https://www.example.com/roles"[0].value'
|
||||
data:
|
||||
'https://www.example.com/roles':
|
||||
- value: postgrest_test_author
|
||||
other: 666
|
||||
expected_status: 200
|
||||
- key: '.myDomain[3]'
|
||||
data:
|
||||
myDomain:
|
||||
- other
|
||||
- postgrest_test_author
|
||||
other: 1.23
|
||||
expected_status: 401
|
||||
- key: '.myRole'
|
||||
data:
|
||||
role: postgrest_test_author
|
||||
other: true
|
||||
expected_status: 401
|
||||
# https://github.com/PostgREST/postgrest/pull/3813
|
||||
- key: '.realm_access.roles[?(@ == "postgrest_test_author")]'
|
||||
data:
|
||||
realm_access:
|
||||
roles:
|
||||
- other
|
||||
- postgrest_test_author
|
||||
expected_status: 200
|
||||
- key: '.realm_access.roles[?(@ != "other")]'
|
||||
data:
|
||||
realm_access:
|
||||
roles:
|
||||
- other
|
||||
- postgrest_test_author
|
||||
expected_status: 200
|
||||
- key: '.realm_access.roles[?(@ ^== "postgrest_te")]'
|
||||
data:
|
||||
realm_access:
|
||||
roles:
|
||||
- other
|
||||
- postgrest_test_author
|
||||
expected_status: 200
|
||||
- key: '.realm_access.roles[?(@ ==^ "st_test_author")]'
|
||||
data:
|
||||
realm_access:
|
||||
roles:
|
||||
- other
|
||||
- postgrest_test_author
|
||||
expected_status: 200
|
||||
- key: '.realm_access.roles[?(@ *== "_test_")]'
|
||||
data:
|
||||
realm_access:
|
||||
roles:
|
||||
- other
|
||||
- postgrest_test_author
|
||||
expected_status: 200
|
||||
- key: '.realm_access.roles[?(@ == "string")]'
|
||||
data:
|
||||
realm_access:
|
||||
roles:
|
||||
- obj_key: obj_value
|
||||
expected_status: 401 # fails because it compares an object with a string
|
||||
|
||||
jwtaudroleclaims:
|
||||
- key: '.aud'
|
||||
data:
|
||||
aud: postgrest_test_author
|
||||
expected_status: 200
|
||||
- key: '.aud'
|
||||
data:
|
||||
aud: postgrest_test_invalid
|
||||
expected_status: 401
|
||||
- key: '.aud[0]'
|
||||
data:
|
||||
aud: [postgrest_test_author]
|
||||
expected_status: 200
|
||||
- key: '.aud[1]' # succeeds the aud claims check, but fail when hits the db
|
||||
data:
|
||||
aud: [postgrest_test_author, postgrest_test_invalid]
|
||||
expected_status: 401
|
||||
|
||||
invalidroleclaimkeys:
|
||||
- 'role.other'
|
||||
- '.role##'
|
||||
- '.my_role;;domain'
|
||||
- '.#$$%&$%/'
|
||||
- '1234'
|
||||
- '.role[?(@ =)]'
|
||||
|
||||
invalidopenapimodes:
|
||||
- 'follow-'
|
||||
- 'ignore-'
|
||||
- '.#$$%&$%/'
|
||||
|
||||
invalidjointypes:
|
||||
- 'left!'
|
||||
- 'right'
|
||||
- '.#$$%&$%/'
|
||||
|
||||
specialhostvalues:
|
||||
- '*4'
|
||||
- '!4'
|
||||
- '*6'
|
||||
- '!6'
|
||||
- '*'
|
||||
@@ -0,0 +1,300 @@
|
||||
\ir db_config.sql
|
||||
|
||||
set check_function_bodies = false; -- to allow conditionals based on the pg version
|
||||
set search_path to public;
|
||||
|
||||
CREATE ROLE postgrest_test_anonymous;
|
||||
ALTER ROLE :PGUSER SET pgrst.db_anon_role = 'postgrest_test_anonymous';
|
||||
|
||||
CREATE ROLE postgrest_test_author;
|
||||
|
||||
CREATE ROLE postgrest_test_serializable;
|
||||
alter role postgrest_test_serializable set default_transaction_isolation = 'serializable';
|
||||
|
||||
CREATE ROLE postgrest_test_repeatable_read;
|
||||
alter role postgrest_test_repeatable_read set default_transaction_isolation = 'REPEATABLE READ';
|
||||
|
||||
CREATE ROLE postgrest_test_w_superuser_settings;
|
||||
alter role postgrest_test_w_superuser_settings set log_min_duration_statement = 1;
|
||||
alter role postgrest_test_w_superuser_settings set log_min_messages = 'fatal';
|
||||
|
||||
DO $do$BEGIN
|
||||
IF (SELECT current_setting('server_version_num')::INT >= 150000) THEN
|
||||
ALTER ROLE postgrest_test_w_superuser_settings SET log_min_duration_sample = 12345;
|
||||
GRANT SET ON PARAMETER log_min_duration_sample to postgrest_test_authenticator;
|
||||
END IF;
|
||||
END$do$;
|
||||
|
||||
GRANT
|
||||
postgrest_test_anonymous, postgrest_test_author,
|
||||
postgrest_test_serializable, postgrest_test_repeatable_read,
|
||||
postgrest_test_w_superuser_settings TO :PGUSER;
|
||||
|
||||
CREATE SCHEMA v1;
|
||||
GRANT USAGE ON SCHEMA v1 TO postgrest_test_anonymous;
|
||||
|
||||
CREATE SCHEMA test;
|
||||
GRANT USAGE ON SCHEMA test TO postgrest_test_anonymous;
|
||||
|
||||
CREATE TABLE authors_only ();
|
||||
GRANT SELECT ON authors_only TO postgrest_test_author;
|
||||
|
||||
CREATE TABLE projects AS SELECT FROM generate_series(1,5);
|
||||
GRANT SELECT ON projects TO postgrest_test_anonymous, postgrest_test_w_superuser_settings;
|
||||
|
||||
create function get_guc_value(name text) returns text as $$
|
||||
select nullif(current_setting(name), '')::text;
|
||||
$$ language sql;
|
||||
|
||||
create function v1.get_guc_value(name text) returns text as $$
|
||||
select nullif(current_setting(name), '')::text;
|
||||
$$ language sql;
|
||||
|
||||
create function uses_prepared_statements() returns bool as $$
|
||||
select count(name) > 0 from pg_catalog.pg_prepared_statements
|
||||
$$ language sql;
|
||||
|
||||
create function change_max_rows_config(val int, notify bool default false) returns void as $_$
|
||||
begin
|
||||
execute format($$
|
||||
alter role postgrest_test_authenticator set pgrst.db_max_rows = %L;
|
||||
$$, val);
|
||||
if notify then
|
||||
perform pg_notify('pgrst', 'reload config');
|
||||
end if;
|
||||
end $_$ volatile security definer language plpgsql ;
|
||||
|
||||
create function reset_max_rows_config() returns void as $_$
|
||||
begin
|
||||
alter role postgrest_test_authenticator reset pgrst.db_max_rows;
|
||||
end $_$ volatile security definer language plpgsql ;
|
||||
|
||||
create function change_db_schema_and_full_reload(schemas text) returns void as $_$
|
||||
begin
|
||||
execute format($$
|
||||
alter role postgrest_test_authenticator set pgrst.db_schemas = %L;
|
||||
$$, schemas);
|
||||
perform pg_notify('pgrst', 'reload config');
|
||||
perform pg_notify('pgrst', 'reload schema');
|
||||
end $_$ volatile security definer language plpgsql ;
|
||||
|
||||
create function v1.reset_db_schema_config() returns void as $_$
|
||||
begin
|
||||
alter role postgrest_test_authenticator reset pgrst.db_schemas;
|
||||
perform pg_notify('pgrst', 'reload config');
|
||||
perform pg_notify('pgrst', 'reload schema');
|
||||
end $_$ volatile security definer language plpgsql ;
|
||||
|
||||
create function invalid_role_claim_key_reload() returns void as $_$
|
||||
begin
|
||||
alter role postgrest_test_authenticator set pgrst.jwt_role_claim_key = 'test';
|
||||
perform pg_notify('pgrst', 'reload config');
|
||||
end $_$ volatile security definer language plpgsql ;
|
||||
|
||||
create function notify_do_nothing() returns void as $_$
|
||||
notify pgrst, 'nothing';
|
||||
$_$ language sql;
|
||||
|
||||
create function do_nothing() returns void as $_$
|
||||
$_$ language sql;
|
||||
|
||||
create function reset_invalid_role_claim_key() returns void as $_$
|
||||
begin
|
||||
alter role postgrest_test_authenticator reset pgrst.jwt_role_claim_key;
|
||||
perform pg_notify('pgrst', 'reload config');
|
||||
end $_$ volatile security definer language plpgsql ;
|
||||
|
||||
create function reload_pgrst_config() returns void as $_$
|
||||
begin
|
||||
perform pg_notify('pgrst', 'reload config');
|
||||
end $_$ language plpgsql ;
|
||||
|
||||
create or replace function sleep(seconds double precision) returns void as $$
|
||||
select pg_sleep(seconds);
|
||||
$$ language sql;
|
||||
|
||||
create or replace function hello() returns text as $$
|
||||
select 'hello'::text;
|
||||
$$ language sql;
|
||||
|
||||
create table cats(id uuid primary key, name text);
|
||||
grant all on cats to postgrest_test_anonymous;
|
||||
|
||||
create function drop_change_cats() returns void
|
||||
language sql security definer
|
||||
as $$
|
||||
drop table cats;
|
||||
create table cats(id bigint primary key, name text);
|
||||
grant all on table cats to postgrest_test_anonymous;
|
||||
notify pgrst, 'reload schema';
|
||||
$$;
|
||||
|
||||
alter role postgrest_test_anonymous set statement_timeout to '2s';
|
||||
alter role postgrest_test_author set statement_timeout to '10s';
|
||||
|
||||
create function change_role_statement_timeout(timeout text) returns void as $_$
|
||||
begin
|
||||
execute format($$
|
||||
alter role current_user set statement_timeout = %L;
|
||||
$$, timeout);
|
||||
end $_$ volatile language plpgsql ;
|
||||
|
||||
create table items as select x as id from generate_series(1,5) x;
|
||||
|
||||
create view items_w_isolation_level as
|
||||
select
|
||||
id,
|
||||
current_setting('transaction_isolation', true) as isolation_level
|
||||
from items;
|
||||
|
||||
grant all on items_w_isolation_level to postgrest_test_anonymous, postgrest_test_repeatable_read, postgrest_test_serializable;
|
||||
|
||||
create function default_isolation_level()
|
||||
returns text as $$
|
||||
select current_setting('transaction_isolation', true);
|
||||
$$
|
||||
language sql;
|
||||
|
||||
create function serializable_isolation_level()
|
||||
returns text as $$
|
||||
select current_setting('transaction_isolation', true);
|
||||
$$
|
||||
language sql set default_transaction_isolation = 'serializable';
|
||||
|
||||
create function repeatable_read_isolation_level()
|
||||
returns text as $$
|
||||
select current_setting('transaction_isolation', true);
|
||||
$$
|
||||
language sql set default_transaction_isolation = 'REPEATABLE READ';
|
||||
|
||||
create or replace function create_function() returns void as $_$
|
||||
drop function if exists mult_them(int, int);
|
||||
create or replace function mult_them(a int, b int) returns int as $$
|
||||
select a*b;
|
||||
$$ language sql;
|
||||
notify pgrst, 'reload schema';
|
||||
$_$ language sql security definer;
|
||||
|
||||
create or replace function migrate_function() returns void as $_$
|
||||
drop function if exists mult_them(int, int);
|
||||
create or replace function mult_them(c int, d int) returns int as $$
|
||||
select c*d;
|
||||
$$ language sql;
|
||||
notify pgrst, 'reload schema';
|
||||
$_$ language sql security definer;
|
||||
|
||||
create or replace function get_pgrst_version() returns text
|
||||
language sql
|
||||
as $$
|
||||
select application_name
|
||||
from pg_stat_activity
|
||||
where application_name ilike 'postgrest%'
|
||||
limit 1;
|
||||
$$;
|
||||
|
||||
create function terminate_pgrst(appname text) returns setof record as $$
|
||||
select pg_terminate_backend(pid) from pg_stat_activity where application_name iLIKE '%' || appname || '%';
|
||||
$$ language sql security definer;
|
||||
|
||||
create or replace function one_sec_timeout() returns void as $$
|
||||
select pg_sleep(3);
|
||||
$$ language sql set statement_timeout = '1s';
|
||||
|
||||
create or replace function four_sec_timeout() returns void as $$
|
||||
select pg_sleep(3);
|
||||
$$ language sql set statement_timeout = '4s';
|
||||
|
||||
create function get_postgres_version() returns int as $$
|
||||
select current_setting('server_version_num')::int;
|
||||
$$ language sql;
|
||||
|
||||
create or replace function rpc_work_mem() returns items as $$
|
||||
select 1
|
||||
$$ language sql
|
||||
set work_mem = '6000';
|
||||
|
||||
create or replace function rpc_with_one_hoisted() returns items as $$
|
||||
select 1
|
||||
$$ language sql
|
||||
set work_mem = '3000'
|
||||
set statement_timeout = '7s';
|
||||
|
||||
create or replace function rpc_with_two_hoisted() returns items as $$
|
||||
select 1
|
||||
$$ language sql
|
||||
set work_mem = '5000'
|
||||
set statement_timeout = '10s';
|
||||
|
||||
create function get_work_mem(items) returns text as $$
|
||||
select current_setting('work_mem', true) as work_mem
|
||||
$$ language sql;
|
||||
|
||||
create function get_statement_timeout(items) returns text as $$
|
||||
select current_setting('statement_timeout', true) as statement_timeout
|
||||
$$ language sql;
|
||||
|
||||
create function change_db_schemas_config() returns void as $_$
|
||||
begin
|
||||
alter role postgrest_test_authenticator set pgrst.db_schemas = 'test';
|
||||
end $_$ volatile security definer language plpgsql;
|
||||
|
||||
create function reset_db_schemas_config() returns void as $_$
|
||||
begin
|
||||
alter role postgrest_test_authenticator reset pgrst.db_schemas;
|
||||
end $_$ volatile security definer language plpgsql ;
|
||||
|
||||
create function test.get_current_schema() returns text as $$
|
||||
select current_schema()::text;
|
||||
$$ language sql;
|
||||
|
||||
create or replace function root() returns json as $_$
|
||||
select '{"swagger": "2.0"}'::json;
|
||||
$_$ language sql;
|
||||
|
||||
create view infinite_recursion as
|
||||
select * from projects;
|
||||
|
||||
create or replace view infinite_recursion as
|
||||
select * from infinite_recursion;
|
||||
|
||||
create or replace function "true"() returns boolean as $_$
|
||||
select true;
|
||||
$_$ language sql;
|
||||
|
||||
create or replace function notify_pgrst() returns void as $$
|
||||
notify pgrst;
|
||||
$$ language sql;
|
||||
|
||||
-- directors and films table can be used for resource embedding tests
|
||||
create table directors (
|
||||
id int primary key,
|
||||
name text
|
||||
);
|
||||
|
||||
create table films (
|
||||
id int primary key,
|
||||
title text,
|
||||
director_id int,
|
||||
|
||||
constraint fk_director
|
||||
foreign key (director_id) references directors (id)
|
||||
on update cascade
|
||||
on delete cascade
|
||||
);
|
||||
|
||||
-- data to test resource embedding
|
||||
truncate table directors cascade;
|
||||
insert into directors
|
||||
values (1, 'quentin tarantino'),
|
||||
(2, 'christopher nolan'),
|
||||
(3, 'yorgos lathinmos');
|
||||
|
||||
truncate table films cascade;
|
||||
insert into films
|
||||
values (1, 'pulp fiction', 1),
|
||||
(2, 'intersteller',2),
|
||||
(3, 'dogtooth',3),
|
||||
(4, 'reservoir dogs', 1);
|
||||
|
||||
|
||||
GRANT SELECT ON directors, films TO postgrest_test_anonymous, postgrest_test_w_superuser_settings;
|
||||
@@ -0,0 +1,21 @@
|
||||
create schema replica;
|
||||
|
||||
create or replace function replica.is_replica() returns bool as $$
|
||||
select pg_is_in_recovery();
|
||||
$$ language sql;
|
||||
|
||||
create or replace function replica.get_replica_slot() returns name as $$
|
||||
select slot_name from pg_replication_slots limit 1;
|
||||
$$ language sql;
|
||||
|
||||
create table replica.items as select x as id from generate_series(1, 10) x;
|
||||
|
||||
DROP ROLE IF EXISTS postgrest_test_anonymous;
|
||||
CREATE ROLE postgrest_test_anonymous;
|
||||
|
||||
GRANT postgrest_test_anonymous TO :PGUSER;
|
||||
|
||||
GRANT USAGE ON SCHEMA replica TO postgrest_test_anonymous;
|
||||
|
||||
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA replica
|
||||
TO postgrest_test_anonymous;
|
||||
Reference in New Issue
Block a user