Skip to content

Commit 9d4b136

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

File tree

2 files changed

+108
-4
lines changed

2 files changed

+108
-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: 75 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,36 @@ 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+
---
151+
apiVersion: v1
152+
kind: Service
153+
metadata:
154+
name: backendtlspolicy-san-test
155+
namespace: gateway-conformance-infra
156+
spec:
157+
selector:
158+
app: backendtlspolicy-test
159+
ports:
160+
- name: "btls"
161+
protocol: TCP
162+
appProtocol: HTTPS
163+
port: 443
164+
targetPort: 8443
165+
---
118166
# Deployment must not be applied until after the secret is generated.
119167
apiVersion: apps/v1
120168
kind: Deployment
@@ -222,18 +270,41 @@ spec:
222270
apiVersion: gateway.networking.k8s.io/v1alpha3
223271
kind: BackendTLSPolicy
224272
metadata:
225-
name: backendtlspolicy-cert-mismatch
273+
name: backendtlspolicy-san
226274
namespace: gateway-conformance-infra
227275
spec:
228276
targetRefs:
229277
- group: ""
230278
kind: Service
231-
name: "backendtlspolicy-cert-mismatch-test"
279+
name: "backendtlspolicy-san-test"
232280
sectionName: "btls"
233281
validation:
234282
caCertificateRefs:
235283
- group: ""
236284
kind: ConfigMap
237285
# This secret is generated dynamically by the test suite.
238-
name: "backend-tls-mismatch-certificate"
239-
hostname: "abc.example.com"
286+
name: "backend-tls-certificate"
287+
SubjectAltNames:
288+
- Type: Hostname
289+
Hostname: abc.example.com
290+
---
291+
apiVersion: gateway.networking.k8s.io/v1alpha3
292+
kind: BackendTLSPolicy
293+
metadata:
294+
name: backendtlspolicy-san-mismatch
295+
namespace: gateway-conformance-infra
296+
spec:
297+
targetRefs:
298+
- group: ""
299+
kind: Service
300+
name: "backendtlspolicy-san-mismatch-test"
301+
sectionName: "btls"
302+
validation:
303+
caCertificateRefs:
304+
- group: ""
305+
kind: ConfigMap
306+
# This secret is generated dynamically by the test suite.
307+
name: "backend-tls-certificate"
308+
SubjectAltNames:
309+
- Type: Hostname
310+
Hostname: cde.example.com

0 commit comments

Comments
 (0)