forked from Kuadrant/testsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for DNSPolicy health check with additional headers
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Backend for Openshift""" | ||
|
||
import abc | ||
|
||
from testsuite.lifecycle import LifecycleObject | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
testsuite/tests/mgc/dnspolicy/health_check/test_additional_headers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"""Tests for DNSPolicy health checks - additional authentication headers sent with health check requests""" | ||
|
||
import pytest | ||
|
||
from testsuite.openshift.secret import Secret | ||
from testsuite.mockserver import MockserverBackend | ||
from testsuite.policy.dns_policy import HealthCheck, AdditionalHeadersRef | ||
|
||
pytestmark = [pytest.mark.mgc] | ||
|
||
HEADER_NAME = "test-header" | ||
HEADER_VALUE = "test-value" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def backend(request, openshift, name, base_domain, blame, label): | ||
"""Use mockserver as backend for health check requests to verify additional headers""" | ||
mockserver = MockserverBackend(openshift, f"http://{name}.{base_domain}", blame("mocksrv"), label) | ||
request.addfinalizer(mockserver.delete) | ||
mockserver.commit() | ||
|
||
return mockserver | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def mockserver_backend_expectation(backend, route, module_label): # pylint: disable=unused-argument | ||
"""Creates Mockserver Expectation which requires additional headers for successful request""" | ||
backend.create_request_expectation(module_label, headers={HEADER_NAME: [HEADER_VALUE]}) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def headers_secret(request, hub_openshift, blame): | ||
"""Creates Secret with additional headers for DNSPolicy health check""" | ||
secret_name = blame("headers") | ||
headers_secret = Secret.create_instance(hub_openshift, secret_name, {HEADER_NAME: HEADER_VALUE}) | ||
|
||
request.addfinalizer(headers_secret.delete) | ||
headers_secret.commit() | ||
return secret_name | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def health_check(headers_secret, module_label): | ||
"""Returns healthy endpoint specification with additional authentication header for DNSPolicy health check""" | ||
return HealthCheck( | ||
allowInsecureCertificates=True, | ||
additionalHeadersRef=AdditionalHeadersRef(name=headers_secret), | ||
endpoint=f"/{module_label}", | ||
interval="5s", | ||
port=80, | ||
protocol="http", | ||
) | ||
|
||
|
||
def test_additional_headers(dns_health_probe, backend, module_label): | ||
"""Test if additional headers in health check requests are used""" | ||
assert dns_health_probe.is_healthy() | ||
|
||
requests = backend.retrieve_requests(module_label) | ||
assert len(requests) > 0 | ||
|
||
request_headers = requests[0]["headers"] | ||
assert request_headers.get(HEADER_NAME) == [HEADER_VALUE] |