@@ -18,6 +18,7 @@ package main
18
18
19
19
import (
20
20
"bytes"
21
+ "crypto/tls"
21
22
"testing"
22
23
23
24
. "github.com/onsi/gomega"
@@ -75,25 +76,59 @@ func Test13CipherSuite(t *testing.T) {
75
76
klog .SetOutput (bufWriter )
76
77
klog .LogToStderr (false ) // this is important, because klog by default logs to stderr only
77
78
_ , err := GetTLSOptionOverrideFuncs (tlsMockOptions )
78
- g .Expect (bufWriter .String ()).Should (ContainSubstring ("warning: Cipher suites should not be set for TLS version 1.3. Ignoring ciphers" ))
79
79
g .Expect (err ).ShouldNot (HaveOccurred ())
80
+ g .Expect (bufWriter .String ()).Should (ContainSubstring ("warning: Cipher suites should not be set for TLS version 1.3. Ignoring ciphers" ))
80
81
})
81
82
}
82
83
83
- func TestGetTLSVersion (t * testing.T ) {
84
- t .Run ("should error out when incorrect tls version passed" , func (t * testing.T ) {
84
+ func TestGetTLSOverrideFuncs (t * testing.T ) {
85
+ t .Run ("should error out when incorrect min tls version passed" , func (t * testing.T ) {
86
+ g := NewWithT (t )
87
+ _ , err := GetTLSOptionOverrideFuncs (TLSOptions {
88
+ TLSMinVersion : "TLS11" ,
89
+ TLSMaxVersion : "TLS12" ,
90
+ })
91
+ g .Expect (err .Error ()).Should (Equal ("unexpected TLS version \" TLS11\" (must be one of: TLS12, TLS13)" ))
92
+ })
93
+ t .Run ("should error out when incorrect max tls version passed" , func (t * testing.T ) {
85
94
g := NewWithT (t )
86
- tlsVersion := "TLS11"
87
- _ , err := GetTLSVersion (tlsVersion )
95
+ _ , err := GetTLSOptionOverrideFuncs (TLSOptions {
96
+ TLSMinVersion : "TLS12" ,
97
+ TLSMaxVersion : "TLS11" ,
98
+ })
88
99
g .Expect (err .Error ()).Should (Equal ("unexpected TLS version \" TLS11\" (must be one of: TLS12, TLS13)" ))
89
100
})
90
- t .Run ("should pass and output correct tls version" , func (t * testing.T ) {
91
- const VersionTLS12 uint16 = 771
101
+ t .Run ("should apply the requested TLS versions" , func (t * testing.T ) {
102
+ g := NewWithT (t )
103
+ tlsOptionOverrides , err := GetTLSOptionOverrideFuncs (TLSOptions {
104
+ TLSMinVersion : "TLS12" ,
105
+ TLSMaxVersion : "TLS13" ,
106
+ })
107
+
108
+ var tlsConfig tls.Config
109
+ for _ , apply := range tlsOptionOverrides {
110
+ apply (& tlsConfig )
111
+ }
112
+
113
+ g .Expect (err ).ShouldNot (HaveOccurred ())
114
+ g .Expect (tlsConfig .MinVersion ).To (Equal (uint16 (tls .VersionTLS12 )))
115
+ g .Expect (tlsConfig .MaxVersion ).To (Equal (uint16 (tls .VersionTLS13 )))
116
+ })
117
+ t .Run ("should apply the requested non-default TLS versions" , func (t * testing.T ) {
92
118
g := NewWithT (t )
93
- tlsVersion := "TLS12"
94
- version , err := GetTLSVersion (tlsVersion )
95
- g .Expect (version ).To (Equal (VersionTLS12 ))
119
+ tlsOptionOverrides , err := GetTLSOptionOverrideFuncs (TLSOptions {
120
+ TLSMinVersion : "TLS13" ,
121
+ TLSMaxVersion : "TLS13" ,
122
+ })
123
+
124
+ var tlsConfig tls.Config
125
+ for _ , apply := range tlsOptionOverrides {
126
+ apply (& tlsConfig )
127
+ }
128
+
96
129
g .Expect (err ).ShouldNot (HaveOccurred ())
130
+ g .Expect (tlsConfig .MinVersion ).To (Equal (uint16 (tls .VersionTLS13 )))
131
+ g .Expect (tlsConfig .MaxVersion ).To (Equal (uint16 (tls .VersionTLS13 )))
97
132
})
98
133
}
99
134
0 commit comments