feat: add uTLS support in measurexlite (#918)
Closes https://github.com/ooni/probe/issues/2253 Co-authored-by: decfox <decfox@github.com>
This commit is contained in:
parent
9e8ad551aa
commit
59d8b6ecef
4 changed files with 136 additions and 1 deletions
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/ooni/probe-cli/v3/internal/model/mocks"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
"github.com/ooni/probe-cli/v3/internal/testingx"
|
||||
utls "gitlab.com/yawning/utls.git"
|
||||
)
|
||||
|
||||
func TestNewTrace(t *testing.T) {
|
||||
|
|
@ -78,6 +79,12 @@ func TestNewTrace(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("newTLShandshakerUTLSFn is nil", func(t *testing.T) {
|
||||
if trace.NewTLSHandshakerUTLSFn != nil {
|
||||
t.Fatal("expected nil NewTLSHandshakerUTLSfn")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("NewQUICDialerWithoutResolverFn is nil", func(t *testing.T) {
|
||||
if trace.NewQUICDialerWithoutResolverFn != nil {
|
||||
t.Fatal("expected nil NewQUICDialerQithoutResolverFn")
|
||||
|
|
@ -426,6 +433,76 @@ func TestTrace(t *testing.T) {
|
|||
})
|
||||
})
|
||||
|
||||
t.Run("NewTLSHandshakerUTLSFn works as intended", func(t *testing.T) {
|
||||
t.Run("when not nil", func(t *testing.T) {
|
||||
mockedErr := errors.New("mocked")
|
||||
tx := &Trace{
|
||||
NewTLSHandshakerUTLSFn: func(dl model.DebugLogger, id *utls.ClientHelloID) model.TLSHandshaker {
|
||||
return &mocks.TLSHandshaker{
|
||||
MockHandshake: func(ctx context.Context, conn net.Conn, config *tls.Config) (net.Conn, tls.ConnectionState, error) {
|
||||
return nil, tls.ConnectionState{}, mockedErr
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
thx := tx.NewTLSHandshakerUTLS(model.DiscardLogger, &utls.HelloGolang)
|
||||
ctx := context.Background()
|
||||
conn, state, err := thx.Handshake(ctx, &mocks.Conn{}, &tls.Config{})
|
||||
if !errors.Is(err, mockedErr) {
|
||||
t.Fatal("unexpected err", err)
|
||||
}
|
||||
if !reflect.ValueOf(state).IsZero() {
|
||||
t.Fatal("state is not a zero value")
|
||||
}
|
||||
if conn != nil {
|
||||
t.Fatal("expected nil conn")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("when nil", func(t *testing.T) {
|
||||
mockedErr := errors.New("mocked")
|
||||
tx := &Trace{
|
||||
NewTLSHandshakerStdlibFn: nil,
|
||||
}
|
||||
thx := tx.newTLSHandshakerUTLS(model.DiscardLogger, &utls.HelloGolang)
|
||||
tcpConn := &mocks.Conn{
|
||||
MockSetDeadline: func(t time.Time) error {
|
||||
return nil
|
||||
},
|
||||
MockRemoteAddr: func() net.Addr {
|
||||
return &mocks.Addr{
|
||||
MockNetwork: func() string {
|
||||
return "tcp"
|
||||
},
|
||||
MockString: func() string {
|
||||
return "1.1.1.1:443"
|
||||
},
|
||||
}
|
||||
},
|
||||
MockWrite: func(b []byte) (int, error) {
|
||||
return 0, mockedErr
|
||||
},
|
||||
MockClose: func() error {
|
||||
return nil
|
||||
},
|
||||
}
|
||||
tlsConfig := &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
ctx := context.Background()
|
||||
conn, state, err := thx.Handshake(ctx, tcpConn, tlsConfig)
|
||||
if !errors.Is(err, mockedErr) {
|
||||
t.Fatal("unexpected err", err)
|
||||
}
|
||||
if !reflect.ValueOf(state).IsZero() {
|
||||
t.Fatal("state is not a zero value")
|
||||
}
|
||||
if conn != nil {
|
||||
t.Fatal("expected nil conn")
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("NewQUICDialerWithoutResolverFn works as intended", func(t *testing.T) {
|
||||
t.Run("when not nil", func(t *testing.T) {
|
||||
mockedErr := errors.New("mocked")
|
||||
|
|
|
|||
Loading…
Reference in a new issue