Skip to content

Commit

Permalink
Merge pull request #51 from JaurbanRH/sharding
Browse files Browse the repository at this point in the history
Add test for authorino sharding
  • Loading branch information
pehala authored Aug 25, 2022
2 parents 7ca5803 + 3935dac commit c75b051
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
9 changes: 6 additions & 3 deletions testsuite/tests/kuadrant/authorino/operator/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
70 changes: 70 additions & 0 deletions testsuite/tests/kuadrant/authorino/operator/test_sharding.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c75b051

Please sign in to comment.