fix(netx): make sure we save quic udp conn events (#423)

https://github.com/ooni/probe-cli/pull/421 was wrong because we need
a more rich interface for quic-go to call ReadMsgUDP.

With this commit, we use such an interface: OOBCapablePacketConn.

Still part of https://github.com/ooni/probe/issues/1505.
This commit is contained in:
Simone Basso 2021-07-02 11:00:12 +02:00 committed by GitHub
commit ceb2aa8a8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 82 additions and 49 deletions

View file

@ -6,18 +6,18 @@ import (
"errors"
"net"
"reflect"
"syscall"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/lucas-clemente/quic-go"
"github.com/ooni/probe-cli/v3/internal/quicx"
)
func TestQUICListenerListen(t *testing.T) {
expected := errors.New("mocked error")
ql := &QUICListener{
MockListen: func(addr *net.UDPAddr) (quicx.UDPConn, error) {
MockListen: func(addr *net.UDPAddr) (quic.OOBCapablePacketConn, error) {
return nil, expected
},
}
@ -417,3 +417,41 @@ func TestQUICUDPConnReadFrom(t *testing.T) {
t.Fatal("expected nil here")
}
}
func TestQUICUDPConnSyscallConn(t *testing.T) {
expected := errors.New("mocked error")
quc := &QUICUDPConn{
MockSyscallConn: func() (syscall.RawConn, error) {
return nil, expected
},
}
conn, err := quc.SyscallConn()
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
if conn != nil {
t.Fatal("expected nil here")
}
}
func TestQUICUDPConnWriteMsgUDP(t *testing.T) {
expected := errors.New("mocked error")
quc := &QUICUDPConn{
MockWriteMsgUDP: func(b, oob []byte, addr *net.UDPAddr) (n int, oobn int, err error) {
return 0, 0, expected
},
}
b := make([]byte, 128)
oob := make([]byte, 128)
addr := &net.UDPAddr{}
n, oobn, err := quc.WriteMsgUDP(b, oob, addr)
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
if n != 0 {
t.Fatal("expected 0 here")
}
if oobn != 0 {
t.Fatal("expected 0 here")
}
}