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:
parent
b834af83ac
commit
3caf5800a2
2 changed files with 49 additions and 5 deletions
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue