Skip to content

Commit 4793604

Browse files
mwaykoleMilind Waykolepre-commit-ci[bot]
authored
ADD test for cross model auth and enable token and verify (#126)
* ADD test for cross model auth and enable token and verify Signed-off-by: Milind Waykole <mwaykole@mwaykole-thinkpadp1gen4i.bengluru.csb> * ADD test for cross model auth and enable token and verify Signed-off-by: Milind Waykole <mwaykole@mwaykole-thinkpadp1gen4i.bengluru.csb> * ADD test for cross model auth and enable token and verify Signed-off-by: Milind Waykole <mwaykole@mwaykole-thinkpadp1gen4i.bengluru.csb> * ADD test for cross model auth and enable token and verify Signed-off-by: Milind Waykole <mwaykole@mwaykole-thinkpadp1gen4i.bengluru.csb> * ADD test for cross model auth and enable token and verify Signed-off-by: Milind Waykole <mwaykole@mwaykole-thinkpadp1gen4i.bengluru.csb> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * ADD test for cross model auth and enable token and verify Signed-off-by: Milind Waykole <mwaykole@mwaykole-thinkpadp1gen4i.bengluru.csb> * ADD test for cross model auth and enable token and verify Signed-off-by: Milind Waykole <mwaykole@mwaykole-thinkpadp1gen4i.bengluru.csb> * ADD test for cross model auth and enable token and verify Signed-off-by: Milind Waykole <mwaykole@mwaykole-thinkpadp1gen4i.bengluru.csb> * ADD test for cross model auth and enable token and verify Signed-off-by: Milind Waykole <mwaykole@mwaykole-thinkpadp1gen4i.bengluru.csb> * ADD test for cross model auth and enable token and verify Signed-off-by: Milind Waykole <mwaykole@mwaykole-thinkpadp1gen4i.bengluru.csb> --------- Signed-off-by: Milind Waykole <mwaykole@mwaykole-thinkpadp1gen4i.bengluru.csb> Co-authored-by: Milind Waykole <mwaykole@mwaykole-thinkpadp1gen4i.bengluru.csb> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 6ee1fc5 commit 4793604

File tree

2 files changed

+84
-2
lines changed

2 files changed

+84
-2
lines changed

tests/model_serving/model_server/authentication/conftest.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ def patched_remove_raw_authentication_isvc(
208208
yield http_s3_caikit_raw_inference_service
209209

210210

211+
@pytest.fixture(scope="class")
212+
def model_service_account_2(
213+
admin_client: DynamicClient, models_endpoint_s3_secret: Secret
214+
) -> Generator[ServiceAccount, Any, Any]:
215+
with ServiceAccount(
216+
client=admin_client,
217+
namespace=models_endpoint_s3_secret.namespace,
218+
name="models-bucket-sa-2",
219+
secrets=[{"name": models_endpoint_s3_secret.name}],
220+
) as sa:
221+
yield sa
222+
223+
211224
@pytest.fixture(scope="class")
212225
def grpc_view_role(
213226
admin_client: DynamicClient, grpc_s3_inference_service: InferenceService
@@ -298,6 +311,30 @@ def http_s3_caikit_raw_inference_service(
298311
yield isvc
299312

300313

314+
@pytest.fixture(scope="class")
315+
def http_s3_caikit_raw_inference_service_2(
316+
request: FixtureRequest,
317+
admin_client: DynamicClient,
318+
model_namespace: Namespace,
319+
http_s3_caikit_tgis_serving_runtime: ServingRuntime,
320+
s3_models_storage_uri: str,
321+
model_service_account_2: ServiceAccount,
322+
) -> InferenceService:
323+
with create_isvc(
324+
client=admin_client,
325+
name=f"{Protocols.HTTP}-{ModelFormat.CAIKIT}-2",
326+
namespace=model_namespace.name,
327+
runtime=http_s3_caikit_tgis_serving_runtime.name,
328+
storage_uri=s3_models_storage_uri,
329+
model_format=http_s3_caikit_tgis_serving_runtime.instance.spec.supportedModelFormats[0].name,
330+
deployment_mode=KServeDeploymentType.RAW_DEPLOYMENT,
331+
model_service_account=model_service_account_2.name,
332+
enable_auth=True,
333+
external_route=True,
334+
) as isvc:
335+
yield isvc
336+
337+
301338
# Unprivileged user tests
302339
@pytest.fixture(scope="class")
303340
def unprivileged_model_namespace(

tests/model_serving/model_server/authentication/test_kserve_token_authentication_raw.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
from ocp_resources.resource import ResourceEditor
33

44
from tests.model_serving.model_server.utils import verify_inference_response
5-
from utilities.constants import Labels, ModelFormat, ModelStoragePath, Protocols
6-
from utilities.inference_utils import Inference
5+
from utilities.constants import ModelFormat, ModelStoragePath, Protocols
6+
from utilities.constants import Labels
7+
from utilities.inference_utils import Inference, UserInference
78
from utilities.infra import check_pod_status_in_time, get_pods_by_isvc_label
9+
from utilities.jira import is_jira_open
810
from utilities.manifests.caikit_tgis import CAIKIT_TGIS_INFERENCE_CONFIG
911

1012
pytestmark = pytest.mark.usefixtures("valid_aws_config")
@@ -80,3 +82,46 @@ def test_raw_disable_enable_authentication_no_pod_rollout(self, http_s3_caikit_r
8082
).update()
8183

8284
check_pod_status_in_time(pod=pod, status={pod.Status.RUNNING})
85+
86+
@pytest.mark.dependency(depends=["test_disabled_raw_model_authentication"])
87+
def test_re_enabled_raw_model_authentication(self, http_s3_caikit_raw_inference_service, http_raw_inference_token):
88+
"""Verify model query after authentication is re-enabled"""
89+
verify_inference_response(
90+
inference_service=http_s3_caikit_raw_inference_service,
91+
inference_config=CAIKIT_TGIS_INFERENCE_CONFIG,
92+
inference_type=Inference.ALL_TOKENS,
93+
protocol=Protocols.HTTPS,
94+
model_name=ModelFormat.CAIKIT,
95+
use_default_query=True,
96+
token=http_raw_inference_token,
97+
)
98+
99+
@pytest.mark.dependency(name="test_cross_model_authentication_raw")
100+
def test_cross_model_authentication_raw(
101+
self, http_s3_caikit_raw_inference_service_2, http_raw_inference_token, admin_client
102+
):
103+
"""Verify model with another model token"""
104+
if is_jira_open(jira_id="RHOAIENG-19645", admin_client=admin_client):
105+
inference = UserInference(
106+
inference_service=http_s3_caikit_raw_inference_service_2,
107+
inference_config=CAIKIT_TGIS_INFERENCE_CONFIG,
108+
inference_type=Inference.ALL_TOKENS,
109+
protocol=Protocols.HTTPS,
110+
)
111+
112+
res = inference.run_inference_flow(
113+
model_name=ModelFormat.CAIKIT, use_default_query=True, token=http_raw_inference_token, insecure=False
114+
)
115+
status_line = res["output"].splitlines()[0]
116+
assert "302 Found" in status_line, f"Expected '302 Found' in status line, got: {status_line}"
117+
else:
118+
verify_inference_response(
119+
inference_service=http_s3_caikit_raw_inference_service_2,
120+
inference_config=CAIKIT_TGIS_INFERENCE_CONFIG,
121+
inference_type=Inference.ALL_TOKENS,
122+
protocol=Protocols.HTTPS,
123+
model_name=ModelFormat.CAIKIT,
124+
use_default_query=True,
125+
token=http_raw_inference_token,
126+
authorized_user=False,
127+
)

0 commit comments

Comments
 (0)