fix(netxlite): gracefully handle utls panics (#462)

* fix(netxlite): gracefully handle utls panics

See https://github.com/ooni/probe/issues/1770

* fix(netxlite): remove wrong timeout from newly written test
This commit is contained in:
Simone Basso 2021-09-05 21:41:49 +02:00 committed by GitHub
commit 3caf5800a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 5 deletions

View file

@ -49,7 +49,7 @@ func TestNewTLSHandshakerUTLSTypes(t *testing.T) {
}
}
func TestUTLSConnHandshakeNotInterrupted(t *testing.T) {
func TestUTLSConnHandshakeNotInterruptedSuccess(t *testing.T) {
ctx := context.Background()
conn := &utlsConn{
testableHandshake: func() error {
@ -62,6 +62,20 @@ func TestUTLSConnHandshakeNotInterrupted(t *testing.T) {
}
}
func TestUTLSConnHandshakeNotInterruptedFailure(t *testing.T) {
expected := errors.New("mocked error")
ctx := context.Background()
conn := &utlsConn{
testableHandshake: func() error {
return expected
},
}
err := conn.HandshakeContext(ctx)
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
}
func TestUTLSConnHandshakeInterrupted(t *testing.T) {
wg := sync.WaitGroup{}
wg.Add(1)
@ -82,3 +96,20 @@ func TestUTLSConnHandshakeInterrupted(t *testing.T) {
close(sigch)
wg.Wait()
}
func TestUTLSConnHandshakePanic(t *testing.T) {
wg := sync.WaitGroup{}
wg.Add(1)
ctx := context.Background()
conn := &utlsConn{
testableHandshake: func() error {
defer wg.Done()
panic("mascetti")
},
}
err := conn.HandshakeContext(ctx)
if !errors.Is(err, ErrUTLSHandshakePanic) {
t.Fatal("not the error we expected", err)
}
wg.Wait()
}