|
| 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 | +} |
0 commit comments