-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher_suite_test.go
More file actions
81 lines (72 loc) · 2.54 KB
/
cipher_suite_test.go
File metadata and controls
81 lines (72 loc) · 2.54 KB
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
package gotls
import (
"testing"
)
func TestCipherSuiteCodeString(t *testing.T) {
tests := []struct {
code CipherSuiteCode
expected string
}{
{TLS_NULL_WITH_NULL_NULL, "TLS_NULL_WITH_NULL_NULL"},
{TLS_RSA_WITH_NULL_MD5, "TLS_RSA_WITH_NULL_MD5"},
{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"},
{TLS_RSA_EXPORT_WITH_RC4_40_MD5, "TLS_RSA_EXPORT_WITH_RC4_40_MD5"},
{TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256"},
}
for _, test := range tests {
if result := test.code.String(); result != test.expected {
t.Errorf("CipherSuiteCode.String() for %d = %s; want %s", test.code, result, test.expected)
}
}
}
func TestCipherSuiteCodeUint16(t *testing.T) {
tests := []struct {
code CipherSuiteCode
expected uint16
}{
{TLS_NULL_WITH_NULL_NULL, 0},
{TLS_RSA_WITH_NULL_MD5, 1},
{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, 49195},
{TLS_RSA_EXPORT_WITH_RC4_40_MD5, 3},
{TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, 52393},
}
for _, test := range tests {
if result := test.code.Uint16(); result != test.expected {
t.Errorf("CipherSuiteCode.Uint16() for %v = %d; want %d", test.code, result, test.expected)
}
}
}
func TestGet(t *testing.T) {
tests := []struct {
code CipherSuiteCode
expected string
}{
{TLS_NULL_WITH_NULL_NULL, "TLS_NULL_WITH_NULL_NULL"},
{TLS_RSA_WITH_NULL_MD5, "TLS_RSA_WITH_NULL_MD5"},
{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"},
{TLS_RSA_EXPORT_WITH_RC4_40_MD5, "TLS_RSA_EXPORT_WITH_RC4_40_MD5"},
{TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256"},
}
for _, test := range tests {
if suite := Get(uint16(test.code)); suite == nil || suite.Name != test.expected {
t.Errorf("Get() for %v returned incorrect or nil CipherSuite", test.code)
}
}
}
func TestGetByName(t *testing.T) {
tests := []struct {
name string
expected CipherSuiteCode
}{
{"TLS_NULL_WITH_NULL_NULL", TLS_NULL_WITH_NULL_NULL},
{"TLS_RSA_WITH_NULL_MD5", TLS_RSA_WITH_NULL_MD5},
{"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
{"TLS_RSA_EXPORT_WITH_RC4_40_MD5", TLS_RSA_EXPORT_WITH_RC4_40_MD5},
{"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
}
for _, test := range tests {
if suite := GetByName(test.name); suite == nil || suite.Code != test.expected {
t.Errorf("GetByName() for %s returned incorrect or nil CipherSuite", test.name)
}
}
}