@@ -154,6 +154,52 @@ var APIKeyAuthTest = suite.ConformanceTest{
154
154
Namespace : ns ,
155
155
}
156
156
157
+ http .MakeRequestAndExpectEventuallyConsistentResponse (t , suite .RoundTripper , suite .TimeoutConfig , gwAddr , expectedResponse )
158
+ })
159
+ t .Run ("section scoped api-key auth with header" , func (t * testing.T ) {
160
+ ns := "gateway-conformance-infra"
161
+ routeNN := types.NamespacedName {Name : "http-with-api-key-auth-header-section-scoped" , Namespace : ns }
162
+ gwNN := types.NamespacedName {Name : "same-namespace" , Namespace : ns }
163
+ gwAddr := kubernetes .GatewayAndHTTPRoutesMustBeAccepted (t , suite .Client , suite .TimeoutConfig , suite .ControllerName , kubernetes .NewGatewayRef (gwNN ), routeNN )
164
+
165
+ ancestorRef := gwapiv1a2.ParentReference {
166
+ Group : gatewayapi .GroupPtr (gwapiv1 .GroupName ),
167
+ Kind : gatewayapi .KindPtr (resource .KindGateway ),
168
+ Namespace : gatewayapi .NamespacePtr (gwNN .Namespace ),
169
+ Name : gwapiv1 .ObjectName (gwNN .Name ),
170
+ }
171
+ SecurityPolicyMustBeAccepted (t , suite .Client , types.NamespacedName {Name : "api-key-auth-header-section-scoped" , Namespace : ns }, suite .ControllerName , ancestorRef )
172
+
173
+ // Invalid key request for a route rule with policy attached will fail.
174
+ expectedResponse := http.ExpectedResponse {
175
+ Request : http.Request {
176
+ Path : "/api-key-auth-header-attached" ,
177
+ Headers : map [string ]string {
178
+ "X-API-KEY" : "invalid" ,
179
+ },
180
+ },
181
+ Response : http.Response {
182
+ StatusCode : 401 ,
183
+ },
184
+ Namespace : ns ,
185
+ }
186
+
187
+ http .MakeRequestAndExpectEventuallyConsistentResponse (t , suite .RoundTripper , suite .TimeoutConfig , gwAddr , expectedResponse )
188
+
189
+ // Invalid key request for a route rule with policy not attached will success.
190
+ expectedResponse = http.ExpectedResponse {
191
+ Request : http.Request {
192
+ Path : "/api-key-auth-header-non-attached" ,
193
+ Headers : map [string ]string {
194
+ "X-API-KEY" : "invalid" ,
195
+ },
196
+ },
197
+ Response : http.Response {
198
+ StatusCode : 200 ,
199
+ },
200
+ Namespace : ns ,
201
+ }
202
+
157
203
http .MakeRequestAndExpectEventuallyConsistentResponse (t , suite .RoundTripper , suite .TimeoutConfig , gwAddr , expectedResponse )
158
204
})
159
205
},
0 commit comments