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:
parent
86ffd6a0c4
commit
57a3919d2a
11 changed files with 93 additions and 32 deletions
|
|
@ -10,6 +10,8 @@ import (
|
|||
|
||||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/model/mocks"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
"github.com/pion/stun"
|
||||
)
|
||||
|
||||
|
|
@ -19,6 +21,7 @@ func TestSTUNIPLookupCanceledContext(t *testing.T) {
|
|||
ip, err := stunIPLookup(ctx, stunConfig{
|
||||
Endpoint: "stun.ekiga.net:3478",
|
||||
Logger: log.Log,
|
||||
Resolver: netxlite.NewStdlibResolver(model.DiscardLogger),
|
||||
})
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("not the error we expected: %+v", err)
|
||||
|
|
@ -32,8 +35,10 @@ func TestSTUNIPLookupDialFailure(t *testing.T) {
|
|||
expected := errors.New("mocked error")
|
||||
ctx := context.Background()
|
||||
ip, err := stunIPLookup(ctx, stunConfig{
|
||||
Dial: func(network, address string) (stunClient, error) {
|
||||
return nil, expected
|
||||
Dialer: &mocks.Dialer{
|
||||
MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
return nil, expected
|
||||
},
|
||||
},
|
||||
Endpoint: "stun.ekiga.net:3478",
|
||||
Logger: log.Log,
|
||||
|
|
@ -70,11 +75,17 @@ func TestSTUNIPLookupStartReturnsError(t *testing.T) {
|
|||
expected := errors.New("mocked error")
|
||||
ctx := context.Background()
|
||||
ip, err := stunIPLookup(ctx, stunConfig{
|
||||
Dial: func(network, address string) (stunClient, error) {
|
||||
return MockableSTUNClient{StartErr: expected}, nil
|
||||
Dialer: &mocks.Dialer{
|
||||
MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
conn := &mocks.Conn{}
|
||||
return conn, nil
|
||||
},
|
||||
},
|
||||
Endpoint: "stun.ekiga.net:3478",
|
||||
Logger: log.Log,
|
||||
NewClient: func(conn net.Conn) (stunClient, error) {
|
||||
return MockableSTUNClient{StartErr: expected}, nil
|
||||
},
|
||||
})
|
||||
if !errors.Is(err, expected) {
|
||||
t.Fatalf("not the error we expected: %+v", err)
|
||||
|
|
@ -88,13 +99,19 @@ func TestSTUNIPLookupStunEventContainsError(t *testing.T) {
|
|||
expected := errors.New("mocked error")
|
||||
ctx := context.Background()
|
||||
ip, err := stunIPLookup(ctx, stunConfig{
|
||||
Dial: func(network, address string) (stunClient, error) {
|
||||
Dialer: &mocks.Dialer{
|
||||
MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
conn := &mocks.Conn{}
|
||||
return conn, nil
|
||||
},
|
||||
},
|
||||
Endpoint: "stun.ekiga.net:3478",
|
||||
Logger: log.Log,
|
||||
NewClient: func(conn net.Conn) (stunClient, error) {
|
||||
return MockableSTUNClient{Event: stun.Event{
|
||||
Error: expected,
|
||||
}}, nil
|
||||
},
|
||||
Endpoint: "stun.ekiga.net:3478",
|
||||
Logger: log.Log,
|
||||
})
|
||||
if !errors.Is(err, expected) {
|
||||
t.Fatalf("not the error we expected: %+v", err)
|
||||
|
|
@ -107,13 +124,19 @@ func TestSTUNIPLookupStunEventContainsError(t *testing.T) {
|
|||
func TestSTUNIPLookupCannotDecodeMessage(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ip, err := stunIPLookup(ctx, stunConfig{
|
||||
Dial: func(network, address string) (stunClient, error) {
|
||||
Dialer: &mocks.Dialer{
|
||||
MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
conn := &mocks.Conn{}
|
||||
return conn, nil
|
||||
},
|
||||
},
|
||||
Endpoint: "stun.ekiga.net:3478",
|
||||
Logger: log.Log,
|
||||
NewClient: func(conn net.Conn) (stunClient, error) {
|
||||
return MockableSTUNClient{Event: stun.Event{
|
||||
Message: &stun.Message{},
|
||||
}}, nil
|
||||
},
|
||||
Endpoint: "stun.ekiga.net:3478",
|
||||
Logger: log.Log,
|
||||
})
|
||||
if !errors.Is(err, stun.ErrAttributeNotFound) {
|
||||
t.Fatalf("not the error we expected: %+v", err)
|
||||
|
|
@ -129,6 +152,7 @@ func TestIPLookupWorksUsingSTUNEkiga(t *testing.T) {
|
|||
http.DefaultClient,
|
||||
log.Log,
|
||||
model.HTTPHeaderUserAgent,
|
||||
netxlite.NewStdlibResolver(model.DiscardLogger),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -144,6 +168,7 @@ func TestIPLookupWorksUsingSTUNGoogle(t *testing.T) {
|
|||
http.DefaultClient,
|
||||
log.Log,
|
||||
model.HTTPHeaderUserAgent,
|
||||
netxlite.NewStdlibResolver(model.DiscardLogger),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue