Skip to content

Commit c1000c0

Browse files
authored
Merge pull request #50 from JaurbanRH/wildcard
Add tests for wildcard hosts
2 parents 36b9f1c + 60349d1 commit c1000c0

File tree

6 files changed

+93
-11
lines changed

6 files changed

+93
-11
lines changed

testsuite/objects/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def remove_all_hosts(self):
6060
def add_opa_policy(self, name, rego_policy):
6161
"""Adds OPA inline Rego policy"""
6262

63+
@abc.abstractmethod
64+
def add_response(self, response):
65+
"""Add response to AuthConfig"""
66+
6367

6468
class PreexistingAuthorino(Authorino):
6569
"""Authorino which is already deployed prior to the testrun"""

testsuite/openshift/objects/auth_config.py

+5
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,8 @@ def add_opa_policy(self, name, rego_policy):
118118
"inlineRego": rego_policy
119119
}
120120
})
121+
122+
@modify
123+
def add_response(self, response):
124+
"""Add response to AuthConfig"""
125+
self.model["spec"]["response"] = [response]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Test for wildcard collisions with clusterwide authorino
3+
"""
4+
5+
import pytest
6+
7+
from testsuite.openshift.objects.auth_config import AuthConfig
8+
9+
10+
# pylint: disable = unused-argument
11+
@pytest.fixture(scope="module")
12+
def authorization(authorino, blame, openshift, module_label, envoy, wildcard_domain):
13+
"""In case of Authorino, AuthConfig used for authorization"""
14+
auth = AuthConfig.create_instance(openshift, blame("ac"), wildcard_domain, labels={"testRun": module_label})
15+
auth.add_response({"name": "header", "json": {"properties": [{"name": "anything", "value": "one"}]}})
16+
return auth
17+
18+
19+
# pylint: disable = unused-argument
20+
@pytest.fixture(scope="module")
21+
def authorization2(authorino, blame, openshift2, module_label, envoy, wildcard_domain):
22+
"""In case of Authorino, AuthConfig used for authorization"""
23+
auth = AuthConfig.create_instance(openshift2, blame("ac"), wildcard_domain, labels={"testRun": module_label})
24+
auth.add_response({"name": "header", "json": {"properties": [{"name": "anything", "value": "two"}]}})
25+
return auth
26+
27+
28+
@pytest.mark.parametrize(("client_fixture", "auth_fixture", "hosts"), [
29+
pytest.param("client", "authorization", "wildcard_domain", id="First namespace"),
30+
pytest.param("client2", "authorization2", [], id="Second namespace"),
31+
])
32+
def test_wildcard_collision(client_fixture, auth_fixture, hosts, request):
33+
"""
34+
Preparation:
35+
- Create AuthConfig with host set to wildcard_domain
36+
- Create AuthConfig with host set to wildcard_domain in another project
37+
Test:
38+
- Send request to authorino
39+
- Assert that the correct AuthConfig was used
40+
"""
41+
if hosts:
42+
hosts = [request.getfixturevalue(hosts)]
43+
client = request.getfixturevalue(client_fixture)
44+
response = client.get("/get")
45+
assert response.status_code == 200
46+
assert response.json()["headers"]["Header"] == '{"anything":"one"}'
47+
authorization = request.getfixturevalue(auth_fixture)
48+
assert authorization.model.status.summary.hostsReady == hosts

testsuite/tests/kuadrant/authorino/operator/conftest.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Conftest for all tests requiring custom deployment of Authorino"""
2+
from urllib.parse import urlparse
3+
24
import pytest
35
from weakget import weakget
46

@@ -37,3 +39,12 @@ def authorino(openshift, blame, request, testconfig, cluster_wide, module_label,
3739
authorino.commit()
3840
authorino.wait_for_ready()
3941
return authorino
42+
43+
44+
@pytest.fixture(scope="session")
45+
def wildcard_domain(openshift):
46+
"""
47+
Wildcard domain of openshift cluster
48+
"""
49+
hostname = urlparse(openshift.api_url).hostname
50+
return "*.apps." + hostname.split(".", 1)[1]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Test for wildcard host
3+
"""
4+
import pytest
5+
6+
from testsuite.openshift.objects.auth_config import AuthConfig
7+
8+
9+
# pylint: disable = unused-argument
10+
@pytest.fixture(scope="module")
11+
def authorization(authorino, blame, openshift, module_label):
12+
"""In case of Authorino, AuthConfig used for authorization"""
13+
return AuthConfig.create_instance(openshift, blame("ac"), "*.redhat.com", labels={"testRun": module_label})
14+
15+
16+
def test_wildcard(client):
17+
"""
18+
Preparation:
19+
- Create AuthConfig with host set to `*.redhat.com`
20+
Test:
21+
- Send request to authorino
22+
- Assert that request was successful
23+
"""
24+
response = client.get("/get")
25+
assert response.status_code == 200

testsuite/tests/kuadrant/authorino/operator/tls/conftest.py

-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Conftest for all TLS-enabled tests"""
2-
from urllib.parse import urlparse
32

43
import pytest
54

@@ -46,16 +45,6 @@ def cfssl(testconfig):
4645
return client
4746

4847

49-
@pytest.fixture(scope="session")
50-
def wildcard_domain(openshift):
51-
"""
52-
Hostname of the upstream certificate sent to be validated by APIcast
53-
May be overwritten to configure different test cases
54-
"""
55-
hostname = urlparse(openshift.api_url).hostname
56-
return "*.apps." + hostname.split(".", 1)[1]
57-
58-
5948
@pytest.fixture(scope="session")
6049
def authorino_domain(openshift):
6150
"""

0 commit comments

Comments
 (0)