Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions testsuite/tests/apicast/policy/on_failed/test_onfailed.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ def status_code(chain_name, on_failed_configuration) -> int:
return on_failed_configuration.get("error_status_code", 503)


@backoff.on_predicate(
backoff.fibo,
lambda response: response.headers.get("server") not in ("openresty", "envoy"),
max_tries=8,
jitter=None,
)
def make_request(api_client):
def make_request(api_client, expected_code):
"""Make request to the product and retry if the response isn't from APIcast"""
return api_client.get("/")

@backoff.on_predicate(
backoff.fibo, lambda response: response.status_code != expected_code, max_tries=8, jitter=None
)
def _request():
return api_client.get("/")

return _request()


def test_on_failed_policy(application, status_code):
Expand All @@ -70,6 +71,5 @@ def test_on_failed_policy(application, status_code):
"""
api_client = application.api_client(disable_retry_status_list=(503,))

response = make_request(api_client)
response = make_request(api_client, status_code)
assert response.status_code == status_code
assert response.headers["server"] in ("openresty", "envoy")
28 changes: 18 additions & 10 deletions testsuite/tests/apicast/test_do_not_send_openresty_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ def client(api_client):
return api_client(disable_retry_status_list={503, 404})


@backoff.on_predicate(
backoff.fibo, lambda x: x.headers.get("server", "") not in ("openresty", "envoy"), max_tries=8, jitter=None
)
def is_openshift_503(response):
"""
The test must distinguish OpenShift's 503 from APIcast's 503.
OpenShift returns 503 with cache-control headers when service is starting.
"""
if response.status_code != 503:
return False
return "Application is not available" in response.text


@backoff.on_predicate(backoff.fibo, is_openshift_503, max_tries=8, jitter=None)
def make_requests(client):
"""Make sure that we get 503 apicast (backend is not available)"""
return client.get("/anything")
Expand All @@ -41,15 +49,15 @@ def make_requests(client):
def test_do_not_send_openresty_version(client):
"""
Make request to non existing endpoint
Assert that the response does not contain openresty version in the headers
Assert that the response does not contain openresty version in the body
Assert that the server header does not contain "openresty" or "nginx"
Assert that the response body does not contain "openresty"
"""
response = make_requests(client)
assert response.status_code == 503

assert "server" in response.headers
if response.headers["server"] == "envoy":
pytest.skip("envoy edge proxy in use")
assert response.headers["server"] == "openresty"
server_header = response.headers.get("server", "")
if server_header:
assert "openresty" not in server_header
assert "nginx" not in server_header

assert "<center>openresty</center>" in response.text
assert "openresty" not in response.text
Loading