/
test_case.go
84 lines (77 loc) · 2.27 KB
/
test_case.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package test_case
import (
"crypto"
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
)
type ExpectedResult int
const (
EXPECTED_RESULT_FAIL = iota
EXPECTED_RESULT_PASS
EXPECTED_RESULT_SOFT_FAIL
EXPECTED_RESULT_SOFT_PASS
)
func (r ExpectedResult) String() string {
switch r {
case EXPECTED_RESULT_FAIL:
return "FAIL"
case EXPECTED_RESULT_PASS:
return "PASS"
case EXPECTED_RESULT_SOFT_FAIL:
return "SOFT_FAIL"
case EXPECTED_RESULT_SOFT_PASS:
return "SOFT_PASS"
}
panic(fmt.Errorf("Unhandled value in ExpectedResult.String(): %v", int(r)))
}
func (r ExpectedResult) MarshalJSON() ([]byte, error) {
return json.Marshal(r.String())
}
func (r *ExpectedResult) UnmarshalJSON(data []byte) error {
var s string
err := json.Unmarshal(data, &s)
if err != nil {
return err
}
switch s {
case "FAIL":
*r = EXPECTED_RESULT_FAIL
case "PASS":
*r = EXPECTED_RESULT_PASS
case "SOFT_FAIL":
*r = EXPECTED_RESULT_SOFT_FAIL
case "SOFT_PASS":
*r = EXPECTED_RESULT_SOFT_PASS
default:
return fmt.Errorf("invalid expected result: %s", s)
}
return nil
}
type Feature int
type TestCase interface {
// The expected result (whether the client should reject or accept the TLS connection)
ExpectedResult() ExpectedResult
// What hostname should be used in the request, e.g. "localhost" or "127.0.0.1".
GetHostname() string
// A callback to get the server certificates for this test case
GetCertificates(rootCert *x509.Certificate, rootKey crypto.Signer) (*tls.Certificate, error)
// Which supported client features are required in order to meaningfully run this test
RequiredFeatures() []Feature
}
type TestCaseProvider interface {
Name() string
// How many test cases does this provider supply?
GetTestCaseCount() (uint, error)
// Get the "index"th test case.
GetTestCase(index uint) (TestCase, error)
// Get a test case index that verifies the client can trusts certificates under the server's root
GetSanityCheckTestCase() (uint, error)
// Get a list of features used by this test provider
GetFeatures() []Feature
// Get a string description of a feature
DescribeFeature(feature Feature) string
// For a given feature, a list of test cases (as indices) that must pass for the client to be considered to support the feature.
GetTestCasesForFeature(feature Feature) ([]uint, error)
}