#120: Add support for StartTLS protocol

* add starttls

* remove starttls from default config

Co-authored-by: Gopher Johns <gopher.johns28@gmail.com>
This commit is contained in:
gopher-johns
2021-06-05 21:47:11 +02:00
committed by GitHub
parent 81aeb7a48e
commit 2131fa4412
3 changed files with 101 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package client
import (
"crypto/x509"
"testing"
"time"
)
@ -49,3 +50,56 @@ func TestPing(t *testing.T) {
}
}
}
func TestCanPerformStartTls(t *testing.T) {
type args struct {
address string
insecure bool
}
tests := []struct {
name string
args args
wantConnected bool
wantCertificate *x509.Certificate
wantErr bool
}{
{
name: "invalid address",
args: args{
address: "test",
},
wantConnected: false,
wantCertificate: nil,
wantErr: true,
},
{
name: "error dial",
args: args{
address: "test:1234",
},
wantConnected: false,
wantCertificate: nil,
wantErr: true,
},
{
name: "valid starttls",
args: args{
address: "smtp.gmail.com:587",
},
wantConnected: true,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotConnected, _, err := CanPerformStartTls(tt.args.address, tt.args.insecure)
if (err != nil) != tt.wantErr {
t.Errorf("CanPerformStartTls() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotConnected != tt.wantConnected {
t.Errorf("CanPerformStartTls() gotConnected = %v, want %v", gotConnected, tt.wantConnected)
}
})
}
}