2021-07-01 20:58:15 +02:00
|
|
|
package errorsx_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/tls"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/lucas-clemente/quic-go"
|
2021-09-07 17:52:42 +02:00
|
|
|
errorsxlegacy "github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx"
|
2021-07-01 20:58:15 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
2021-11-12 14:43:28 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite/quictesting"
|
2021-07-01 20:58:15 +02:00
|
|
|
)
|
|
|
|
|
2021-11-12 14:43:28 +01:00
|
|
|
func TestErrorWrapperQUICDialerFailure(t *testing.T) {
|
2021-07-01 20:58:15 +02:00
|
|
|
nextprotos := []string{"h3"}
|
|
|
|
servername := "example.com"
|
|
|
|
tlsConf := &tls.Config{
|
|
|
|
NextProtos: nextprotos,
|
|
|
|
ServerName: servername,
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:09:30 +02:00
|
|
|
dlr := &errorsxlegacy.ErrorWrapperQUICDialer{Dialer: &netxlite.QUICDialerQUICGo{
|
2021-07-01 20:58:15 +02:00
|
|
|
QUICListener: &netxlite.QUICListenerStdlib{},
|
|
|
|
}}
|
|
|
|
sess, err := dlr.DialContext(context.Background(), "udp",
|
2021-11-12 14:43:28 +01:00
|
|
|
quictesting.Endpoint("443"), tlsConf, &quic.Config{})
|
2021-07-01 20:58:15 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected an error here")
|
|
|
|
}
|
|
|
|
if sess != nil {
|
|
|
|
t.Fatal("expected nil sess here")
|
|
|
|
}
|
2021-11-12 14:43:28 +01:00
|
|
|
if err.Error() != netxlite.FailureSSLFailedHandshake {
|
|
|
|
t.Fatal("unexpected failure", err.Error())
|
2021-07-01 20:58:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestErrorWrapperQUICDialerSuccess(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
tlsConf := &tls.Config{
|
|
|
|
NextProtos: []string{"h3"},
|
2021-11-12 14:43:28 +01:00
|
|
|
ServerName: quictesting.Domain,
|
2021-07-01 20:58:15 +02:00
|
|
|
}
|
2021-09-07 17:09:30 +02:00
|
|
|
d := &errorsxlegacy.ErrorWrapperQUICDialer{Dialer: &netxlite.QUICDialerQUICGo{
|
2021-07-01 20:58:15 +02:00
|
|
|
QUICListener: &netxlite.QUICListenerStdlib{},
|
|
|
|
}}
|
2021-11-12 14:43:28 +01:00
|
|
|
sess, err := d.DialContext(ctx, "udp", quictesting.Endpoint("443"), tlsConf, &quic.Config{})
|
2021-07-01 20:58:15 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if sess == nil {
|
|
|
|
t.Fatal("expected non-nil sess here")
|
|
|
|
}
|
|
|
|
}
|