feat: clearly indicate which resolver we're using (#885)

See what we documented at https://github.com/ooni/spec/pull/257

Reference issue: https://github.com/ooni/probe/issues/2238

See also the related ooni/spec PR: https://github.com/ooni/spec/pull/257

See also https://github.com/ooni/probe/issues/2237

While there, bump webconnectivity@v0.5 version because this change
has an impact onto the generated data format.

The drop in coverage is unavoidable because we've written some
tests for `measurex` to ensure we deal with DNS resolvers and transport
names correctly depending on the splitting policy we use.

(However, `measurex` is only used for the `tor` experiment and, per
the step-by-step design document, new experiments should use
`measurexlite` instead, so this is hopefully fine(TM).)

While there, fix a broken integration test that does not run in `-short` mode.
This commit is contained in:
Simone Basso
2022-08-27 15:47:48 +02:00
committed by GitHub
parent c3964e43b3
commit 8a0c062844
19 changed files with 362 additions and 59 deletions
+2 -1
View File
@@ -11,6 +11,7 @@ import (
"time"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/tracex"
)
// WrapDNSXRoundTripper creates a new DNSXRoundTripper that
@@ -42,7 +43,7 @@ func (txp *dnsxRoundTripperDB) RoundTrip(
response, err := txp.DNSTransport.RoundTrip(ctx, query)
finished := time.Since(txp.begin).Seconds()
txp.db.InsertIntoDNSRoundTrip(&DNSRoundTripEvent{
Network: txp.DNSTransport.Network(),
Network: tracex.ResolverNetworkAdaptNames(txp.DNSTransport.Network()),
Address: txp.DNSTransport.Address(),
Query: txp.maybeQueryBytes(query),
Started: started,
+47
View File
@@ -0,0 +1,47 @@
package measurex
import (
"context"
"testing"
"github.com/miekg/dns"
"github.com/ooni/probe-cli/v3/internal/model/mocks"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
func TestDNSXModifiesStdlibTransportName(t *testing.T) {
// See https://github.com/ooni/spec/pull/257 for more information.
child := netxlite.NewDNSOverGetaddrinfoTransport()
mx := NewMeasurerWithDefaultSettings()
dbout := &MeasurementDB{}
txp := mx.WrapDNSXRoundTripper(dbout, child)
ctx, cancel := context.WithCancel(context.Background())
cancel() // we want to fail immediately
query := &mocks.DNSQuery{
MockDomain: func() string {
return "dns.google"
},
MockType: func() uint16 {
return dns.TypeANY
},
MockBytes: func() ([]byte, error) {
return []byte{}, nil
},
MockID: func() uint16 {
return 1453
},
}
_, _ = txp.RoundTrip(ctx, query)
measurement := dbout.AsMeasurement()
var good int
for _, rtinfo := range measurement.DNSRoundTrip {
network := rtinfo.Network
if network != netxlite.StdlibResolverSystem {
t.Fatal("unexpected network", network)
}
good++
}
if good < 1 {
t.Fatal("no good entry seen")
}
}
+3 -2
View File
@@ -13,6 +13,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/tracex"
)
// WrapResolver creates a new Resolver that saves events into the WritableDB.
@@ -105,7 +106,7 @@ func (r *resolverDB) LookupHost(ctx context.Context, domain string) ([]string, e
func (r *resolverDB) saveLookupResults(domain string, started, finished float64,
err error, addrs []string, qtype string) {
ev := &DNSLookupEvent{
Network: r.Resolver.Network(),
Network: tracex.ResolverNetworkAdaptNames(r.Resolver.Network()),
Address: r.Resolver.Address(),
Failure: NewFailure(err),
Domain: domain,
@@ -158,7 +159,7 @@ func (r *resolverDB) LookupHTTPS(ctx context.Context, domain string) (*model.HTT
https, err := r.Resolver.LookupHTTPS(ctx, domain)
finished := time.Since(r.begin).Seconds()
ev := &DNSLookupEvent{
Network: r.Resolver.Network(),
Network: tracex.ResolverNetworkAdaptNames(r.Resolver.Network()),
Address: r.Resolver.Address(),
Domain: domain,
QueryType: "HTTPS",
+58
View File
@@ -0,0 +1,58 @@
package measurex
import (
"context"
"testing"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
func TestResolverModifiesStdlibResolverName(t *testing.T) {
// See https://github.com/ooni/spec/pull/257 for more information.
t.Run("for LookupHost", func(t *testing.T) {
child := netxlite.NewStdlibResolver(model.DiscardLogger)
mx := NewMeasurerWithDefaultSettings()
dbout := &MeasurementDB{}
txp := mx.WrapResolver(dbout, child)
ctx, cancel := context.WithCancel(context.Background())
cancel() // we want to fail immediately
_, _ = txp.LookupHost(ctx, "dns.google")
measurement := dbout.AsMeasurement()
var good int
for _, rtinfo := range measurement.LookupHost {
network := rtinfo.Network
if network != netxlite.StdlibResolverSystem {
t.Fatal("unexpected network", network)
}
good++
}
if good < 1 {
t.Fatal("no good entry seen")
}
})
t.Run("for LookupHTTPS", func(t *testing.T) {
child := netxlite.NewStdlibResolver(model.DiscardLogger)
mx := NewMeasurerWithDefaultSettings()
dbout := &MeasurementDB{}
txp := mx.WrapResolver(dbout, child)
ctx, cancel := context.WithCancel(context.Background())
cancel() // we want to fail immediately
_, _ = txp.LookupHTTPS(ctx, "dns.google")
measurement := dbout.AsMeasurement()
var good int
for _, rtinfo := range measurement.LookupHTTPSSvc {
network := rtinfo.Network
if network != netxlite.StdlibResolverSystem {
t.Fatal("unexpected network", network)
}
good++
}
if good < 1 {
t.Fatal("no good entry seen")
}
})
}