@@ -33,6 +33,16 @@ func Test_configureCipherSuites(t *testing.T) {
33
33
return ids
34
34
}
35
35
36
+ cipherByName := func (cipher string ) * tls.CipherSuite {
37
+ for _ , c := range append (tls .CipherSuites (), tls .InsecureCipherSuites ()... ) {
38
+ if cipher == c .Name {
39
+ c := c
40
+ return c
41
+ }
42
+ }
43
+ return nil
44
+ }
45
+
36
46
tests := []struct {
37
47
name string
38
48
wantErr string
@@ -43,6 +53,14 @@ func Test_configureCipherSuites(t *testing.T) {
43
53
allowInsecure bool
44
54
expectCiphers []uint16
45
55
}{
56
+ {
57
+ name : "AllSecure" ,
58
+ minTLS : tls .VersionTLS10 ,
59
+ maxTLS : tls .VersionTLS13 ,
60
+ inputCiphers : cipherNames (tls .CipherSuites ()),
61
+ wantWarnings : []string {},
62
+ expectCiphers : cipherIDs (tls .CipherSuites ()),
63
+ },
46
64
{
47
65
name : "AllowInsecure" ,
48
66
minTLS : tls .VersionTLS10 ,
@@ -54,7 +72,45 @@ func Test_configureCipherSuites(t *testing.T) {
54
72
},
55
73
expectCiphers : append (cipherIDs (tls .CipherSuites ()), tls .InsecureCipherSuites ()[0 ].ID ),
56
74
},
75
+ {
76
+ name : "AllInsecure" ,
77
+ minTLS : tls .VersionTLS10 ,
78
+ maxTLS : tls .VersionTLS13 ,
79
+ inputCiphers : append (cipherNames (tls .CipherSuites ()), cipherNames (tls .InsecureCipherSuites ())... ),
80
+ allowInsecure : true ,
81
+ wantWarnings : []string {
82
+ "insecure tls cipher specified" ,
83
+ },
84
+ expectCiphers : append (cipherIDs (tls .CipherSuites ()), cipherIDs (tls .InsecureCipherSuites ())... ),
85
+ },
86
+ {
87
+ // Providing ciphers that are not compatible with any tls version
88
+ // enabled should generate a warning.
89
+ name : "ExcessiveCiphers" ,
90
+ minTLS : tls .VersionTLS10 ,
91
+ maxTLS : tls .VersionTLS11 ,
92
+ inputCiphers : []string {
93
+ "TLS_RSA_WITH_AES_128_CBC_SHA" ,
94
+ // Only for TLS 1.3
95
+ "TLS_AES_128_GCM_SHA256" ,
96
+ },
97
+ allowInsecure : true ,
98
+ wantWarnings : []string {
99
+ "cipher not supported for tls versions" ,
100
+ },
101
+ expectCiphers : cipherIDs ([]* tls.CipherSuite {
102
+ cipherByName ("TLS_RSA_WITH_AES_128_CBC_SHA" ),
103
+ cipherByName ("TLS_AES_128_GCM_SHA256" ),
104
+ }),
105
+ },
57
106
// Errors
107
+ {
108
+ name : "NotRealCiphers" ,
109
+ minTLS : tls .VersionTLS10 ,
110
+ maxTLS : tls .VersionTLS13 ,
111
+ inputCiphers : []string {"RSA-Fake" },
112
+ wantErr : "unsupported tls ciphers" ,
113
+ },
58
114
{
59
115
name : "NoCiphers" ,
60
116
minTLS : tls .VersionTLS10 ,
@@ -75,6 +131,20 @@ func Test_configureCipherSuites(t *testing.T) {
75
131
inputCiphers : cipherNames (tls .CipherSuites ()),
76
132
wantErr : "tls ciphers cannot be specified when using minimum tls version 1.3" ,
77
133
},
134
+ {
135
+ name : "TLSUnsupported" ,
136
+ minTLS : tls .VersionTLS10 ,
137
+ maxTLS : tls .VersionTLS13 ,
138
+ // TLS_RSA_WITH_AES_128_GCM_SHA256 only supports tls 1.2
139
+ inputCiphers : []string {"TLS_RSA_WITH_AES_128_GCM_SHA256" },
140
+ wantErr : "no tls ciphers supported for tls versions" ,
141
+ },
142
+ {
143
+ name : "Min>Max" ,
144
+ minTLS : tls .VersionTLS13 ,
145
+ maxTLS : tls .VersionTLS12 ,
146
+ wantErr : "minimum tls version cannot be greater than maximum tls version" ,
147
+ },
78
148
}
79
149
for _ , tt := range tests {
80
150
tt := tt
0 commit comments