Skip to content

Commit 4552d17

Browse files
authored
Merge pull request #112 from pehala/lazy_validators
Make validators even more lazy
2 parents f652c64 + 39e79ac commit 4552d17

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

testsuite/config/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def __init__(self, name, default, **kwargs) -> None:
2929
merge_enabled=True,
3030
validators=[
3131
Validator("authorino.deploy", must_exist=True, eq=True) | Validator("authorino.url", must_exist=True),
32-
DefaultValueValidator("rhsso.url", must_exist=True, default=fetch_route("no-ssl-sso")),
33-
DefaultValueValidator("rhsso.password",
34-
must_exist=True, default=fetch_secret("credential-sso", "ADMIN_PASSWORD")),
35-
DefaultValueValidator("mockserver.url", must_exist=True, default=fetch_route("no-ssl-mockserver")),
32+
DefaultValueValidator("rhsso.url", default=fetch_route("no-ssl-sso")),
33+
DefaultValueValidator("rhsso.password", default=fetch_secret("credential-sso", "ADMIN_PASSWORD")),
34+
DefaultValueValidator("mockserver.url", default=fetch_route("no-ssl-mockserver")),
3635
],
36+
validate_only=["authorino"],
3737
loaders=["testsuite.config.openshift_loader", "dynaconf.loaders.env_loader"]
3838
)

testsuite/tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ def openshift2(testconfig):
5555
@pytest.fixture(scope="session")
5656
def rhsso(request, testconfig, blame):
5757
"""RHSSO OIDC Provider fixture"""
58-
cnf = testconfig["rhsso"]
5958
try:
59+
testconfig.validators.validate(only="rhsso")
60+
cnf = testconfig["rhsso"]
6061
info = RHSSO(cnf["url"], cnf["username"], cnf["password"], blame("realm"), blame("client"),
6162
cnf["test_user"]["username"], cnf["test_user"]["password"])
6263

testsuite/tests/kuadrant/authorino/authorization/opa/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Conftest for Open Policy Agent (OPA)"""
22
import pytest
3+
from dynaconf import ValidationError
34

45
from testsuite.mockserver import Mockserver
56
from testsuite.utils import rego_allow_header
@@ -15,9 +16,10 @@ def header():
1516
def mockserver(request, testconfig, module_label, header):
1617
"""Returns mockserver and creates Expectation that returns Rego query"""
1718
try:
19+
testconfig.validators.validate(only=["mockserver"])
1820
mockserver = Mockserver(testconfig["mockserver"]["url"])
1921
request.addfinalizer(lambda: mockserver.clear_expectation(module_label))
2022
mockserver.create_expectation(module_label, "/opa", rego_allow_header(*header))
2123
return mockserver
22-
except KeyError as exc:
24+
except (KeyError, ValidationError) as exc:
2325
return pytest.skip(f"Mockserver configuration item is missing: {exc}")

testsuite/tests/kuadrant/authorino/authorization/opa/test_external_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
@pytest.fixture(scope="module")
7-
def authorization(authorization, mockserver):
7+
def authorization(mockserver, authorization):
88
"""
99
Adds OPA policy. Rego query is located on external registry (Mockserver).
1010
Policy accepts requests that contain `header`.

testsuite/tests/kuadrant/authorino/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from weakget import weakget
44

55
from testsuite.httpx.auth import HttpxOidcClientAuth
6+
from testsuite.objects import Authorino, Authorization, PreexistingAuthorino
67
from testsuite.openshift.client import OpenShiftClient
78
from testsuite.openshift.objects.api_key import APIKey
89
from testsuite.openshift.objects.auth_config import AuthConfig
9-
from testsuite.objects import Authorino, Authorization, PreexistingAuthorino
1010
from testsuite.openshift.objects.authorino import AuthorinoCR
1111

1212

@@ -42,7 +42,7 @@ def authorino(authorino, openshift, blame, request, testconfig, module_label, au
4242

4343
# pylint: disable=unused-argument
4444
@pytest.fixture(scope="module")
45-
def authorization(authorization, authorino, envoy, blame, openshift, module_label, oidc_provider) -> Authorization:
45+
def authorization(authorization, oidc_provider, authorino, envoy, blame, openshift, module_label) -> Authorization:
4646
"""In case of Authorino, AuthConfig used for authorization"""
4747
if authorization is None:
4848
authorization = AuthConfig.create_instance(openshift, blame("ac"),

0 commit comments

Comments
 (0)