-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtlstext_test.go
97 lines (84 loc) · 2.23 KB
/
tlstext_test.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
85
86
87
88
89
90
91
92
93
94
95
96
97
package tlstext
import (
"crypto/tls"
"fmt"
"testing"
)
func TestCipherSuite(t *testing.T) {
value := uint16(0xc02b)
expected := "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"
actual := CipherSuite(value)
if expected != actual {
t.Errorf("For %d, expected %q got %q", value, expected, actual)
}
newvalue := CipherFromString(expected)
if newvalue != value {
t.Errorf("For %s, expected %q got %q", expected, value, newvalue)
}
value = uint16(1234)
expected = "04d2"
actual = CipherSuite(value)
if expected != actual {
t.Errorf("For %d, expected %q got %q", value, expected, actual)
}
zero := CipherFromString("junk")
if zero != 0x0 {
t.Errorf("Expected zero value for bad version")
}
}
func TestVersion(t *testing.T) {
value := uint16(0x0303)
expected := "TLS12"
actual := Version(value)
if expected != actual {
t.Errorf("For %d, expected %q got %q", value, expected, actual)
}
newvalue := VersionFromString(expected)
if newvalue != value {
t.Errorf("For %s, expected %q got %q", expected, value, newvalue)
}
value = uint16(1234)
expected = "04d2"
actual = Version(value)
if expected != actual {
t.Errorf("For %d, expected %q got %q", value, expected, actual)
}
zero := VersionFromString("junk")
if zero != 0x0 {
t.Errorf("Expected zero value for bad version")
}
}
func TestFromConnection(t *testing.T) {
actual := VersionFromConnection(nil)
if actual != "" {
t.Errorf("Expected empty version from nil input, got %q", actual)
}
actual = CipherSuiteFromConnection(nil)
if actual != "" {
t.Errorf("Expected empty cipher suite from nil input, got %q", actual)
}
c := tls.ConnectionState{
Version: uint16(0x0303),
CipherSuite: uint16(0xc02b),
}
expected := "TLS12"
actual = VersionFromConnection(&c)
if expected != actual {
t.Errorf("For %d, expected %q got %q", c.Version, expected, actual)
}
expected = "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"
actual = CipherSuiteFromConnection(&c)
if expected != actual {
t.Errorf("For %d, expected %q got %q", c.CipherSuite, expected, actual)
}
}
func ExampleVersion() {
fmt.Println(Version(uint16(0x0303)))
// Output:
// TLS12
}
func ExampleCipherSuite() {
fmt.Println(CipherSuite(uint16(0xc02b)))
// Output:
// TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
}