Skip to content

Commit 749768e

Browse files
committed
Apply PR feedback
Signed-off-by: Norwin Schnyder <[email protected]>
1 parent 5ea56fc commit 749768e

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

conformance/tests/backendtlspolicy-invalid-ca-certificate-ref.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ import (
3232
)
3333

3434
func init() {
35-
ConformanceTests = append(ConformanceTests, BackendTLSPolicyCACertificateRefInvalidCACertificateRef)
35+
ConformanceTests = append(ConformanceTests, BackendTLSPolicyInvalidCACertificateRef)
3636
}
3737

38-
var BackendTLSPolicyCACertificateRefInvalidCACertificateRef = suite.ConformanceTest{
39-
ShortName: "BackendTLSPolicyCACertificateRefInvalidCACertificateRef",
38+
var BackendTLSPolicyInvalidCACertificateRef = suite.ConformanceTest{
39+
ShortName: "BackendTLSPolicyInvalidCACertificateRef",
4040
Description: "A BackendTLSPolicy that specifies a single invalid CACertificateRef should have the Accepted and ResolvedRefs status condition set False with appropriate reasons, and HTTP requests to a backend targeted by this policy should fail with a 5xx response.",
4141
Features: []features.FeatureName{
4242
features.SupportGateway,
@@ -81,13 +81,16 @@ var BackendTLSPolicyCACertificateRefInvalidCACertificateRef = suite.ConformanceT
8181
})
8282

8383
t.Run("HTTP Request to backend targeted by an invalid BackendTLSPolicy receive a 5xx", func(t *testing.T) {
84-
h.MakeRequestAndExpectFailure(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr,
84+
h.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr,
8585
h.ExpectedResponse{
8686
Namespace: ns,
8787
Request: h.Request{
8888
Host: serverStr,
8989
Path: "/backendtlspolicy-" + policyNN.Name,
9090
},
91+
Response: h.Response{
92+
StatusCodes: []int{500, 502, 503},
93+
},
9194
})
9295
})
9396
})

conformance/tests/backendtlspolicy-invalid-kind.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ import (
3232
)
3333

3434
func init() {
35-
ConformanceTests = append(ConformanceTests, BackendTLSPolicyCACertificateRefInvalidKind)
35+
ConformanceTests = append(ConformanceTests, BackendTLSPolicyInvalidKind)
3636
}
3737

38-
var BackendTLSPolicyCACertificateRefInvalidKind = suite.ConformanceTest{
39-
ShortName: "BackendTLSPolicyCACertificateRefInvalidKind",
38+
var BackendTLSPolicyInvalidKind = suite.ConformanceTest{
39+
ShortName: "BackendTLSPolicyInvalidKind",
4040
Description: "A BackendTLSPolicy that specifies a single CACertificateRef with an invalid kind should have the Accepted and ResolvedRefs status condition set False with appropriate reasons, and HTTP requests to a backend targeted by this policy should fail with a 5xx response.",
4141
Features: []features.FeatureName{
4242
features.SupportGateway,
@@ -78,13 +78,16 @@ var BackendTLSPolicyCACertificateRefInvalidKind = suite.ConformanceTest{
7878
})
7979

8080
t.Run("HTTP Request to backend targeted by an invalid BackendTLSPolicy receive a 5xx", func(t *testing.T) {
81-
h.MakeRequestAndExpectFailure(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr,
81+
h.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr,
8282
h.ExpectedResponse{
8383
Namespace: ns,
8484
Request: h.Request{
8585
Host: serverStr,
8686
Path: "/backendtlspolicy-" + policyNN.Name,
8787
},
88+
Response: h.Response{
89+
StatusCodes: []int{500, 502, 503},
90+
},
8891
})
8992
})
9093
},

conformance/utils/http/http.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type ExpectedRequest struct {
9292
// Response defines expected properties of a response from a backend.
9393
type Response struct {
9494
StatusCode int
95+
StatusCodes []int // alternative to StatusCode, allows multiple acceptable codes
9596
Headers map[string]string
9697
AbsentHeaders []string
9798
Protocol string
@@ -304,7 +305,18 @@ func CompareRoundTrip(t *testing.T, req *roundtripper.Request, cReq *roundtrippe
304305
return nil
305306
}
306307
}
307-
if expected.Response.StatusCode != cRes.StatusCode {
308+
if len(expected.Response.StatusCodes) > 0 {
309+
matched := false
310+
for _, code := range expected.Response.StatusCodes {
311+
if code == cRes.StatusCode {
312+
matched = true
313+
break
314+
}
315+
}
316+
if !matched {
317+
return fmt.Errorf("expected status code to be one of %v, got %d", expected.Response.StatusCodes, cRes.StatusCode)
318+
}
319+
} else if expected.Response.StatusCode != cRes.StatusCode {
308320
return fmt.Errorf("expected status code to be %d, got %d. CRes: %v", expected.Response.StatusCode, cRes.StatusCode, cRes)
309321
}
310322
if expected.Response.Protocol != "" && expected.Response.Protocol != cRes.Protocol {
@@ -467,6 +479,9 @@ func (er *ExpectedResponse) GetTestCaseName(i int) string {
467479
if er.Backend != "" {
468480
return fmt.Sprintf("%s should go to %s", reqStr, er.Backend)
469481
}
482+
if len(er.Response.StatusCodes) > 0 {
483+
return fmt.Sprintf("%s should receive one of %v", reqStr, er.Response.StatusCodes)
484+
}
470485
return fmt.Sprintf("%s should receive a %d", reqStr, er.Response.StatusCode)
471486
}
472487

0 commit comments

Comments
 (0)