refactor(netx): start moving tls-specific code inside the tlsx pkg (#363)
* refactor(netx): move cert pool code inside tlsx * refactor(netx): move more tls code inside tlsx
This commit is contained in:
parent
0317420398
commit
c553afdbd5
6 changed files with 120 additions and 119 deletions
|
|
@ -2,6 +2,7 @@ package tlsx
|
|||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
@ -28,3 +29,77 @@ func TestCipherSuite(t *testing.T) {
|
|||
t.Fatal("not working for zero cipher suite")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewDefaultCertPoolWorks(t *testing.T) {
|
||||
pool := NewDefaultCertPool()
|
||||
if pool == nil {
|
||||
t.Fatal("expected non-nil value here")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigureTLSVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
version string
|
||||
wantErr error
|
||||
versionMin int
|
||||
versionMax int
|
||||
}{{
|
||||
name: "with TLSv1.3",
|
||||
version: "TLSv1.3",
|
||||
wantErr: nil,
|
||||
versionMin: tls.VersionTLS13,
|
||||
versionMax: tls.VersionTLS13,
|
||||
}, {
|
||||
name: "with TLSv1.2",
|
||||
version: "TLSv1.2",
|
||||
wantErr: nil,
|
||||
versionMin: tls.VersionTLS12,
|
||||
versionMax: tls.VersionTLS12,
|
||||
}, {
|
||||
name: "with TLSv1.1",
|
||||
version: "TLSv1.1",
|
||||
wantErr: nil,
|
||||
versionMin: tls.VersionTLS11,
|
||||
versionMax: tls.VersionTLS11,
|
||||
}, {
|
||||
name: "with TLSv1.0",
|
||||
version: "TLSv1.0",
|
||||
wantErr: nil,
|
||||
versionMin: tls.VersionTLS10,
|
||||
versionMax: tls.VersionTLS10,
|
||||
}, {
|
||||
name: "with TLSv1",
|
||||
version: "TLSv1",
|
||||
wantErr: nil,
|
||||
versionMin: tls.VersionTLS10,
|
||||
versionMax: tls.VersionTLS10,
|
||||
}, {
|
||||
name: "with default",
|
||||
version: "",
|
||||
wantErr: nil,
|
||||
versionMin: 0,
|
||||
versionMax: 0,
|
||||
}, {
|
||||
name: "with invalid version",
|
||||
version: "TLSv999",
|
||||
wantErr: ErrInvalidTLSVersion,
|
||||
versionMin: 0,
|
||||
versionMax: 0,
|
||||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
conf := new(tls.Config)
|
||||
err := ConfigureTLSVersion(conf, tt.version)
|
||||
if !errors.Is(err, tt.wantErr) {
|
||||
t.Fatalf("not the error we expected: %+v", err)
|
||||
}
|
||||
if conf.MinVersion != uint16(tt.versionMin) {
|
||||
t.Fatalf("not the min version we expected: %+v", conf.MinVersion)
|
||||
}
|
||||
if conf.MaxVersion != uint16(tt.versionMax) {
|
||||
t.Fatalf("not the max version we expected: %+v", conf.MaxVersion)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue