|
| 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 |
0 commit comments