refactor(netxlite): hide details without breaking the rest of the tree (#454)
## Description This PR continues the refactoring of `netx` under the following principles: 1. do not break the rest of the tree and do not engage in extensive tree-wide refactoring yet 2. move under `netxlite` clearly related subpackages (e.g., `iox`, `netxmocks`) 3. move into `internal/netxlite/internal` stuff that is clearly private of `netxlite` 4. hide implementation details in `netxlite` pending new factories 5. refactor `tls` code in `netxlite` to clearly separate `crypto/tls` code from `utls` code After each commit, I run `go test -short -race ./...` locally. Each individual commit explains what it does. I will squash, but this operation will preserve the original commit titles, so this will give further insight on each step. ## Commits * refactor: rename netxmocks -> netxlite/mocks Part of https://github.com/ooni/probe/issues/1591 * refactor: rename quicx -> netxlite/quicx See https://github.com/ooni/probe/issues/1591 * refactor: rename iox -> netxlite/iox Regenerate sources and make sure the tests pass. See https://github.com/ooni/probe/issues/1591. * refactor(iox): move MockableReader to netxlite/mocks See https://github.com/ooni/probe/issues/1591 * refactor(netxlite): generator is an implementation detail See https://github.com/ooni/probe/issues/1591 * refactor(netxlite): separate tls and utls code See https://github.com/ooni/probe/issues/1591 * refactor(netxlite): hide most types but keep old names as legacy With this change we avoid breaking the rest of the tree, but we start hiding some implementation details a bit. Factories will follow. See https://github.com/ooni/probe/issues/1591
This commit is contained in:
parent
ae799c4942
commit
2e0118d1a6
137 changed files with 1244 additions and 1173 deletions
|
|
@ -11,16 +11,16 @@ import (
|
|||
"github.com/apex/log"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxmocks"
|
||||
"github.com/ooni/probe-cli/v3/internal/quicx"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite/quicx"
|
||||
)
|
||||
|
||||
func TestQUICDialerQUICGoCannotSplitHostPort(t *testing.T) {
|
||||
tlsConfig := &tls.Config{
|
||||
ServerName: "www.google.com",
|
||||
}
|
||||
systemdialer := QUICDialerQUICGo{
|
||||
QUICListener: &QUICListenerStdlib{},
|
||||
systemdialer := quicDialerQUICGo{
|
||||
QUICListener: &quicListenerStdlib{},
|
||||
}
|
||||
ctx := context.Background()
|
||||
sess, err := systemdialer.DialContext(
|
||||
|
|
@ -37,8 +37,8 @@ func TestQUICDialerQUICGoInvalidPort(t *testing.T) {
|
|||
tlsConfig := &tls.Config{
|
||||
ServerName: "www.google.com",
|
||||
}
|
||||
systemdialer := QUICDialerQUICGo{
|
||||
QUICListener: &QUICListenerStdlib{},
|
||||
systemdialer := quicDialerQUICGo{
|
||||
QUICListener: &quicListenerStdlib{},
|
||||
}
|
||||
ctx := context.Background()
|
||||
sess, err := systemdialer.DialContext(
|
||||
|
|
@ -55,8 +55,8 @@ func TestQUICDialerQUICGoInvalidIP(t *testing.T) {
|
|||
tlsConfig := &tls.Config{
|
||||
ServerName: "www.google.com",
|
||||
}
|
||||
systemdialer := QUICDialerQUICGo{
|
||||
QUICListener: &QUICListenerStdlib{},
|
||||
systemdialer := quicDialerQUICGo{
|
||||
QUICListener: &quicListenerStdlib{},
|
||||
}
|
||||
ctx := context.Background()
|
||||
sess, err := systemdialer.DialContext(
|
||||
|
|
@ -74,8 +74,8 @@ func TestQUICDialerQUICGoCannotListen(t *testing.T) {
|
|||
tlsConfig := &tls.Config{
|
||||
ServerName: "www.google.com",
|
||||
}
|
||||
systemdialer := QUICDialerQUICGo{
|
||||
QUICListener: &netxmocks.QUICListener{
|
||||
systemdialer := quicDialerQUICGo{
|
||||
QUICListener: &mocks.QUICListener{
|
||||
MockListen: func(addr *net.UDPAddr) (quicx.UDPLikeConn, error) {
|
||||
return nil, expected
|
||||
},
|
||||
|
|
@ -96,8 +96,8 @@ func TestQUICDialerQUICGoCannotPerformHandshake(t *testing.T) {
|
|||
tlsConfig := &tls.Config{
|
||||
ServerName: "dns.google",
|
||||
}
|
||||
systemdialer := QUICDialerQUICGo{
|
||||
QUICListener: &QUICListenerStdlib{},
|
||||
systemdialer := quicDialerQUICGo{
|
||||
QUICListener: &quicListenerStdlib{},
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel() // fail immediately
|
||||
|
|
@ -115,8 +115,8 @@ func TestQUICDialerQUICGoWorksAsIntended(t *testing.T) {
|
|||
tlsConfig := &tls.Config{
|
||||
ServerName: "dns.google",
|
||||
}
|
||||
systemdialer := QUICDialerQUICGo{
|
||||
QUICListener: &QUICListenerStdlib{},
|
||||
systemdialer := quicDialerQUICGo{
|
||||
QUICListener: &quicListenerStdlib{},
|
||||
}
|
||||
ctx := context.Background()
|
||||
sess, err := systemdialer.DialContext(
|
||||
|
|
@ -136,8 +136,8 @@ func TestQUICDialerQUICGoTLSDefaultsForWeb(t *testing.T) {
|
|||
tlsConfig := &tls.Config{
|
||||
ServerName: "dns.google",
|
||||
}
|
||||
systemdialer := QUICDialerQUICGo{
|
||||
QUICListener: &QUICListenerStdlib{},
|
||||
systemdialer := quicDialerQUICGo{
|
||||
QUICListener: &quicListenerStdlib{},
|
||||
mockDialEarlyContext: func(ctx context.Context, pconn net.PacketConn,
|
||||
remoteAddr net.Addr, host string, tlsConfig *tls.Config,
|
||||
quicConfig *quic.Config) (quic.EarlySession, error) {
|
||||
|
|
@ -177,8 +177,8 @@ func TestQUICDialerQUICGoTLSDefaultsForDoQ(t *testing.T) {
|
|||
tlsConfig := &tls.Config{
|
||||
ServerName: "dns.google",
|
||||
}
|
||||
systemdialer := QUICDialerQUICGo{
|
||||
QUICListener: &QUICListenerStdlib{},
|
||||
systemdialer := quicDialerQUICGo{
|
||||
QUICListener: &quicListenerStdlib{},
|
||||
mockDialEarlyContext: func(ctx context.Context, pconn net.PacketConn,
|
||||
remoteAddr net.Addr, host string, tlsConfig *tls.Config,
|
||||
quicConfig *quic.Config) (quic.EarlySession, error) {
|
||||
|
|
@ -214,9 +214,9 @@ func TestQUICDialerQUICGoTLSDefaultsForDoQ(t *testing.T) {
|
|||
|
||||
func TestQUICDialerResolverSuccess(t *testing.T) {
|
||||
tlsConfig := &tls.Config{}
|
||||
dialer := &QUICDialerResolver{
|
||||
Resolver: &net.Resolver{}, Dialer: &QUICDialerQUICGo{
|
||||
QUICListener: &QUICListenerStdlib{},
|
||||
dialer := &quicDialerResolver{
|
||||
Resolver: &net.Resolver{}, Dialer: &quicDialerQUICGo{
|
||||
QUICListener: &quicListenerStdlib{},
|
||||
}}
|
||||
sess, err := dialer.DialContext(
|
||||
context.Background(), "udp", "www.google.com:443",
|
||||
|
|
@ -232,8 +232,8 @@ func TestQUICDialerResolverSuccess(t *testing.T) {
|
|||
|
||||
func TestQUICDialerResolverNoPort(t *testing.T) {
|
||||
tlsConfig := &tls.Config{}
|
||||
dialer := &QUICDialerResolver{
|
||||
Resolver: new(net.Resolver), Dialer: &QUICDialerQUICGo{}}
|
||||
dialer := &quicDialerResolver{
|
||||
Resolver: new(net.Resolver), Dialer: &quicDialerQUICGo{}}
|
||||
sess, err := dialer.DialContext(
|
||||
context.Background(), "udp", "www.google.com",
|
||||
tlsConfig, &quic.Config{})
|
||||
|
|
@ -246,7 +246,7 @@ func TestQUICDialerResolverNoPort(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQUICDialerResolverLookupHostAddress(t *testing.T) {
|
||||
dialer := &QUICDialerResolver{Resolver: &netxmocks.Resolver{
|
||||
dialer := &quicDialerResolver{Resolver: &mocks.Resolver{
|
||||
MockLookupHost: func(ctx context.Context, domain string) ([]string, error) {
|
||||
// We should not arrive here and call this function but if we do then
|
||||
// there is going to be an error that fails this test.
|
||||
|
|
@ -265,7 +265,7 @@ func TestQUICDialerResolverLookupHostAddress(t *testing.T) {
|
|||
func TestQUICDialerResolverLookupHostFailure(t *testing.T) {
|
||||
tlsConfig := &tls.Config{}
|
||||
expected := errors.New("mocked error")
|
||||
dialer := &QUICDialerResolver{Resolver: &netxmocks.Resolver{
|
||||
dialer := &quicDialerResolver{Resolver: &mocks.Resolver{
|
||||
MockLookupHost: func(ctx context.Context, domain string) ([]string, error) {
|
||||
return nil, expected
|
||||
},
|
||||
|
|
@ -285,9 +285,9 @@ func TestQUICDialerResolverInvalidPort(t *testing.T) {
|
|||
// This test allows us to check for the case where every attempt
|
||||
// to establish a connection leads to a failure
|
||||
tlsConf := &tls.Config{}
|
||||
dialer := &QUICDialerResolver{
|
||||
Resolver: new(net.Resolver), Dialer: &QUICDialerQUICGo{
|
||||
QUICListener: &QUICListenerStdlib{},
|
||||
dialer := &quicDialerResolver{
|
||||
Resolver: new(net.Resolver), Dialer: &quicDialerQUICGo{
|
||||
QUICListener: &quicListenerStdlib{},
|
||||
}}
|
||||
sess, err := dialer.DialContext(
|
||||
context.Background(), "udp", "www.google.com:0",
|
||||
|
|
@ -308,8 +308,8 @@ func TestQUICDialerResolverApplyTLSDefaults(t *testing.T) {
|
|||
expected := errors.New("mocked error")
|
||||
var gotTLSConfig *tls.Config
|
||||
tlsConfig := &tls.Config{}
|
||||
dialer := &QUICDialerResolver{
|
||||
Resolver: new(net.Resolver), Dialer: &netxmocks.QUICContextDialer{
|
||||
dialer := &quicDialerResolver{
|
||||
Resolver: new(net.Resolver), Dialer: &mocks.QUICContextDialer{
|
||||
MockDialContext: func(ctx context.Context, network, address string,
|
||||
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
|
||||
gotTLSConfig = tlsConfig
|
||||
|
|
@ -334,12 +334,12 @@ func TestQUICDialerResolverApplyTLSDefaults(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQUICDialerLoggerSuccess(t *testing.T) {
|
||||
d := &QUICDialerLogger{
|
||||
Dialer: &netxmocks.QUICContextDialer{
|
||||
d := &quicDialerLogger{
|
||||
Dialer: &mocks.QUICContextDialer{
|
||||
MockDialContext: func(ctx context.Context, network string,
|
||||
address string, tlsConfig *tls.Config,
|
||||
quicConfig *quic.Config) (quic.EarlySession, error) {
|
||||
return &netxmocks.QUICEarlySession{
|
||||
return &mocks.QUICEarlySession{
|
||||
MockCloseWithError: func(
|
||||
code quic.ApplicationErrorCode, reason string) error {
|
||||
return nil
|
||||
|
|
@ -363,8 +363,8 @@ func TestQUICDialerLoggerSuccess(t *testing.T) {
|
|||
|
||||
func TestQUICDialerLoggerFailure(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
d := &QUICDialerLogger{
|
||||
Dialer: &netxmocks.QUICContextDialer{
|
||||
d := &quicDialerLogger{
|
||||
Dialer: &mocks.QUICContextDialer{
|
||||
MockDialContext: func(ctx context.Context, network string,
|
||||
address string, tlsConfig *tls.Config,
|
||||
quicConfig *quic.Config) (quic.EarlySession, error) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue