2021-07-01 18:00:09 +02:00
|
|
|
package errorsx
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/tls"
|
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
|
2021-09-07 17:09:30 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
|
2021-09-05 14:49:38 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
|
2021-07-01 18:00:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestErrorWrapperTLSHandshakerFailure(t *testing.T) {
|
2021-09-05 14:49:38 +02:00
|
|
|
th := ErrorWrapperTLSHandshaker{TLSHandshaker: &mocks.TLSHandshaker{
|
2021-07-01 18:00:09 +02:00
|
|
|
MockHandshake: func(ctx context.Context, conn net.Conn, config *tls.Config) (net.Conn, tls.ConnectionState, error) {
|
|
|
|
return nil, tls.ConnectionState{}, io.EOF
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
conn, _, err := th.Handshake(
|
2021-09-05 14:49:38 +02:00
|
|
|
context.Background(), &mocks.Conn{
|
2021-07-01 18:00:09 +02:00
|
|
|
MockRead: func(b []byte) (int, error) {
|
|
|
|
return 0, io.EOF
|
|
|
|
},
|
|
|
|
}, new(tls.Config))
|
|
|
|
if !errors.Is(err, io.EOF) {
|
|
|
|
t.Fatal("not the error that we expected")
|
|
|
|
}
|
|
|
|
if conn != nil {
|
|
|
|
t.Fatal("expected nil con here")
|
|
|
|
}
|
2021-09-07 17:09:30 +02:00
|
|
|
var errWrapper *errorsx.ErrWrapper
|
2021-07-01 18:00:09 +02:00
|
|
|
if !errors.As(err, &errWrapper) {
|
|
|
|
t.Fatal("cannot cast to ErrWrapper")
|
|
|
|
}
|
2021-09-07 17:09:30 +02:00
|
|
|
if errWrapper.Failure != errorsx.FailureEOFError {
|
2021-07-01 18:00:09 +02:00
|
|
|
t.Fatal("unexpected Failure")
|
|
|
|
}
|
2021-09-07 17:09:30 +02:00
|
|
|
if errWrapper.Operation != errorsx.TLSHandshakeOperation {
|
2021-07-01 18:00:09 +02:00
|
|
|
t.Fatal("unexpected Operation")
|
|
|
|
}
|
|
|
|
}
|