2021-09-05 14:49:38 +02:00
|
|
|
package netxlite
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/tls"
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
|
2021-09-05 20:59:42 +02:00
|
|
|
"github.com/apex/log"
|
2021-09-05 14:49:38 +02:00
|
|
|
utls "gitlab.com/yawning/utls.git"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUTLSHandshakerChrome(t *testing.T) {
|
|
|
|
h := &tlsHandshakerConfigurable{
|
2021-09-05 20:59:42 +02:00
|
|
|
NewConn: newConnUTLS(&utls.HelloChrome_Auto),
|
2021-09-05 14:49:38 +02:00
|
|
|
}
|
|
|
|
cfg := &tls.Config{ServerName: "google.com"}
|
|
|
|
conn, err := net.Dial("tcp", "google.com:443")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("unexpected error", err)
|
|
|
|
}
|
|
|
|
conn, _, err = h.Handshake(context.Background(), conn, cfg)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("unexpected error", err)
|
|
|
|
}
|
|
|
|
if conn == nil {
|
|
|
|
t.Fatal("nil connection")
|
|
|
|
}
|
|
|
|
}
|
2021-09-05 20:59:42 +02:00
|
|
|
|
|
|
|
func TestNewTLSHandshakerUTLSTypes(t *testing.T) {
|
|
|
|
th := NewTLSHandshakerUTLS(log.Log, &utls.HelloChrome_83)
|
|
|
|
thl, okay := th.(*tlsHandshakerLogger)
|
|
|
|
if !okay {
|
|
|
|
t.Fatal("invalid type")
|
|
|
|
}
|
|
|
|
if thl.Logger != log.Log {
|
|
|
|
t.Fatal("invalid logger")
|
|
|
|
}
|
|
|
|
thc, okay := thl.TLSHandshaker.(*tlsHandshakerConfigurable)
|
|
|
|
if !okay {
|
|
|
|
t.Fatal("invalid type")
|
|
|
|
}
|
|
|
|
if thc.NewConn == nil {
|
|
|
|
t.Fatal("expected non-nil NewConn")
|
|
|
|
}
|
|
|
|
}
|