Correct hardcoded postgrest_test_authenticator (#1743)

Also remove panic from Config and correct io test not running
This commit is contained in:
Steve Chavez
2021-01-25 18:38:46 -05:00
committed by GitHub
parent 6557f1f9c0
commit c93e8f9e0c
5 changed files with 69 additions and 14 deletions
+21 -6
View File
@@ -154,7 +154,9 @@ def run(configpath=None, stdin=None, env=None, port=None):
if configpath:
command.append(configpath)
process = subprocess.Popen(command, stdin=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
process = subprocess.Popen(
command, stdin=subprocess.PIPE, stderr=subprocess.PIPE, env=env
)
try:
process.stdin.write(stdin or b"")
@@ -267,23 +269,34 @@ def test_expected_config_from_environment():
assert dumpconfig(env=env) == expected
def test_expected_config_from_db_settings(defaultenv):
@pytest.mark.parametrize(
"role, expectedconfig",
[
("postgrest_test_authenticator", "no-defaults-with-db.config"),
("other_authenticator", "no-defaults-with-db-other-authenticator.config"),
],
)
def test_expected_config_from_db_settings(defaultenv, role, expectedconfig):
"Config should be overriden from database settings"
config = CONFIGSDIR / "no-defaults.config"
db_uri = defaultenv["PGRST_DB_URI"].replace(
"user=postgrest_test_authenticator", f"user={role}"
)
env = {
**defaultenv,
"PGRST_DB_URI": db_uri,
"PGRST_DB_LOAD_GUC_CONFIG": "true",
}
expected = (
(CONFIGSDIR / "expected" / "no-defaults-with-db.config")
(CONFIGSDIR / "expected" / expectedconfig)
.read_text()
.replace("<REPLACED_WITH_DB_URI>", env["PGRST_DB_URI"])
)
assert dumpconfig(configpath=config, env=env) == expected
@pytest.mark.parametrize(
"config",
[conf for conf in CONFIGSDIR.iterdir() if conf.suffix == ".config"],
@@ -591,7 +604,7 @@ def test_max_rows_notify_reload(defaultenv):
# reset max-rows config on the db
postgrest.session.post("/rpc/reset_max_rows_config")
def invalid_role_claim_key_notify_reload(defaultenv):
def test_invalid_role_claim_key_notify_reload(defaultenv):
"NOTIFY reload config should show an error if role-claim-key is invalid"
env = {
@@ -603,6 +616,8 @@ def invalid_role_claim_key_notify_reload(defaultenv):
with run(env=env) as postgrest:
postgrest.session.post("/rpc/invalid_role_claim_key_reload")
assert "failed to parse role-claim-key value" in str(postgrest.process.stderr.readline())
assert "failed to parse role-claim-key value" in str(
postgrest.process.stderr.readline()
)
postgrest.session.post("/rpc/reset_invalid_role_claim_key")