From 6d3c346a4980d82e556a562a3763bf44c9886659 Mon Sep 17 00:00:00 2001 From: Conor Evans <43791257+conorevans@users.noreply.github.com> Date: Thu, 3 Aug 2023 00:32:51 +0100 Subject: [PATCH] fix: httpRoute.match.prefix does not need to end in '/' (#713) * fix: httpRoute.match.prefix does not need to end in '/' Signed-off-by: Conor Evans * fix: update test error message Signed-off-by: Conor Evans --------- Signed-off-by: Conor Evans --- webhooks/appmesh/gatewayroute_validator.go | 4 ++-- webhooks/appmesh/gatewayroute_validator_test.go | 14 +------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/webhooks/appmesh/gatewayroute_validator.go b/webhooks/appmesh/gatewayroute_validator.go index ec8cd1f3..f8fde890 100644 --- a/webhooks/appmesh/gatewayroute_validator.go +++ b/webhooks/appmesh/gatewayroute_validator.go @@ -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) } diff --git a/webhooks/appmesh/gatewayroute_validator_test.go b/webhooks/appmesh/gatewayroute_validator_test.go index 1a40c503..86f564a6 100644 --- a/webhooks/appmesh/gatewayroute_validator_test.go +++ b/webhooks/appmesh/gatewayroute_validator_test.go @@ -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{ @@ -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",