Skip to content

Commit 2c64c87

Browse files
committed
add redirect-port and redirect scheme mesh tests
1 parent 1e14dd6 commit 2c64c87

6 files changed

+344
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package meshtests
18+
19+
import (
20+
"testing"
21+
22+
"sigs.k8s.io/gateway-api/conformance/utils/echo"
23+
"sigs.k8s.io/gateway-api/conformance/utils/http"
24+
"sigs.k8s.io/gateway-api/conformance/utils/roundtripper"
25+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
26+
"sigs.k8s.io/gateway-api/pkg/features"
27+
)
28+
29+
func init() {
30+
MeshConformanceTests = append(MeshConformanceTests, MeshHTTPRouteRedirectPort)
31+
}
32+
33+
var MeshHTTPRouteRedirectPort = suite.ConformanceTest{
34+
ShortName: "MeshHTTPRouteRedirectPort",
35+
Description: "An HTTPRoute with a port redirect filter",
36+
Manifests: []string{"tests/mesh/httproute-redirect-port.yaml"},
37+
Features: []features.FeatureName{
38+
features.SupportMesh,
39+
features.SupportHTTPRoute,
40+
features.SupportMeshHTTPRouteRedirectPort,
41+
},
42+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
43+
ns := "gateway-conformance-mesh"
44+
client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1)
45+
46+
testCases := []http.ExpectedResponse{
47+
{
48+
Request: http.Request{
49+
Host: "echo",
50+
Path: "/port",
51+
UnfollowRedirect: true,
52+
},
53+
Response: http.Response{
54+
StatusCode: 302,
55+
},
56+
RedirectRequest: &roundtripper.RedirectRequest{
57+
Port: "8083",
58+
},
59+
Namespace: ns,
60+
}, {
61+
Request: http.Request{
62+
Host: "echo",
63+
Path: "/port-and-host",
64+
UnfollowRedirect: true,
65+
},
66+
Response: http.Response{
67+
StatusCode: 302,
68+
},
69+
RedirectRequest: &roundtripper.RedirectRequest{
70+
Host: "example.org",
71+
Port: "8083",
72+
},
73+
Namespace: ns,
74+
}, {
75+
Request: http.Request{
76+
Host: "echo",
77+
Path: "/port-and-status",
78+
UnfollowRedirect: true,
79+
},
80+
Response: http.Response{
81+
StatusCode: 301,
82+
},
83+
RedirectRequest: &roundtripper.RedirectRequest{
84+
Port: "8083",
85+
},
86+
Namespace: ns,
87+
}, {
88+
Request: http.Request{
89+
Host: "echo",
90+
Path: "/port-and-host-and-status",
91+
UnfollowRedirect: true,
92+
},
93+
Response: http.Response{
94+
StatusCode: 302,
95+
},
96+
RedirectRequest: &roundtripper.RedirectRequest{
97+
Port: "8083",
98+
Host: "example.org",
99+
},
100+
Namespace: ns,
101+
},
102+
}
103+
for i := range testCases {
104+
// Declare tc here to avoid loop variable
105+
// reuse issues across parallel tests.
106+
tc := testCases[i]
107+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
108+
t.Parallel()
109+
client.MakeRequestAndExpectEventuallyConsistentResponse(t, tc, s.TimeoutConfig)
110+
})
111+
}
112+
},
113+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: mesh-redirect-port
5+
namespace: gateway-conformance-mesh
6+
spec:
7+
parentRefs:
8+
- group: ""
9+
kind: Service
10+
name: echo
11+
port: 80
12+
rules:
13+
- matches:
14+
- path:
15+
type: PathPrefix
16+
value: /port
17+
filters:
18+
- type: RequestRedirect
19+
requestRedirect:
20+
port: 8083
21+
- matches:
22+
- path:
23+
type: PathPrefix
24+
value: /port-and-host
25+
filters:
26+
- type: RequestRedirect
27+
requestRedirect:
28+
hostname: example.org
29+
port: 8083
30+
- matches:
31+
- path:
32+
type: PathPrefix
33+
value: /port-and-status
34+
filters:
35+
- type: RequestRedirect
36+
requestRedirect:
37+
port: 8083
38+
statusCode: 301
39+
- matches:
40+
- path:
41+
type: PathPrefix
42+
value: /port-and-host-and-status
43+
filters:
44+
- type: RequestRedirect
45+
requestRedirect:
46+
port: 8083
47+
hostname: example.org
48+
statusCode: 302
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package meshtests
18+
19+
import (
20+
"testing"
21+
22+
"sigs.k8s.io/gateway-api/conformance/utils/echo"
23+
"sigs.k8s.io/gateway-api/conformance/utils/http"
24+
"sigs.k8s.io/gateway-api/conformance/utils/roundtripper"
25+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
26+
"sigs.k8s.io/gateway-api/pkg/features"
27+
)
28+
29+
func init() {
30+
MeshConformanceTests = append(MeshConformanceTests, MeshHTTPRouteSchemeRedirect)
31+
}
32+
33+
var MeshHTTPRouteSchemeRedirect = suite.ConformanceTest{
34+
ShortName: "MeshHTTPRouteSchemeRedirect",
35+
Description: "An HTTPRoute with a scheme redirect filter",
36+
Manifests: []string{"tests/mesh/httproute-redirect-scheme.yaml"},
37+
Features: []features.FeatureName{
38+
features.SupportMesh,
39+
features.SupportHTTPRoute,
40+
features.SupportMeshHTTPRouteSchemeRedirect,
41+
},
42+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
43+
ns := "gateway-conformance-mesh"
44+
client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1)
45+
46+
testCases := []http.ExpectedResponse{
47+
{
48+
Request: http.Request{
49+
Host: "echo",
50+
Path: "/scheme",
51+
UnfollowRedirect: true,
52+
},
53+
Response: http.Response{
54+
StatusCode: 302,
55+
},
56+
RedirectRequest: &roundtripper.RedirectRequest{
57+
Scheme: "https",
58+
},
59+
Namespace: ns,
60+
},
61+
{
62+
Request: http.Request{
63+
Host: "echo",
64+
Path: "/scheme-and-host",
65+
UnfollowRedirect: true,
66+
},
67+
Response: http.Response{
68+
StatusCode: 302,
69+
},
70+
RedirectRequest: &roundtripper.RedirectRequest{
71+
Host: "example.org",
72+
Scheme: "https",
73+
},
74+
Namespace: ns,
75+
},
76+
{
77+
Request: http.Request{
78+
Host: "echo",
79+
Path: "/scheme-and-status",
80+
UnfollowRedirect: true,
81+
},
82+
Response: http.Response{
83+
StatusCode: 301,
84+
},
85+
RedirectRequest: &roundtripper.RedirectRequest{
86+
Scheme: "https",
87+
},
88+
Namespace: ns,
89+
},
90+
{
91+
Request: http.Request{
92+
Host: "echo",
93+
Path: "/scheme-and-host-and-status",
94+
UnfollowRedirect: true,
95+
},
96+
Response: http.Response{
97+
StatusCode: 302,
98+
},
99+
RedirectRequest: &roundtripper.RedirectRequest{
100+
Scheme: "https",
101+
Host: "example.org",
102+
},
103+
Namespace: ns,
104+
},
105+
}
106+
for i := range testCases {
107+
// Declare tc here to avoid loop variable
108+
// reuse issues across parallel tests.
109+
tc := testCases[i]
110+
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
111+
t.Parallel()
112+
client.MakeRequestAndExpectEventuallyConsistentResponse(t, tc, s.TimeoutConfig)
113+
})
114+
}
115+
},
116+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: mesh-redirect-scheme
5+
namespace: gateway-conformance-mesh
6+
spec:
7+
parentRefs:
8+
- group: ""
9+
kind: Service
10+
name: echo
11+
port: 80
12+
rules:
13+
- matches:
14+
- path:
15+
type: PathPrefix
16+
value: /scheme
17+
filters:
18+
- type: RequestRedirect
19+
requestRedirect:
20+
scheme: "https"
21+
- matches:
22+
- path:
23+
type: PathPrefix
24+
value: /scheme-and-host
25+
filters:
26+
- type: RequestRedirect
27+
requestRedirect:
28+
hostname: example.org
29+
scheme: "https"
30+
- matches:
31+
- path:
32+
type: PathPrefix
33+
value: /scheme-and-status
34+
filters:
35+
- type: RequestRedirect
36+
requestRedirect:
37+
scheme: "https"
38+
statusCode: 301
39+
- matches:
40+
- path:
41+
type: PathPrefix
42+
value: /scheme-and-host-and-status
43+
filters:
44+
- type: RequestRedirect
45+
requestRedirect:
46+
scheme: "https"
47+
statusCode: 302
48+
hostname: example.org
49+

