Correct live/ready checks to consider special host values (#2182)

This commit is contained in:
Steve Chavez
2022-03-11 15:16:45 +01:00
committed by GitHub
parent c803c4d0b6
commit a3c1d9977f
4 changed files with 55 additions and 18 deletions
+7
View File
@@ -171,3 +171,10 @@ invalidjointypes:
- 'left!'
- 'right'
- '.#$$%&$%/'
specialhostvalues:
- '*4'
- '!4'
- '*6'
- '!6'
- '*'
+13 -2
View File
@@ -140,7 +140,7 @@ def dumpconfig(configpath=None, env=None, stdin=None):
@contextlib.contextmanager
def run(configpath=None, stdin=None, env=None, port=None):
def run(configpath=None, stdin=None, env=None, port=None, host=None):
"Run PostgREST and yield an endpoint that is ready for connections."
env = env or {}
env["PGRST_DB_POOL"] = "1"
@@ -149,7 +149,7 @@ def run(configpath=None, stdin=None, env=None, port=None):
with tempfile.TemporaryDirectory() as tmpdir:
if port:
env["PGRST_SERVER_PORT"] = str(port)
env["PGRST_SERVER_HOST"] = "localhost"
env["PGRST_SERVER_HOST"] = host or "localhost"
baseurl = f"http://localhost:{port}"
else:
socketfile = pathlib.Path(tmpdir) / "postgrest.sock"
@@ -883,6 +883,17 @@ def test_admin_live_dependent_on_main_app(defaultenv):
response = postgrest.admin.get("/live")
assert response.status_code == 503
@pytest.mark.parametrize("specialhostvalue", FIXTURES["specialhostvalues"])
def test_admin_works_with_host_special_values(specialhostvalue, defaultenv):
"Should get a success from the admin live and ready endpoints when using special host values for the main app"
with run(env=defaultenv, port=freeport(), host=specialhostvalue) as postgrest:
response = postgrest.admin.get("/live")
assert response.status_code == 200
response = postgrest.admin.get("/ready")
assert response.status_code == 200
@pytest.mark.parametrize(
"level, has_output",