Skip to content

Add mesh conformance tests for httproute path host and status redirect #3777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions conformance/tests/mesh/httproute-redirect-host-and-status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package meshtests

import (
"testing"

"sigs.k8s.io/gateway-api/conformance/utils/echo"
"sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/roundtripper"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/pkg/features"
)

func init() {
MeshConformanceTests = append(MeshConformanceTests, MeshHTTPRouteRedirectHostAndStatus)
}

var MeshHTTPRouteRedirectHostAndStatus = suite.ConformanceTest{
ShortName: "MeshHTTPRouteRedirectHostAndStatus",
Description: "An HTTPRoute with hostname and statusCode redirect filters",
Features: []features.FeatureName{
features.SupportMesh,
features.SupportHTTPRoute,
},
Manifests: []string{"tests/mesh/httproute-redirect-host-and-status.yaml"},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
ns := "gateway-conformance-mesh"
client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1)

testCases := []http.ExpectedResponse{
{
Request: http.Request{
Host: "echo",
Path: "/hostname-redirect",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 302,
},
RedirectRequest: &roundtripper.RedirectRequest{
Host: "example.org",
},
Namespace: ns,
}, {
Request: http.Request{
Host: "echo",
Path: "/host-and-status",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 301,
},
RedirectRequest: &roundtripper.RedirectRequest{
Host: "example.org",
},
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()
client.MakeRequestAndExpectEventuallyConsistentResponse(t, tc, s.TimeoutConfig)
})
}
},
}
30 changes: 30 additions & 0 deletions conformance/tests/mesh/httproute-redirect-host-and-status.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: mesh-redirect-host-and-status
namespace: gateway-conformance-mesh
spec:
parentRefs:
- group: ""
kind: Service
name: echo
port: 80
rules:
- matches:
- path:
type: PathPrefix
value: /hostname-redirect
filters:
- type: RequestRedirect
requestRedirect:
hostname: example.org
- matches:
- path:
type: PathPrefix
value: /host-and-status
filters:
- type: RequestRedirect
requestRedirect:
statusCode: 301
hostname: example.org

139 changes: 139 additions & 0 deletions conformance/tests/mesh/httproute-redirect-path.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package meshtests

import (
"testing"

"sigs.k8s.io/gateway-api/conformance/utils/echo"
"sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/roundtripper"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/pkg/features"
)

func init() {
MeshConformanceTests = append(MeshConformanceTests, MeshHTTPRouteRedirectPath)
}

var MeshHTTPRouteRedirectPath = suite.ConformanceTest{
ShortName: "MeshHTTPRouteRedirectPath",
Description: "An HTTPRoute with scheme redirect filter",
Manifests: []string{"tests/mesh/httproute-redirect-path.yaml"},
Features: []features.FeatureName{
features.SupportMesh,
features.SupportHTTPRoute,
features.SupportMeshHTTPRouteRedirectPath,
},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
ns := "gateway-conformance-mesh"
client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1)

testCases := []http.ExpectedResponse{
{
Request: http.Request{
Host: "echo",
Path: "/original-prefix/lemon",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 302,
},
RedirectRequest: &roundtripper.RedirectRequest{
Path: "/replacement-prefix/lemon",
},
Namespace: ns,
}, {
Request: http.Request{
Host: "echo",
Path: "/full/path/original",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 302,
},
RedirectRequest: &roundtripper.RedirectRequest{
Path: "/full-path-replacement",
},
Namespace: ns,
}, {
Request: http.Request{
Host: "echo",
Path: "/path-and-host",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 302,
},
RedirectRequest: &roundtripper.RedirectRequest{
Host: "example.org",
Path: "/replacement-prefix",
},
Namespace: ns,
}, {
Request: http.Request{
Host: "echo",
Path: "/path-and-status",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 301,
},
RedirectRequest: &roundtripper.RedirectRequest{
Path: "/replacement-prefix",
},
Namespace: ns,
}, {
Request: http.Request{
Host: "echo",
Path: "/full-path-and-host",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 302,
},
RedirectRequest: &roundtripper.RedirectRequest{
Host: "example.org",
Path: "/replacement-full",
},
Namespace: ns,
}, {
Request: http.Request{
Host: "echo",
Path: "/full-path-and-status",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 301,
},
RedirectRequest: &roundtripper.RedirectRequest{
Path: "/replacement-full",
},
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()
client.MakeRequestAndExpectEventuallyConsistentResponse(t, tc, s.TimeoutConfig)
})
}
},
}
76 changes: 76 additions & 0 deletions conformance/tests/mesh/httproute-redirect-path.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: mesh-redirect-path
namespace: gateway-conformance-mesh
spec:
parentRefs:
- group: ""
kind: Service
name: echo
port: 80
rules:
- matches:
- path:
type: PathPrefix
value: /original-prefix
filters:
- type: RequestRedirect
requestRedirect:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /replacement-prefix
- matches:
- path:
type: PathPrefix
value: /full
filters:
- type: RequestRedirect
requestRedirect:
path:
type: ReplaceFullPath
replaceFullPath: /full-path-replacement
- matches:
- path:
type: PathPrefix
value: /path-and-host
filters:
- type: RequestRedirect
requestRedirect:
hostname: example.org
path:
type: ReplacePrefixMatch
replacePrefixMatch: /replacement-prefix
- matches:
- path:
type: PathPrefix
value: /path-and-status
filters:
- type: RequestRedirect
requestRedirect:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /replacement-prefix
statusCode: 301
- matches:
- path:
type: PathPrefix
value: /full-path-and-host
filters:
- type: RequestRedirect
requestRedirect:
hostname: example.org
path:
type: ReplaceFullPath
replaceFullPath: /replacement-full
- matches:
- path:
type: PathPrefix
value: /full-path-and-status
filters:
- type: RequestRedirect
requestRedirect:
path:
type: ReplaceFullPath
replaceFullPath: /replacement-full
statusCode: 301
Loading