From 3935dac31694254c0f4913a58cb6f7014d2e2455 Mon Sep 17 00:00:00 2001 From: Jakub Urban Date: Fri, 19 Aug 2022 10:25:37 +0200 Subject: [PATCH] Add test for authorino sharding --- .../kuadrant/authorino/operator/conftest.py | 9 ++- .../authorino/operator/test_sharding.py | 70 +++++++++++++++++++ 2 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 testsuite/tests/kuadrant/authorino/operator/test_sharding.py diff --git a/testsuite/tests/kuadrant/authorino/operator/conftest.py b/testsuite/tests/kuadrant/authorino/operator/conftest.py index 9fa235a8..37a16186 100644 --- a/testsuite/tests/kuadrant/authorino/operator/conftest.py +++ b/testsuite/tests/kuadrant/authorino/operator/conftest.py @@ -23,13 +23,16 @@ def authorino(openshift, blame, request, testconfig, cluster_wide, module_label, if not testconfig["authorino"]["deploy"]: return pytest.skip("Operator tests don't work with already deployed Authorino") - parameters = {"label_selectors": [f"testRun={module_label}"], - **authorino_parameters} + if authorino_parameters.get("label_selectors"): + authorino_parameters["label_selectors"].append(f"testRun={module_label}") + else: + authorino_parameters["label_selectors"] = [f"testRun={module_label}"] + authorino = AuthorinoCR.create_instance(openshift, blame("authorino"), cluster_wide=cluster_wide, image=weakget(testconfig)["authorino"]["image"] % None, - **parameters) + **authorino_parameters) request.addfinalizer(lambda: authorino.delete(ignore_not_found=True)) authorino.commit() authorino.wait_for_ready() diff --git a/testsuite/tests/kuadrant/authorino/operator/test_sharding.py b/testsuite/tests/kuadrant/authorino/operator/test_sharding.py new file mode 100644 index 00000000..df845068 --- /dev/null +++ b/testsuite/tests/kuadrant/authorino/operator/test_sharding.py @@ -0,0 +1,70 @@ +"""Test for authorino sharding""" +import pytest + +from testsuite.openshift.httpbin import Envoy +from testsuite.openshift.objects.auth_config import AuthConfig + + +@pytest.fixture(scope="module") +def authorino_parameters(authorino_parameters): + """Setup TLS for authorino""" + authorino_parameters["label_selectors"] = ["sharding=true"] + yield authorino_parameters + + +@pytest.fixture(scope="module") +def envoy(request, authorino, openshift, blame, backend, module_label): + """Envoy""" + + def _envoy(): + envoy = Envoy(openshift, authorino, blame("envoy"), module_label, backend.url) + request.addfinalizer(envoy.delete) + envoy.commit() + return envoy + + return _envoy + + +# pylint: disable=unused-argument +@pytest.fixture(scope="module") +def authorization(request, authorino, blame, openshift, module_label): + """In case of Authorino, AuthConfig used for authorization""" + + def _authorization(envoy, sharding): + auth = AuthConfig.create_instance(openshift, blame("ac"), envoy.hostname, + labels={"testRun": module_label, "sharding": sharding}) + request.addfinalizer(auth.delete) + auth.commit() + return auth + + return _authorization + + +@pytest.fixture(scope="module", autouse=True) +def commit(): + """Ensure no default resources are created""" + return + + +def test_sharding(authorization, envoy): + """ + Setup: + - Create Authorino that watch only AuthConfigs with label `sharding=true` + Test: + - Create AuthConfig with `sharding=true` label + - Create AuthConfig with `sharding=false` label + - Send a request to the first AuthConfig + - Assert that the response status code is 200 + - Send a request to the second AuthConfig + - Assert that the response status code is 404 + """ + envoy1 = envoy() + envoy2 = envoy() + authorization(envoy1, "true") + authorization(envoy2, "false") + + response = envoy1.client().get("/get") + assert response.status_code == 200 + + response = envoy2.client().get("/get") + assert response.status_code == 404