Skip to content

Commit da9028a

Browse files
authored
test: Add more test cases to validate model name while loading (#8701)
This PR adds more test cases to validate model name while loading: Test cover cases " .." and ".. ". Remove leading and trailing whitespace from model name before checking for path traversal characters. Names with dots like "model..", "...", "..model" are valid according to the POSIX standard. Test checks those
1 parent 4c4b3ae commit da9028a

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

qa/L0_input_validation/input_validation_test.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ class ModelNameValidationTest(unittest.TestCase):
306306
def test_model_name_invalid_load(self):
307307
client = tritongrpcclient.InferenceServerClient("localhost:8001")
308308
for model_name in self.INVALID_TRAVERSAL_NAMES:
309+
print(f"Testing model name: {model_name!r}")
309310
with self.assertRaises(InferenceServerException) as cm:
310311
client.load_model(model_name)
311312
self.assertIn(
@@ -318,7 +319,10 @@ def test_model_name_empty_load(self):
318319
client = tritongrpcclient.InferenceServerClient("localhost:8001")
319320
with self.assertRaises(InferenceServerException) as cm:
320321
client.load_model("")
321-
self.assertIn("model name must not be empty", str(cm.exception))
322+
self.assertIn(
323+
"Model name cannot be empty. Please enter a valid name to deploy.",
324+
str(cm.exception),
325+
)
322326

323327
def test_model_name_whitespace_only_load(self):
324328
client = tritongrpcclient.InferenceServerClient("localhost:8001")
@@ -327,7 +331,7 @@ def test_model_name_whitespace_only_load(self):
327331
with self.assertRaises(InferenceServerException) as cm:
328332
client.load_model(model_name)
329333
self.assertIn(
330-
"model name must not contain only whitespace",
334+
"Model name cannot be empty. Please enter a valid name to deploy.",
331335
str(cm.exception),
332336
f"Expected whitespace-only rejection for model name: {model_name!r}",
333337
)
@@ -348,15 +352,25 @@ def test_model_name_invalid_unload(self):
348352
def test_model_name_valid(self):
349353
"""Verify that a syntactically valid model name is not rejected by
350354
the traversal check -- it should fail with a model not found error instead."""
355+
VALID_MODEL_NAMES = [
356+
"model123",
357+
# "model OAI", TRI-769: Fix this test case
358+
"model.version1",
359+
"...",
360+
"..my_model",
361+
"model..1",
362+
"model....1",
363+
]
351364
client = tritongrpcclient.InferenceServerClient("localhost:8001")
352-
with self.assertRaises(InferenceServerException) as cm:
353-
client.load_model("nonexistent_model")
354-
self.assertNotIn(
355-
"path traversal characters",
356-
str(cm.exception),
357-
"Valid model name should not trigger path traversal rejection",
358-
)
359-
self.assertIn("failed to poll from model repository", str(cm.exception))
365+
for model_name in VALID_MODEL_NAMES:
366+
with self.assertRaises(InferenceServerException) as cm:
367+
client.load_model(model_name)
368+
self.assertNotIn(
369+
"path traversal characters",
370+
str(cm.exception),
371+
"Valid model name should not trigger path traversal rejection",
372+
)
373+
self.assertIn("failed to poll from model repository", str(cm.exception))
360374

361375

362376
if __name__ == "__main__":

0 commit comments

Comments
 (0)