Skip to content

Commit b2dc6d5

Browse files
committed
Add Conformance tests for BackendTLSPolicy validating SANs
1 parent b167eed commit b2dc6d5

File tree

2 files changed

+93
-4
lines changed

2 files changed

+93
-4
lines changed

conformance/tests/backendtlspolicy.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ var BackendTLSPolicy = suite.ConformanceTest{
6969
invalidCertPolicyNN := types.NamespacedName{Name: "backendtlspolicy-cert-mismatch", Namespace: ns}
7070
kubernetes.BackendTLSPolicyMustHaveCondition(t, suite.Client, suite.TimeoutConfig, invalidCertPolicyNN, gwNN, policyCond)
7171

72+
invalidSanPolicyNN := types.NamespacedName{Name: "backendtlspolicy-san-mismatch", Namespace: ns}
73+
kubernetes.BackendTLSPolicyMustHaveCondition(t, suite.Client, suite.TimeoutConfig, invalidSanPolicyNN, gwNN, policyCond)
74+
75+
validSanPolicyNN := types.NamespacedName{Name: "backendtlspolicy-san", Namespace: ns}
76+
kubernetes.BackendTLSPolicyMustHaveCondition(t, suite.Client, suite.TimeoutConfig, validSanPolicyNN, gwNN, policyCond)
77+
7278
serverStr := "abc.example.com"
7379

7480
// Verify that the request sent to Service with valid BackendTLSPolicy should succeed.
@@ -130,5 +136,32 @@ var BackendTLSPolicy = suite.ConformanceTest{
130136
},
131137
})
132138
})
139+
140+
// Verify that the request sent to Service with BackendTLSPolicy configured with SANs should succeed.
141+
t.Run("HTTP request sent to Service with BackendTLSPolicy configured with SAN should succeed", func(t *testing.T) {
142+
h.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr,
143+
h.ExpectedResponse{
144+
Namespace: ns,
145+
Request: h.Request{
146+
Host: serverStr,
147+
Path: "/backendTLSSan",
148+
SNI: serverStr,
149+
},
150+
Response: h.Response{StatusCode: 200},
151+
})
152+
})
153+
154+
// Verify that request sent to Service targeted by BackendTLSPolicy with mismatched SAN should failed.
155+
t.Run("HTTP request send to Service targeted by BackendTLSPolicy with mismatched SAN should return HTTP error", func(t *testing.T) {
156+
h.MakeRequestAndExpectFailure(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr,
157+
h.ExpectedResponse{
158+
Namespace: ns,
159+
Request: h.Request{
160+
Host: serverStr,
161+
Path: "/backendTLSSanMismatch",
162+
SNI: serverStr,
163+
},
164+
})
165+
})
133166
},
134167
}

conformance/tests/backendtlspolicy.yaml

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ spec:
7070
- path:
7171
type: Exact
7272
value: /backendTLSCertMismatch
73+
- backendRefs:
74+
- group: ""
75+
kind: Service
76+
name: backendtlspolicy-san-mismatch-test
77+
port: 443
78+
matches:
79+
- path:
80+
type: Exact
81+
value: /backendTLSSanMismatch
82+
- backendRefs:
83+
- group: ""
84+
kind: Service
85+
name: backendtlspolicy-san-test
86+
port: 443
87+
matches:
88+
- path:
89+
type: Exact
90+
value: /backendTLSSan
7391
---
7492
apiVersion: v1
7593
kind: Service
@@ -115,6 +133,21 @@ spec:
115133
port: 443
116134
targetPort: 8443
117135
---
136+
apiVersion: v1
137+
kind: Service
138+
metadata:
139+
name: backendtlspolicy-san-mismatch-test
140+
namespace: gateway-conformance-infra
141+
spec:
142+
selector:
143+
app: backendtlspolicy-test
144+
ports:
145+
- name: "btls"
146+
protocol: TCP
147+
appProtocol: HTTPS
148+
port: 443
149+
targetPort: 8443
150+
---
118151
# Deployment must not be applied until after the secret is generated.
119152
apiVersion: apps/v1
120153
kind: Deployment
@@ -222,18 +255,41 @@ spec:
222255
apiVersion: gateway.networking.k8s.io/v1alpha3
223256
kind: BackendTLSPolicy
224257
metadata:
225-
name: backendtlspolicy-cert-mismatch
258+
name: backendtlspolicy-san
226259
namespace: gateway-conformance-infra
227260
spec:
228261
targetRefs:
229262
- group: ""
230263
kind: Service
231-
name: "backendtlspolicy-cert-mismatch-test"
264+
name: "backendtlspolicy-san-test"
232265
sectionName: "btls"
233266
validation:
234267
caCertificateRefs:
235268
- group: ""
236269
kind: ConfigMap
237270
# This secret is generated dynamically by the test suite.
238-
name: "backend-tls-mismatch-certificate"
239-
hostname: "abc.example.com"
271+
name: "backend-tls-certificate"
272+
SubjectAltNames:
273+
- Type: Hostname
274+
Hostname: abc.example.com
275+
---
276+
apiVersion: gateway.networking.k8s.io/v1alpha3
277+
kind: BackendTLSPolicy
278+
metadata:
279+
name: backendtlspolicy-san-mismatch
280+
namespace: gateway-conformance-infra
281+
spec:
282+
targetRefs:
283+
- group: ""
284+
kind: Service
285+
name: "backendtlspolicy-san-mismatch-test"
286+
sectionName: "btls"
287+
validation:
288+
caCertificateRefs:
289+
- group: ""
290+
kind: ConfigMap
291+
# This secret is generated dynamically by the test suite.
292+
name: "backend-tls-certificate"
293+
SubjectAltNames:
294+
- Type: Hostname
295+
Hostname: cde.example.com

0 commit comments

Comments
 (0)