Skip to content

Commit

Permalink
Test validation for wildcard match in middle of path (#23752)
Browse files Browse the repository at this point in the history
Test validation for wildcard match in middle of path

Additional Description:
Pattern matching does not support wildcard matching in the middle of a path. This test checks that it is not allowed in config.

Signed-off-by: silverstar195 <seanmaloney@google.com>
  • Loading branch information
silverstar194 authored Oct 31, 2022
1 parent 66e5e6f commit 6b7c95d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/common/router/config_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9314,6 +9314,35 @@ TEST_F(RouteMatcherTest, PatternMatchInvalidVariableName) {
EnvoyException, "path_match_policy.path_template /rest/{on==e}/{two} is invalid");
}

TEST_F(RouteMatcherTest, PatternMatchInvalidPlacedWildcard) {
const std::string yaml = R"EOF(
virtual_hosts:
- name: path_pattern
domains: ["*"]
routes:
- match:
path_match_policy:
name: envoy.path.match.uri_template.pattern_template_match_predicate
typed_config:
"@type": type.googleapis.com/envoy.extensions.path.match.uri_template.v3.UriTemplateMatchConfig
path_template: "/rest/{middlewildcard=**}/{two}"
case_sensitive: false
route:
cluster: "path-pattern-cluster-one"
path_rewrite_policy:
name: envoy.path.rewrite.uri_template.pattern_template_rewrite_predicate
typed_config:
"@type": type.googleapis.com/envoy.extensions.path.rewrite.uri_template.v3.UriTemplateRewriteConfig
path_template_rewrite: "/rest/{middlewildcard=**}/{two}"
)EOF";
NiceMock<Envoy::StreamInfo::MockStreamInfo> stream_info;
factory_context_.cluster_manager_.initializeClusters({"path-pattern-cluster-one"}, {});

EXPECT_THROW_WITH_MESSAGE(
TestConfigImpl config(parseRouteConfigurationFromYaml(yaml), factory_context_, true),
EnvoyException, "path_match_policy.path_template /rest/{middlewildcard=**}/{two} is invalid");
}

TEST_F(RouteMatcherTest, PatternMatchWildcardUnnamedVariable) {
const std::string yaml = R"EOF(
virtual_hosts:
Expand Down

0 comments on commit 6b7c95d

Please sign in to comment.