-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from JaurbanRH/sharding
Add test for authorino sharding
- Loading branch information
Showing
2 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
testsuite/tests/kuadrant/authorino/operator/test_sharding.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |