d57c78bc71
This is how I did it: 1. `git clone https://github.com/ooni/probe-engine internal/engine` 2. ``` (cd internal/engine && git describe --tags) v0.23.0 ``` 3. `nvim go.mod` (merging `go.mod` with `internal/engine/go.mod` 4. `rm -rf internal/.git internal/engine/go.{mod,sum}` 5. `git add internal/engine` 6. `find . -type f -name \*.go -exec sed -i 's@/ooni/probe-engine@/ooni/probe-cli/v3/internal/engine@g' {} \;` 7. `go build ./...` (passes) 8. `go test -race ./...` (temporary failure on RiseupVPN) 9. `go mod tidy` 10. this commit message Once this piece of work is done, we can build a new version of `ooniprobe` that is using `internal/engine` directly. We need to do more work to ensure all the other functionality in `probe-engine` (e.g. making mobile packages) are still WAI. Part of https://github.com/ooni/probe/issues/1335
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package quicdialer_test
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"testing"
|
|
|
|
"github.com/lucas-clemente/quic-go"
|
|
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
|
|
"github.com/ooni/probe-cli/v3/internal/engine/netx/quicdialer"
|
|
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace"
|
|
)
|
|
|
|
func TestSystemDialerInvalidIPFailure(t *testing.T) {
|
|
tlsConf := &tls.Config{
|
|
NextProtos: []string{"h3-29"},
|
|
ServerName: "www.google.com",
|
|
}
|
|
saver := &trace.Saver{}
|
|
systemdialer := quicdialer.SystemDialer{
|
|
Saver: saver,
|
|
}
|
|
sess, err := systemdialer.DialContext(context.Background(), "udp", "a.b.c.d:0", tlsConf, &quic.Config{})
|
|
if err == nil {
|
|
t.Fatal("expected an error here")
|
|
}
|
|
if sess != nil {
|
|
t.Fatal("expected nil sess here")
|
|
}
|
|
if err.Error() != "quicdialer: invalid IP representation" {
|
|
t.Fatal("expected another error here")
|
|
}
|
|
}
|
|
|
|
func TestSystemDialerSuccessWithReadWrite(t *testing.T) {
|
|
// This is the most common use case for collecting reads, writes
|
|
tlsConf := &tls.Config{
|
|
NextProtos: []string{"h3-29"},
|
|
ServerName: "www.google.com",
|
|
}
|
|
saver := &trace.Saver{}
|
|
systemdialer := quicdialer.SystemDialer{Saver: saver}
|
|
_, err := systemdialer.DialContext(context.Background(), "udp",
|
|
"216.58.212.164:443", tlsConf, &quic.Config{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ev := saver.Read()
|
|
if len(ev) < 2 {
|
|
t.Fatal("unexpected number of events")
|
|
}
|
|
last := len(ev) - 1
|
|
for idx := 1; idx < last; idx++ {
|
|
if ev[idx].Data == nil {
|
|
t.Fatal("unexpected Data")
|
|
}
|
|
if ev[idx].Duration <= 0 {
|
|
t.Fatal("unexpected Duration")
|
|
}
|
|
if ev[idx].Err != nil {
|
|
t.Fatal("unexpected Err")
|
|
}
|
|
if ev[idx].NumBytes <= 0 {
|
|
t.Fatal("unexpected NumBytes")
|
|
}
|
|
switch ev[idx].Name {
|
|
case errorx.ReadFromOperation, errorx.WriteToOperation:
|
|
default:
|
|
t.Fatal("unexpected Name")
|
|
}
|
|
if ev[idx].Time.Before(ev[idx-1].Time) {
|
|
t.Fatal("unexpected Time")
|
|
}
|
|
}
|
|
}
|