Skip to content

Commit

Permalink
Improve statement and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Feb 27, 2021
1 parent 5e1d2e1 commit a9f5930
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/PostgREST/Statements.hs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ dbSettingsStatement = H.Statement sql HE.noParams decodeSettings False
),
kv_settings as (
select setdatabase, split_part(setting, '=', 1) as k, split_part(setting, '=', 2) as value from role_setting
where setting like 'pgrst.%'
)
select distinct on (key) replace(k, 'pgrst.', '') as key, value
from kv_settings
where k like 'pgrst.%'
order by key, setdatabase desc;
|]
decodeSettings = HD.rowList $ (,) <$> column HD.text <*> column HD.text
9 changes: 7 additions & 2 deletions test/fixtures/roles.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ ALTER ROLE postgrest_test_authenticator SET pgrst."db_max_rows" = '1000';
ALTER ROLE postgrest_test_authenticator SET pgrst."db_extra_search_path" = 'public, extensions';

-- override with database specific setting
ALTER ROLE postgrest_test_authenticator SET pgrst."db_max_rows" = '1111';
ALTER ROLE postgrest_test_authenticator IN DATABASE postgres SET pgrst."db_extra_search_path" = 'public, extensions, private';
ALTER ROLE postgrest_test_authenticator IN DATABASE :DBNAME SET pgrst."jwt_secret" = 'OVERRIDEREALLYREALLYREALLYREALLYVERYSAFE';
ALTER ROLE postgrest_test_authenticator IN DATABASE :DBNAME SET pgrst."db_extra_search_path" = 'public, extensions, private';

-- other database settings that should be ignored
DROP DATABASE IF EXISTS other;
CREATE DATABASE other;
ALTER ROLE postgrest_test_authenticator IN DATABASE other SET pgrst."db_max_rows" = '1111';

-- non-reloadable configs for io tests
ALTER ROLE postgrest_test_authenticator SET pgrst."server_host" = 'ignored';
Expand Down
4 changes: 2 additions & 2 deletions test/io-tests/configs/expected/no-defaults-with-db.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ db-anon-role = "postgrest_test_anonymous"
db-channel = "postgrest"
db-channel-enabled = true
db-extra-search-path = "public,extensions,private"
db-max-rows = 1111
db-max-rows = 1000
db-pool = 1
db-pool-timeout = 100
db-pre-request = "test.custom_headers"
Expand All @@ -14,7 +14,7 @@ db-tx-end = "commit-allow-override"
db-uri = "<REPLACED_WITH_DB_URI>"
jwt-aud = "https://example.org"
jwt-role-claim-key = ".\"a\".\"role\""
jwt-secret = "REALLYREALLYREALLYREALLYVERYSAFE"
jwt-secret = "OVERRIDEREALLYREALLYREALLYREALLYVERYSAFE"
jwt-secret-is-base64 = true
log-level = "info"
openapi-server-proxy-uri = "https://example.org/api"
Expand Down
4 changes: 2 additions & 2 deletions test/io-tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ def test_read_db_setting(defaultenv):
"PGRST_DB_LOAD_GUC_CONFIG": "true",
}
with run(env=env) as postgrest:
uri = "/rpc/get_guc_value?name=pgrst.db_max_rows"
uri = "/rpc/get_guc_value?name=pgrst.jwt_secret"
response = postgrest.session.get(uri)

assert response.text == '"1111"'
assert response.text == '"OVERRIDEREALLYREALLYREALLYREALLYVERYSAFE"'


@pytest.mark.parametrize(
Expand Down

0 comments on commit a9f5930

Please sign in to comment.