Skip to content

Commit

Permalink
fix: ReplaceFullPath not working for root path (/) (envoyproxy#3530)
Browse files Browse the repository at this point in the history
* fix: ReplaceFullPath not working for root path (/)

Takes envoyproxy#2817 forward

Signed-off-by: Arko Dasgupta <[email protected]>
(cherry picked from commit 8f83c3d)
Signed-off-by: Arko Dasgupta <[email protected]>
  • Loading branch information
arkodg committed Jun 12, 2024
1 parent 86bb0cc commit 9957cb7
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/xds/translator/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func buildXdsURLRewriteAction(destName string, urlRewrite *ir.URLRewrite, pathMa
if urlRewrite.Path.FullReplace != nil {
routeAction.RegexRewrite = &matcherv3.RegexMatchAndSubstitute{
Pattern: &matcherv3.RegexMatcher{
Regex: "/.+",
Regex: "^/.*$",
},
Substitution: *urlRewrite.Path.FullReplace,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
cluster: rewrite-route
regexRewrite:
pattern:
regex: /.+
regex: ^/.*$
substitution: /rewrite
upgradeConfigs:
- upgradeType: websocket
22 changes: 22 additions & 0 deletions test/e2e/testdata/httproute-rewrite-full-path.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: rewrite-full-path
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: same-namespace
rules:
- matches:
- path:
type: PathPrefix
value: /
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplaceFullPath
replaceFullPath: /full-replace
backendRefs:
- name: infra-backend-v1
port: 8080
59 changes: 59 additions & 0 deletions test/e2e/tests/httproute-rewrite-full-path.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

//go:build e2e
// +build e2e

package tests

import (
"testing"

"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
)

func init() {
ConformanceTests = append(ConformanceTests, HTTPRouteRewriteFullPath)
}

var HTTPRouteRewriteFullPath = suite.ConformanceTest{
ShortName: "HTTPRouteRewriteFullPath",
Description: "An HTTPRoute with path rewrite filter to replace full path",
Manifests: []string{"testdata/httproute-rewrite-full-path.yaml"},
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
ns := "gateway-conformance-infra"
routeNN := types.NamespacedName{Name: "rewrite-full-path", Namespace: ns}
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN)

testCases := []http.ExpectedResponse{
{
Request: http.Request{
Path: "/",
},
ExpectedRequest: &http.ExpectedRequest{
Request: http.Request{
Path: "/full-replace",
},
},
Backend: "infra-backend-v1",
Namespace: ns,
},
}
for i := range testCases {
// Declare tc here to avoid loop variable
// reuse issues across parallel tests.
tc := testCases[i]
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
t.Parallel()
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc)
})
}
},
}

0 comments on commit 9957cb7

Please sign in to comment.