@@ -25,31 +25,51 @@ class TestJailbreakRequestChanges:
2525 """Test jailbreak request function changes introduced in this PR."""
2626
2727 def test_url_joining_logic (self ):
28- """Test that URL joining works correctly using urljoin."""
28+ """Test that URL joining works correctly with all slash combinations."""
29+ from nemoguardrails .library .jailbreak_detection .request import join_nim_url
30+
2931 test_cases = [
3032 (
3133 "http://localhost:8000/v1" ,
3234 "classify" ,
33- "http://localhost:8000/classify" ,
34- ), # v1 replaced by classify
35+ "http://localhost:8000/v1/ classify" ,
36+ ),
3537 (
3638 "http://localhost:8000/v1/" ,
3739 "classify" ,
3840 "http://localhost:8000/v1/classify" ,
39- ), # trailing slash preserves v1
41+ ),
42+ (
43+ "http://localhost:8000/v1" ,
44+ "/classify" ,
45+ "http://localhost:8000/v1/classify" ,
46+ ),
4047 (
41- "http://localhost:8000" ,
42- "v1 /classify" ,
48+ "http://localhost:8000/v1/ " ,
49+ "/classify" ,
4350 "http://localhost:8000/v1/classify" ,
4451 ),
52+ ("http://localhost:8000" , "classify" , "http://localhost:8000/classify" ),
53+ ("http://localhost:8000" , "/classify" , "http://localhost:8000/classify" ),
54+ ("http://localhost:8000/" , "classify" , "http://localhost:8000/classify" ),
4555 ("http://localhost:8000/" , "/classify" , "http://localhost:8000/classify" ),
56+ (
57+ "http://localhost:8000/api/v1" ,
58+ "classify" ,
59+ "http://localhost:8000/api/v1/classify" ,
60+ ),
61+ (
62+ "http://localhost:8000/api/v1/" ,
63+ "/classify" ,
64+ "http://localhost:8000/api/v1/classify" ,
65+ ),
4666 ]
4767
48- for base_url , path , expected_url in test_cases :
49- result = urljoin (base_url , path )
68+ for base_url , classification_path , expected_url in test_cases :
69+ result = join_nim_url (base_url , classification_path )
5070 assert (
5171 result == expected_url
52- ), f"urljoin ({ base_url } , { path } ) should equal { expected_url } "
72+ ), f"join_nim_url ({ base_url } , { classification_path } ) should equal { expected_url } , got { result } "
5373
5474 def test_auth_header_logic (self ):
5575 """Test the authorization header logic."""
0 commit comments