@@ -2,8 +2,8 @@ use rivet_guard::routing::parse_actor_path;
22
33#[ test]
44fn test_parse_actor_path_with_token ( ) {
5- // Basic path with token and route
6- let path = "/gateway/actors/ actor-123/tokens/ my-token/route /api/v1/endpoint" ;
5+ // Basic path with token using @ syntax
6+ let path = "/gateway/actor-123@ my-token/api/v1/endpoint" ;
77 let result = parse_actor_path ( path) . unwrap ( ) ;
88 assert_eq ! ( result. actor_id, "actor-123" ) ;
99 assert_eq ! ( result. token, Some ( "my-token" . to_string( ) ) ) ;
@@ -13,7 +13,7 @@ fn test_parse_actor_path_with_token() {
1313#[ test]
1414fn test_parse_actor_path_without_token ( ) {
1515 // Path without token
16- let path = "/gateway/actors/ actor-123/route /api/v1/endpoint" ;
16+ let path = "/gateway/actor-123/api/v1/endpoint" ;
1717 let result = parse_actor_path ( path) . unwrap ( ) ;
1818 assert_eq ! ( result. actor_id, "actor-123" ) ;
1919 assert_eq ! ( result. token, None ) ;
@@ -23,7 +23,7 @@ fn test_parse_actor_path_without_token() {
2323#[ test]
2424fn test_parse_actor_path_with_uuid ( ) {
2525 // Path with UUID as actor ID
26- let path = "/gateway/actors/ 12345678-1234-1234-1234-123456789abc/route /status" ;
26+ let path = "/gateway/12345678-1234-1234-1234-123456789abc/status" ;
2727 let result = parse_actor_path ( path) . unwrap ( ) ;
2828 assert_eq ! ( result. actor_id, "12345678-1234-1234-1234-123456789abc" ) ;
2929 assert_eq ! ( result. token, None ) ;
@@ -33,14 +33,14 @@ fn test_parse_actor_path_with_uuid() {
3333#[ test]
3434fn test_parse_actor_path_with_query_params ( ) {
3535 // Path with query parameters
36- let path = "/gateway/actors/ actor-456/route /api/endpoint?foo=bar&baz=qux" ;
36+ let path = "/gateway/actor-456/api/endpoint?foo=bar&baz=qux" ;
3737 let result = parse_actor_path ( path) . unwrap ( ) ;
3838 assert_eq ! ( result. actor_id, "actor-456" ) ;
3939 assert_eq ! ( result. token, None ) ;
4040 assert_eq ! ( result. remaining_path, "/api/endpoint?foo=bar&baz=qux" ) ;
4141
4242 // Path with token and query parameters
43- let path = "/gateway/actors/ actor-456/tokens/ token123/route /api?key=value" ;
43+ let path = "/gateway/actor-456@ token123/api?key=value" ;
4444 let result = parse_actor_path ( path) . unwrap ( ) ;
4545 assert_eq ! ( result. actor_id, "actor-456" ) ;
4646 assert_eq ! ( result. token, Some ( "token123" . to_string( ) ) ) ;
@@ -50,7 +50,7 @@ fn test_parse_actor_path_with_query_params() {
5050#[ test]
5151fn test_parse_actor_path_with_fragment ( ) {
5252 // Path with fragment
53- let path = "/gateway/actors/ actor-789/route /page#section" ;
53+ let path = "/gateway/actor-789/page#section" ;
5454 let result = parse_actor_path ( path) . unwrap ( ) ;
5555 assert_eq ! ( result. actor_id, "actor-789" ) ;
5656 assert_eq ! ( result. token, None ) ;
@@ -60,15 +60,15 @@ fn test_parse_actor_path_with_fragment() {
6060
6161#[ test]
6262fn test_parse_actor_path_empty_remaining ( ) {
63- // Path with no remaining path after route
64- let path = "/gateway/actors/ actor-000/route " ;
63+ // Path with no remaining path
64+ let path = "/gateway/actor-000" ;
6565 let result = parse_actor_path ( path) . unwrap ( ) ;
6666 assert_eq ! ( result. actor_id, "actor-000" ) ;
6767 assert_eq ! ( result. token, None ) ;
6868 assert_eq ! ( result. remaining_path, "/" ) ;
6969
7070 // With token and no remaining path
71- let path = "/gateway/actors/ actor-000/tokens/ tok/route " ;
71+ let path = "/gateway/actor-000@ tok" ;
7272 let result = parse_actor_path ( path) . unwrap ( ) ;
7373 assert_eq ! ( result. actor_id, "actor-000" ) ;
7474 assert_eq ! ( result. token, Some ( "tok" . to_string( ) ) ) ;
@@ -78,7 +78,7 @@ fn test_parse_actor_path_empty_remaining() {
7878#[ test]
7979fn test_parse_actor_path_with_trailing_slash ( ) {
8080 // Path with trailing slash
81- let path = "/gateway/actors/ actor-111/route /api/" ;
81+ let path = "/gateway/actor-111/api/" ;
8282 let result = parse_actor_path ( path) . unwrap ( ) ;
8383 assert_eq ! ( result. actor_id, "actor-111" ) ;
8484 assert_eq ! ( result. token, None ) ;
@@ -88,8 +88,7 @@ fn test_parse_actor_path_with_trailing_slash() {
8888#[ test]
8989fn test_parse_actor_path_complex_remaining ( ) {
9090 // Complex remaining path with multiple segments
91- let path =
92- "/gateway/actors/actor-complex/tokens/secure-token/route/api/v2/users/123/profile/settings" ;
91+ let path = "/gateway/actor-complex@secure-token/api/v2/users/123/profile/settings" ;
9392 let result = parse_actor_path ( path) . unwrap ( ) ;
9493 assert_eq ! ( result. actor_id, "actor-complex" ) ;
9594 assert_eq ! ( result. token, Some ( "secure-token" . to_string( ) ) ) ;
@@ -99,7 +98,7 @@ fn test_parse_actor_path_complex_remaining() {
9998#[ test]
10099fn test_parse_actor_path_special_characters ( ) {
101100 // Actor ID with allowed special characters
102- let path = "/gateway/actors/ actor_id-123.test/route /endpoint" ;
101+ let path = "/gateway/actor_id-123.test/endpoint" ;
103102 let result = parse_actor_path ( path) . unwrap ( ) ;
104103 assert_eq ! ( result. actor_id, "actor_id-123.test" ) ;
105104 assert_eq ! ( result. token, None ) ;
@@ -109,7 +108,7 @@ fn test_parse_actor_path_special_characters() {
109108#[ test]
110109fn test_parse_actor_path_encoded_characters ( ) {
111110 // URL encoded characters in path
112- let path = "/gateway/actors/ actor-123/route /api%20endpoint/test%2Fpath" ;
111+ let path = "/gateway/actor-123/api%20endpoint/test%2Fpath" ;
113112 let result = parse_actor_path ( path) . unwrap ( ) ;
114113 assert_eq ! ( result. actor_id, "actor-123" ) ;
115114 assert_eq ! ( result. token, None ) ;
@@ -121,70 +120,48 @@ fn test_parse_actor_path_encoded_characters() {
121120#[ test]
122121fn test_parse_actor_path_invalid_prefix ( ) {
123122 // Wrong prefix
124- assert ! ( parse_actor_path( "/api/actors/123/route/endpoint" ) . is_none( ) ) ;
125- assert ! ( parse_actor_path( "/gateway/actor/123/route/endpoint" ) . is_none( ) ) ;
126- assert ! ( parse_actor_path( "/actors/123/route/endpoint" ) . is_none( ) ) ;
127- }
128-
129- #[ test]
130- fn test_parse_actor_path_missing_route ( ) {
131- // Missing route keyword
132- assert ! ( parse_actor_path( "/gateway/actors/123" ) . is_none( ) ) ;
133- assert ! ( parse_actor_path( "/gateway/actors/123/endpoint" ) . is_none( ) ) ;
134- assert ! ( parse_actor_path( "/gateway/actors/123/tokens/tok" ) . is_none( ) ) ;
123+ assert ! ( parse_actor_path( "/api/123/endpoint" ) . is_none( ) ) ;
124+ assert ! ( parse_actor_path( "/actor/123/endpoint" ) . is_none( ) ) ;
135125}
136126
137127#[ test]
138128fn test_parse_actor_path_too_short ( ) {
139129 // Too few segments
140130 assert ! ( parse_actor_path( "/gateway" ) . is_none( ) ) ;
141- assert ! ( parse_actor_path( "/gateway/actors" ) . is_none( ) ) ;
142- assert ! ( parse_actor_path( "/gateway/actors/123" ) . is_none( ) ) ;
143131}
144132
145133#[ test]
146- fn test_parse_actor_path_malformed_token_path ( ) {
147- // Token path but missing route
148- assert ! ( parse_actor_path( "/gateway/actors/123/tokens/tok/api" ) . is_none( ) ) ;
149- // Token without value
150- assert ! ( parse_actor_path( "/gateway/actors/123/tokens//route/api" ) . is_none( ) ) ;
151- }
152-
153- #[ test]
154- fn test_parse_actor_path_wrong_segment_positions ( ) {
155- // Segments in wrong positions
156- assert ! ( parse_actor_path( "/actors/gateway/123/route/endpoint" ) . is_none( ) ) ;
157- assert ! ( parse_actor_path( "/gateway/route/actors/123/endpoint" ) . is_none( ) ) ;
134+ fn test_parse_actor_path_malformed_token ( ) {
135+ // Token without actor_id (empty before @)
136+ assert ! ( parse_actor_path( "/gateway/@tok/api" ) . is_none( ) ) ;
137+ // Empty token (nothing after @)
138+ assert ! ( parse_actor_path( "/gateway/actor-123@/api" ) . is_none( ) ) ;
158139}
159140
160141#[ test]
161142fn test_parse_actor_path_empty_values ( ) {
162143 // Empty actor_id
163- assert ! ( parse_actor_path( "/gateway/actors//route/endpoint" ) . is_none( ) ) ;
164- assert ! ( parse_actor_path( "/gateway/actors//tokens/tok/route/endpoint" ) . is_none( ) ) ;
144+ assert ! ( parse_actor_path( "/gateway//endpoint" ) . is_none( ) ) ;
165145}
166146
167147#[ test]
168148fn test_parse_actor_path_double_slash ( ) {
169149 // Double slashes in path
170- let path = "/gateway/actors// actor-123/route /endpoint" ;
150+ let path = "/gateway// actor-123/endpoint" ;
171151 // This will fail because the double slash creates an empty segment
172152 assert ! ( parse_actor_path( path) . is_none( ) ) ;
173153}
174154
175155#[ test]
176156fn test_parse_actor_path_case_sensitive ( ) {
177157 // Keywords are case sensitive
178- assert ! ( parse_actor_path( "/Gateway/actors/123/route/endpoint" ) . is_none( ) ) ;
179- assert ! ( parse_actor_path( "/gateway/Actors/123/route/endpoint" ) . is_none( ) ) ;
180- assert ! ( parse_actor_path( "/gateway/actors/123/Route/endpoint" ) . is_none( ) ) ;
181- assert ! ( parse_actor_path( "/gateway/actors/123/tokens/tok/Route/endpoint" ) . is_none( ) ) ;
158+ assert ! ( parse_actor_path( "/Gateway/123/endpoint" ) . is_none( ) ) ;
182159}
183160
184161#[ test]
185162fn test_parse_actor_path_query_and_fragment ( ) {
186163 // Path with both query and fragment
187- let path = "/gateway/actors/ actor-123/route /api?query=1#section" ;
164+ let path = "/gateway/actor-123/api?query=1#section" ;
188165 let result = parse_actor_path ( path) . unwrap ( ) ;
189166 assert_eq ! ( result. actor_id, "actor-123" ) ;
190167 assert_eq ! ( result. token, None ) ;
@@ -194,10 +171,30 @@ fn test_parse_actor_path_query_and_fragment() {
194171
195172#[ test]
196173fn test_parse_actor_path_only_query_string ( ) {
197- // Path ending with route but having query string
198- let path = "/gateway/actors/ actor-123/route ?direct=true" ;
174+ // Path ending after actor_id but having query string
175+ let path = "/gateway/actor-123?direct=true" ;
199176 let result = parse_actor_path ( path) . unwrap ( ) ;
200177 assert_eq ! ( result. actor_id, "actor-123" ) ;
201178 assert_eq ! ( result. token, None ) ;
202179 assert_eq ! ( result. remaining_path, "/?direct=true" ) ;
203180}
181+
182+ #[ test]
183+ fn test_parse_actor_path_token_with_special_chars ( ) {
184+ // Token containing special characters
185+ let path = "/gateway/actor-123@token_with-chars.123/endpoint" ;
186+ let result = parse_actor_path ( path) . unwrap ( ) ;
187+ assert_eq ! ( result. actor_id, "actor-123" ) ;
188+ assert_eq ! ( result. token, Some ( "token_with-chars.123" . to_string( ) ) ) ;
189+ assert_eq ! ( result. remaining_path, "/endpoint" ) ;
190+ }
191+
192+ #[ test]
193+ fn test_parse_actor_path_multiple_at_signs ( ) {
194+ // Multiple @ signs - only first one is used for token splitting
195+ let path = "/gateway/actor-123@token@with@ats/endpoint" ;
196+ let result = parse_actor_path ( path) . unwrap ( ) ;
197+ assert_eq ! ( result. actor_id, "actor-123" ) ;
198+ assert_eq ! ( result. token, Some ( "token@with@ats" . to_string( ) ) ) ;
199+ assert_eq ! ( result. remaining_path, "/endpoint" ) ;
200+ }
0 commit comments