|
| 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 tests |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "k8s.io/apimachinery/pkg/types" |
| 23 | + |
| 24 | + "sigs.k8s.io/gateway-api/conformance/utils/http" |
| 25 | + "sigs.k8s.io/gateway-api/conformance/utils/kubernetes" |
| 26 | + "sigs.k8s.io/gateway-api/conformance/utils/suite" |
| 27 | +) |
| 28 | + |
| 29 | +func init() { |
| 30 | + ConformanceTests = append(ConformanceTests, HTTPRouteResponseHeaderModifier) |
| 31 | +} |
| 32 | + |
| 33 | +var HTTPRouteResponseHeaderModifier = suite.ConformanceTest{ |
| 34 | + ShortName: "HTTPRouteResponseHeaderModifier", |
| 35 | + Description: "An HTTPRoute has response header modifier filters applied correctly", |
| 36 | + Features: []suite.SupportedFeature{suite.SupportHTTPResponseHeaderModification}, |
| 37 | + Manifests: []string{"tests/httproute-response-header-modifier.yaml"}, |
| 38 | + Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { |
| 39 | + ns := "gateway-conformance-infra" |
| 40 | + routeNN := types.NamespacedName{Name: "response-header-modifier", Namespace: ns} |
| 41 | + gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns} |
| 42 | + gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) |
| 43 | + |
| 44 | + testCases := []http.ExpectedResponse{{ |
| 45 | + Request: http.Request{ |
| 46 | + Path: "/set", |
| 47 | + Headers: map[string]string{ |
| 48 | + "Some-Other-Header": "val", |
| 49 | + }, |
| 50 | + }, |
| 51 | + Headers: map[string]string{ |
| 52 | + "Some-Other-Header": "val", |
| 53 | + "X-Header-Set": "set-overwrites-values", |
| 54 | + }, |
| 55 | + Backend: "infra-backend-v1", |
| 56 | + Namespace: ns, |
| 57 | + }, { |
| 58 | + Request: http.Request{ |
| 59 | + Path: "/set", |
| 60 | + Headers: map[string]string{ |
| 61 | + "Some-Other-Header": "val", |
| 62 | + "X-Header-Set": "some-other-value", |
| 63 | + }, |
| 64 | + }, |
| 65 | + Headers: map[string]string{ |
| 66 | + "Some-Other-Header": "val", |
| 67 | + "X-Header-Set": "set-overwrites-values", |
| 68 | + }, |
| 69 | + Backend: "infra-backend-v1", |
| 70 | + Namespace: ns, |
| 71 | + }, { |
| 72 | + Request: http.Request{ |
| 73 | + Path: "/add", |
| 74 | + Headers: map[string]string{ |
| 75 | + "Some-Other-Header": "val", |
| 76 | + }, |
| 77 | + }, |
| 78 | + Headers: map[string]string{ |
| 79 | + "Some-Other-Header": "val", |
| 80 | + "X-Header-Add": "add-appends-values", |
| 81 | + }, |
| 82 | + Backend: "infra-backend-v1", |
| 83 | + Namespace: ns, |
| 84 | + }, { |
| 85 | + Request: http.Request{ |
| 86 | + Path: "/add", |
| 87 | + Headers: map[string]string{ |
| 88 | + "Some-Other-Header": "val", |
| 89 | + "X-Header-Add": "some-other-value", |
| 90 | + }, |
| 91 | + }, |
| 92 | + Headers: map[string]string{ |
| 93 | + "Some-Other-Header": "val", |
| 94 | + "X-Header-Add": "some-other-value,add-appends-values", |
| 95 | + }, |
| 96 | + Backend: "infra-backend-v1", |
| 97 | + Namespace: ns, |
| 98 | + }, { |
| 99 | + Request: http.Request{ |
| 100 | + Path: "/remove", |
| 101 | + Headers: map[string]string{ |
| 102 | + "X-Header-Remove": "val", |
| 103 | + }, |
| 104 | + }, |
| 105 | + Headers: map[string]string{}, |
| 106 | + AbsentHeaders: []string{"X-Header-Remove"}, |
| 107 | + Backend: "infra-backend-v1", |
| 108 | + Namespace: ns, |
| 109 | + }, { |
| 110 | + Request: http.Request{ |
| 111 | + Path: "/multiple", |
| 112 | + Headers: map[string]string{ |
| 113 | + "X-Header-Set-2": "set-val-2", |
| 114 | + "X-Header-Add-2": "add-val-2", |
| 115 | + "X-Header-Remove-2": "remove-val-2", |
| 116 | + "Another-Header": "another-header-val", |
| 117 | + }, |
| 118 | + }, |
| 119 | + Headers: map[string]string{ |
| 120 | + "X-Header-Set-1": "header-set-1", |
| 121 | + "X-Header-Set-2": "header-set-2", |
| 122 | + "X-Header-Add-1": "header-add-1", |
| 123 | + "X-Header-Add-2": "add-val-2,header-add-2", |
| 124 | + "X-Header-Add-3": "header-add-3", |
| 125 | + "Another-Header": "another-header-val", |
| 126 | + }, |
| 127 | + AbsentHeaders: []string{"X-Header-Remove-1", "X-Header-Remove-2"}, |
| 128 | + Backend: "infra-backend-v1", |
| 129 | + Namespace: ns, |
| 130 | + }, { |
| 131 | + Request: http.Request{ |
| 132 | + Path: "/case-insensitivity", |
| 133 | + // The filter uses canonicalized header names, |
| 134 | + // the request uses lowercase names. |
| 135 | + Headers: map[string]string{ |
| 136 | + "x-header-set": "original-val-set", |
| 137 | + "x-header-add": "original-val-add", |
| 138 | + "x-header-remove": "original-val-remove", |
| 139 | + "Another-Header": "another-header-val", |
| 140 | + }, |
| 141 | + }, |
| 142 | + Headers: map[string]string{ |
| 143 | + "X-Header-Set": "header-set", |
| 144 | + "X-Header-Add": "original-val-add,header-add", |
| 145 | + "Another-Header": "another-header-val", |
| 146 | + }, |
| 147 | + AbsentHeaders: []string{"x-header-remove", "X-Header-Remove"}, |
| 148 | + Backend: "infra-backend-v1", |
| 149 | + Namespace: ns, |
| 150 | + }} |
| 151 | + |
| 152 | + for i := range testCases { |
| 153 | + // Declare tc here to avoid loop variable |
| 154 | + // reuse issues across parallel tests. |
| 155 | + tc := testCases[i] |
| 156 | + t.Run(tc.GetTestCaseName(i), func(t *testing.T) { |
| 157 | + t.Parallel() |
| 158 | + http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc) |
| 159 | + }) |
| 160 | + } |
| 161 | + }, |
| 162 | +} |
0 commit comments