diff --git a/golem-worker-service-base/src/gateway_api_definition/http/http_api_definition.rs b/golem-worker-service-base/src/gateway_api_definition/http/http_api_definition.rs index 119be7d95d..1d9089be22 100644 --- a/golem-worker-service-base/src/gateway_api_definition/http/http_api_definition.rs +++ b/golem-worker-service-base/src/gateway_api_definition/http/http_api_definition.rs @@ -330,8 +330,14 @@ impl FromStr for AllPathPatterns { fn from_str(s: &str) -> Result { parse_path_pattern(s) - .map(|(_, result)| result) .map_err(|err| err.to_string()) + .and_then(|(leftover, result)| { + if !leftover.is_empty() { + Err("Failed to parse path".to_string()) + } else { + Ok(result) + } + }) } } @@ -519,7 +525,7 @@ mod tests { #[test] fn split_path_works_with_single_value() { - let path_pattern = "foo"; + let path_pattern = "/foo"; let result = AllPathPatterns::parse(path_pattern); let expected = AllPathPatterns { @@ -532,7 +538,7 @@ mod tests { #[test] fn split_path_works_with_multiple_values() { - let path_pattern = "foo/bar"; + let path_pattern = "/foo/bar"; let result = AllPathPatterns::parse(path_pattern); let expected = AllPathPatterns { @@ -545,7 +551,7 @@ mod tests { #[test] fn split_path_works_with_variables() { - let path_pattern = "foo/bar/{var}"; + let path_pattern = "/foo/bar/{var}"; let result = AllPathPatterns::parse(path_pattern); let expected = AllPathPatterns { @@ -562,7 +568,7 @@ mod tests { #[test] fn split_path_works_with_variables_and_queries() { - let path_pattern = "foo/bar/{var}?{userid1}&{userid2}"; + let path_pattern = "/foo/bar/{var}?{userid1}&{userid2}"; let result = AllPathPatterns::parse(path_pattern); let expected = AllPathPatterns { @@ -741,22 +747,22 @@ mod tests { assert_eq!(core_http_definition, decoded); } test_encode_decode( - "foo/{user-id}", + "/foo/{user-id}", "let x: str = request.path.user-id; \"shopping-cart-${if x>100 then 0 else 1}\"", "${ let result = golem:it/api.{do-something}(request.body); {status: if result.user == \"admin\" then 401 else 200 } }", ); test_encode_decode( - "foo/{user-id}", + "/foo/{user-id}", "let x: str = request.path.user-id; \"shopping-cart-${if x>100 then 0 else 1}\"", "${ let result = golem:it/api.{do-something}(request.body.foo); {status: if result.user == \"admin\" then 401 else 200 } }", ); test_encode_decode( - "foo/{user-id}", + "/foo/{user-id}", "let x: str = request.path.user-id; \"shopping-cart-${if x>100 then 0 else 1}\"", "${ let result = golem:it/api.{do-something}(request.path.user-id); {status: if result.user == \"admin\" then 401 else 200 } }", ); test_encode_decode( - "foo", + "/foo", "let x: str = request.body.user-id; \"shopping-cart-${if x>100 then 0 else 1}\"", "${ let result = golem:it/api.{do-something}(\"foo\"); {status: if result.user == \"admin\" then 401 else 200 } }", ); diff --git a/golem-worker-service-base/src/gateway_api_definition/http/path_pattern_parser.rs b/golem-worker-service-base/src/gateway_api_definition/http/path_pattern_parser.rs index f1ca1ee56c..3293461e94 100644 --- a/golem-worker-service-base/src/gateway_api_definition/http/path_pattern_parser.rs +++ b/golem-worker-service-base/src/gateway_api_definition/http/path_pattern_parser.rs @@ -180,6 +180,6 @@ mod tests { ); // {+var} is not allowed in the middle of the path - assert!(parse_path_pattern("/api/{foo}/{+others}/{bar}").is_err()); + assert!(AllPathPatterns::parse("/api/{foo}/{+others}/{bar}").is_err()); } }