Skip to content

Commit e3a82f6

Browse files
lugi0adolfo-ab
authored andcommitted
test MR failure when using http protocol for endpoint (opendatahub-io#336)
* feat: test failure when using http protocol Signed-off-by: lugi0 <[email protected]> * fix: typo and small refactor Signed-off-by: lugi0 <[email protected]> --------- Signed-off-by: lugi0 <[email protected]>
1 parent b0cc478 commit e3a82f6

1 file changed

Lines changed: 47 additions & 6 deletions

File tree

tests/model_registry/python_client/test_model_registry_creation_oauth.py

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
from utilities.constants import DscComponents
88
from tests.model_registry.constants import MODEL_NAME, MODEL_DICT
99
from model_registry import ModelRegistry as ModelRegistryClient
10+
from kubernetes.dynamic import DynamicClient
11+
from ocp_resources.service import Service
12+
from utilities.constants import Protocols
13+
from tests.model_registry.utils import get_endpoint_from_mr_service
14+
from aiohttp.client_exceptions import ServerDisconnectedError
1015

1116
LOGGER = get_logger(name=__name__)
1217
MINVER = Version.parse(version="2.21.0")
1318

1419

1520
@pytest.mark.parametrize(
16-
"updated_dsc_component_state_scope_class, model_registry_client",
21+
"updated_dsc_component_state_scope_class",
1722
[
1823
pytest.param(
1924
{
@@ -24,7 +29,6 @@
2429
},
2530
},
2631
},
27-
{"service_fixture": "model_registry_instance_oauth_service"},
2832
id="oauth_proxy",
2933
),
3034
],
@@ -33,18 +37,28 @@
3337
@pytest.mark.usefixtures("updated_dsc_component_state_scope_class")
3438
class TestModelRegistryCreationOAuth:
3539
"""
36-
Tests the creation of a model registry with OAuth proxy configuration.
37-
Jira ID: RHOAIENG-26194
40+
Validate model registry with OAuth proxy configuration.
41+
Jira IDs: RHOAIENG-26194, RHOAIENG-26195
3842
"""
3943

44+
# Tests RHOAIENG-26194
45+
@pytest.mark.parametrize(
46+
"model_registry_client",
47+
[
48+
pytest.param(
49+
{"service_fixture": "model_registry_instance_oauth_service"},
50+
)
51+
],
52+
indirect=True,
53+
)
4054
@pytest.mark.smoke
4155
def test_registering_model_with_oauth(
4256
self: Self,
43-
admin_client,
57+
admin_client: DynamicClient,
4458
model_registry_client: ModelRegistryClient,
4559
):
4660
if py_config["distribution"] == "downstream" and get_product_version(admin_client=admin_client) < MINVER:
47-
pytest.skip("Skipping test for RHOAI < 2.21")
61+
pytest.skip(f"Skipping test for RHOAI < {MINVER}")
4862

4963
# Register a new model
5064
registered_model = model_registry_client.register_model(
@@ -75,3 +89,30 @@ def test_registering_model_with_oauth(
7589
]
7690
if errors:
7791
pytest.fail("errors found in model registry response validation:\n{}".format("\n".join(errors)))
92+
93+
# Tests RHOAIENG-26195
94+
def test_encrypted_oauth_proxy(
95+
self: Self,
96+
admin_client: DynamicClient,
97+
model_registry_instance_oauth_service: Service,
98+
current_client_token: str,
99+
):
100+
"""Test that connecting to encrypted OAuth proxy with HTTP protocol fails appropriately."""
101+
if py_config["distribution"] == "downstream" and get_product_version(admin_client=admin_client) < MINVER:
102+
pytest.skip(f"Skipping test for RHOAI < {MINVER}")
103+
104+
# Get the REST endpoint
105+
rest_endpoint = get_endpoint_from_mr_service(svc=model_registry_instance_oauth_service, protocol=Protocols.REST)
106+
107+
# Create the client
108+
server, port = rest_endpoint.split(":")
109+
with pytest.raises(ServerDisconnectedError) as exc_info:
110+
_ = ModelRegistryClient(
111+
server_address=f"{Protocols.HTTP}://{server}",
112+
port=port,
113+
author="opendatahub-test",
114+
user_token=current_client_token,
115+
is_secure=False,
116+
)
117+
assert str(exc_info.value) == "Server disconnected", f"Expected Server disconnected, but got {exc_info.value}"
118+
LOGGER.info("Successfully received expected Server Disconnected exception")

0 commit comments

Comments
 (0)