Skip to content

Commit 8f83c3d

Browse files
authored
fix: ReplaceFullPath not working for root path (/) (#3530)
* fix: ReplaceFullPath not working for root path (/) Takes #2817 forward Signed-off-by: Arko Dasgupta <[email protected]>
1 parent 607d8bc commit 8f83c3d

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

internal/xds/translator/route.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func buildXdsURLRewriteAction(destName string, urlRewrite *ir.URLRewrite, pathMa
386386
if urlRewrite.Path.FullReplace != nil {
387387
routeAction.RegexRewrite = &matcherv3.RegexMatchAndSubstitute{
388388
Pattern: &matcherv3.RegexMatcher{
389-
Regex: "/.+",
389+
Regex: "^/.*$",
390390
},
391391
Substitution: *urlRewrite.Path.FullReplace,
392392
}

internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-url-fullpath.routes.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
cluster: rewrite-route
1313
regexRewrite:
1414
pattern:
15-
regex: /.+
15+
regex: ^/.*$
1616
substitution: /rewrite
1717
upgradeConfigs:
1818
- upgradeType: websocket
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: rewrite-full-path
5+
namespace: gateway-conformance-infra
6+
spec:
7+
parentRefs:
8+
- name: same-namespace
9+
rules:
10+
- matches:
11+
- path:
12+
type: PathPrefix
13+
value: /
14+
filters:
15+
- type: URLRewrite
16+
urlRewrite:
17+
path:
18+
type: ReplaceFullPath
19+
replaceFullPath: /full-replace
20+
backendRefs:
21+
- name: infra-backend-v1
22+
port: 8080
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright Envoy Gateway Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
// The full text of the Apache license is available in the LICENSE file at
4+
// the root of the repo.
5+
6+
//go:build e2e
7+
// +build e2e
8+
9+
package tests
10+
11+
import (
12+
"testing"
13+
14+
"k8s.io/apimachinery/pkg/types"
15+
"sigs.k8s.io/gateway-api/conformance/utils/http"
16+
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
17+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
18+
)
19+
20+
func init() {
21+
ConformanceTests = append(ConformanceTests, HTTPRouteRewriteFullPath)
22+
}
23+
24+
var HTTPRouteRewriteFullPath = suite.ConformanceTest{
25+
ShortName: "HTTPRouteRewriteFullPath",
26+
Description: "An HTTPRoute with path rewrite filter to replace full path",
27+
Manifests: []string{"testdata/httproute-rewrite-full-path.yaml"},
28+
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
29+
ns := "gateway-conformance-infra"
30+
routeNN := types.NamespacedName{Name: "rewrite-full-path", Namespace: ns}
31+
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
32+
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
33+
kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN)
34+
35+
testCases := []http.ExpectedResponse{
36+
{
37+
Request: http.Request{
38+
Path: "/",
39+
},
40+
ExpectedRequest: &http.ExpectedRequest{
41+
Request: http.Request{
42+
Path: "/full-replace",
43+
},
44+
},
45+
Backend: "infra-backend-v1",
46+
Namespace: ns,
47+
},
48+
}
49+
for i := range testCases {
50+
// Declare tc here to avoid loop variable
51+
// reuse issues across parallel tests.
52+
tc := testCases[i]
53+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
54+
t.Parallel()
55+
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc)
56+
})
57+
}
58+
},
59+
}

0 commit comments

Comments
 (0)