Skip to content

Commit

Permalink
fix: httpRoute.match.prefix does not need to end in '/' (#713)
Browse files Browse the repository at this point in the history
* fix: httpRoute.match.prefix does not need to end in '/'

Signed-off-by: Conor Evans <[email protected]>

* fix: update test error message

Signed-off-by: Conor Evans <[email protected]>

---------

Signed-off-by: Conor Evans <[email protected]>
  • Loading branch information
conorevans authored Aug 2, 2023
1 parent 472069b commit 6d3c346
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
4 changes: 2 additions & 2 deletions webhooks/appmesh/gatewayroute_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func validateHTTPRouteRewrite(rewrite *appmesh.HTTPGatewayRouteRewrite, match ap
return errors.New("Both prefix and path for rewrites cannot be specified. Only 1 allowed")
}
if rewrite.Prefix != nil {
if match.Prefix != nil && (!strings.HasSuffix(*match.Prefix, "/") || !strings.HasPrefix(*match.Prefix, "/")) {
return errors.New("Prefix to be matched on must start and end with '/'")
if match.Prefix != nil && !strings.HasPrefix(*match.Prefix, "/") {
return errors.New("Prefix to be matched on must start with '/'")
}
return validatePrefixRewrite(rewrite.Prefix)
}
Expand Down
14 changes: 1 addition & 13 deletions webhooks/appmesh/gatewayroute_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,6 @@ func Test_gatewayRouteValidator_validateHTTPRouteRewrite(t *testing.T) {
},
wantErr: errors.New("Both prefix and path for rewrites cannot be specified. Only 1 allowed"),
},
{
name: "Incorrect Prefix Match format",
match: appmesh.HTTPGatewayRouteMatch{
Prefix: aws.String("/red"),
},
rewrite: appmesh.HTTPGatewayRouteRewrite{
Prefix: &appmesh.GatewayRoutePrefixRewrite{
Value: aws.String("/test/"),
},
},
wantErr: errors.New("Prefix to be matched on must start and end with '/'"),
},
{
name: "Incorrect Prefix Rewrite format",
match: appmesh.HTTPGatewayRouteMatch{
Expand All @@ -374,7 +362,7 @@ func Test_gatewayRouteValidator_validateHTTPRouteRewrite(t *testing.T) {
Value: aws.String("/test/"),
},
},
wantErr: errors.New("Prefix to be matched on must start and end with '/'"),
wantErr: errors.New("Prefix to be matched on must start with '/'"),
},
{
name: "Incorrect Prefix Rewrite format - case2",
Expand Down

0 comments on commit 6d3c346

Please sign in to comment.