Skip to content

Commit 0104bd0

Browse files
committed
add e2e for route rule level sp
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
1 parent a02f5c4 commit 0104bd0

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

test/e2e/testdata/api-key-auth.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ spec:
7070
- name: infra-backend-v1
7171
port: 8080
7272
---
73+
apiVersion: gateway.networking.k8s.io/v1
74+
kind: HTTPRoute
75+
metadata:
76+
name: http-with-api-key-auth-header-section-scoped
77+
namespace: gateway-conformance-infra
78+
spec:
79+
parentRefs:
80+
- name: same-namespace
81+
rules:
82+
- name: policy-attached
83+
matches:
84+
- path:
85+
type: Exact
86+
value: /api-key-auth-header-attached
87+
backendRefs:
88+
- name: infra-backend-v1
89+
port: 8080
90+
- name: policy-non-attached
91+
matches:
92+
- path:
93+
type: Exact
94+
value: /api-key-auth-header-non-attached
95+
backendRefs:
96+
- name: infra-backend-v1
97+
port: 8080
98+
---
7399
apiVersion: gateway.envoyproxy.io/v1alpha1
74100
kind: SecurityPolicy
75101
metadata:
@@ -121,3 +147,21 @@ spec:
121147
credentialRefs:
122148
- name: "api-key-auth-users-secret-1"
123149
- name: "api-key-auth-users-secret-2"
150+
---
151+
apiVersion: gateway.envoyproxy.io/v1alpha1
152+
kind: SecurityPolicy
153+
metadata:
154+
name: api-key-auth-header-section-scoped
155+
namespace: gateway-conformance-infra
156+
spec:
157+
targetRefs:
158+
- group: gateway.networking.k8s.io
159+
kind: HTTPRoute
160+
name: http-with-api-key-auth-header-section-scoped
161+
sectionName: policy-attached
162+
apiKeyAuth:
163+
extractFrom:
164+
- headers: ["X-API-KEY"]
165+
credentialRefs:
166+
- name: "api-key-auth-users-secret-1"
167+
- name: "api-key-auth-users-secret-2"

test/e2e/tests/api_key_auth.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,52 @@ var APIKeyAuthTest = suite.ConformanceTest{
154154
Namespace: ns,
155155
}
156156

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+
157203
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
158204
})
159205
},

0 commit comments

Comments
 (0)