b07890af4d
Auto-configure every relevant TLS field as close as possible to where it's actually used. As a side effect, add support for mocking the creation of a TLS connection, which should possibly be useful for uTLS? Work that is part of https://github.com/ooni/probe/issues/1505
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package netxmocks
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"errors"
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/lucas-clemente/quic-go"
|
|
)
|
|
|
|
func TestQUICListenerListen(t *testing.T) {
|
|
expected := errors.New("mocked error")
|
|
ql := &QUICListener{
|
|
MockListen: func(addr *net.UDPAddr) (net.PacketConn, error) {
|
|
return nil, expected
|
|
},
|
|
}
|
|
pconn, err := ql.Listen(&net.UDPAddr{})
|
|
if !errors.Is(err, expected) {
|
|
t.Fatal("not the error we expected", expected)
|
|
}
|
|
if pconn != nil {
|
|
t.Fatal("expected nil conn here")
|
|
}
|
|
}
|
|
|
|
func TestQUICContextDialerDialContext(t *testing.T) {
|
|
expected := errors.New("mocked error")
|
|
qcd := &QUICContextDialer{
|
|
MockDialContext: func(ctx context.Context, network string, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
|
|
return nil, expected
|
|
},
|
|
}
|
|
ctx := context.Background()
|
|
tlsConfig := &tls.Config{}
|
|
quicConfig := &quic.Config{}
|
|
sess, err := qcd.DialContext(ctx, "udp", "dns.google:443", tlsConfig, quicConfig)
|
|
if !errors.Is(err, expected) {
|
|
t.Fatal("not the error we expected")
|
|
}
|
|
if sess != nil {
|
|
t.Fatal("expected nil session")
|
|
}
|
|
}
|