fix(geolocate): always use netxlite functionality (#976)

This change ensures that, in turn, we're able to "remote" all the traffic generated by the `geolocate` package, rather than missing some bits of it that were still using the standard library and caused _some_ geolocations to geolocate as the local host rather than as the remote host.

Extracted from https://github.com/ooni/probe-cli/pull/969, where we tested this functionality.

Closes https://github.com/ooni/probe/issues/1383 (which was long overdue).

Part of https://github.com/ooni/probe/issues/2340, because it allows us to make progress with that.
This commit is contained in:
Simone Basso 2022-10-12 18:07:42 +02:00 committed by GitHub
commit 57a3919d2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 93 additions and 32 deletions

View file

@ -4,10 +4,16 @@ import (
"context"
"errors"
"testing"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
func TestLookupResolverIP(t *testing.T) {
addr, err := (resolverLookupClient{}).LookupResolverIP(context.Background())
rlc := resolverLookupClient{
Resolver: netxlite.NewStdlibResolver(model.DiscardLogger),
}
addr, err := rlc.LookupResolverIP(context.Background())
if err != nil {
t.Fatal(err)
}
@ -26,7 +32,9 @@ func (bhl brokenHostLookupper) LookupHost(ctx context.Context, host string) ([]s
func TestLookupResolverIPFailure(t *testing.T) {
expected := errors.New("mocked error")
rlc := resolverLookupClient{}
rlc := resolverLookupClient{
Resolver: netxlite.NewStdlibResolver(model.DiscardLogger),
}
addr, err := rlc.do(context.Background(), brokenHostLookupper{
err: expected,
})
@ -39,7 +47,9 @@ func TestLookupResolverIPFailure(t *testing.T) {
}
func TestLookupResolverIPNoAddressReturned(t *testing.T) {
rlc := resolverLookupClient{}
rlc := resolverLookupClient{
Resolver: netxlite.NewStdlibResolver(model.DiscardLogger),
}
addr, err := rlc.do(context.Background(), brokenHostLookupper{})
if !errors.Is(err, ErrNoIPAddressReturned) {
t.Fatalf("not the error we expected: %+v", err)