conformance/tests/mesh/httproute-rewrite-path.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ var MeshHTTPRouteRewritePath = suite.ConformanceTest{
3434
Description: "An HTTPRoute with path rewrite filter",
3535
Features: []features.FeatureName{
3636
features.SupportMesh,
37-
features.SupportMeshHTTPRouteRewritePath,
3837
features.SupportHTTPRoute,
38+
features.SupportMeshHTTPRouteRewritePath,
3939
},
4040
Manifests: []string{"tests/mesh/httproute-rewrite-path.yaml"},
4141
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {

pkg/features/mesh.go

+17
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ const (
5050
SupportMeshConsumerRoute FeatureName = "MeshConsumerRoute"
5151
// This option indicates mesh support for HTTPRoute path rewrite (extended conformance)
5252
SupportMeshHTTPRouteRewritePath FeatureName = "MeshHTTPRouteRewritePath"
53+
// This option indicates mesh support for HTTPRoute scheme redirect (extended conformance)
54+
SupportMeshHTTPRouteSchemeRedirect FeatureName = "MeshHTTPRouteSchemeRedirect"
55+
// This option indicates mesh support for HTTPRoute port redirect (extended conformance)
56+
SupportMeshHTTPRouteRedirectPort FeatureName = "MeshHTTPRouteRedirectPort"
5357
)
5458

5559
var (
@@ -69,6 +73,18 @@ var (
6973
Name: SupportMeshHTTPRouteRewritePath,
7074
Channel: FeatureChannelStandard,
7175
}
76+
77+
// MeshHTTPRouteSchemeRedirect contains metadata for the MeshHTTPRouteSchemeRedirect feature.
78+
MeshHTTPRouteSchemeRedirect = Feature{
79+
Name: SupportMeshHTTPRouteRewritePath,
80+
Channel: FeatureChannelStandard,
81+
}
82+
83+
// MeshHTTPRouteRedirectPort contains metadata for the MeshHTTPRouteRedirectPort feature.
84+
MeshHTTPRouteRedirectPort = Feature{
85+
Name: SupportMeshHTTPRouteRedirectPort,
86+
Channel: FeatureChannelStandard,
87+
}
7288
)
7389

7490
// MeshExtendedFeatures includes all the supported features for the service mesh at
@@ -77,4 +93,5 @@ var MeshExtendedFeatures = sets.New(
7793
MeshClusterIPMatchingFeature,
7894
MeshConsumerRouteFeature,
7995
MeshHTTPRouteRewritePath,
96+
MeshHTTPRouteSchemeRedirect,
8097
)

0 commit comments

Comments
 (0)