Skip to content

Commit

Permalink
Add test for authorino sharding
Browse files Browse the repository at this point in the history
  • Loading branch information
jakurban committed Aug 19, 2022
1 parent 1c93b44 commit d3aabae
Show file tree
Hide file tree
Showing 2 changed files with 70 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, label, author
if not testconfig["authorino"]["deploy"]:
return pytest.skip("Operator tests don't work with already deployed Authorino")

parameters = {"label_selectors": [f"testRun={label}"],
**authorino_parameters}
if authorino_parameters.get("label_selectors"):
authorino_parameters["label_selectors"].append(f"testRun={label}")
else:
authorino_parameters["label_selectors"] = [f"testRun={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
64 changes: 64 additions & 0 deletions testsuite/tests/kuadrant/authorino/operator/test_sharding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""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, label):
"""Envoy"""

def _envoy():
envoy = Envoy(openshift, authorino, blame("envoy"), 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, label):
"""In case of Authorino, AuthConfig used for authorization"""

def _authorization(envoy, sharding):
auth = AuthConfig.create_instance(openshift, blame("ac"), envoy.hostname,
labels={"testRun": label, "sharding": sharding})
request.addfinalizer(auth.delete)
auth.commit()
return auth

return _authorization


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 d3aabae

Please sign in to comment.