-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #549 from ooni/issue/1839
stable: backport from master useful patches for 3.11.0 See ooni/probe#1839
- Loading branch information
Showing
13 changed files
with
359 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
internal/cmd/oohelperd/internal/webconnectivity/dns_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package webconnectivity | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" | ||
"github.com/ooni/probe-cli/v3/internal/netxlite" | ||
"github.com/ooni/probe-cli/v3/internal/netxlite/mocks" | ||
) | ||
|
||
func stringPointerForString(s string) *string { | ||
return &s | ||
} | ||
|
||
func Test_dnsMapFailure(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
failure *string | ||
want *string | ||
}{{ | ||
name: "nil", | ||
failure: nil, | ||
want: nil, | ||
}, { | ||
name: "nxdomain", | ||
failure: stringPointerForString(netxlite.FailureDNSNXDOMAINError), | ||
want: stringPointerForString(webconnectivity.DNSNameError), | ||
}, { | ||
name: "no answer", | ||
failure: stringPointerForString(netxlite.FailureDNSNoAnswer), | ||
want: nil, | ||
}, { | ||
name: "non recoverable failure", | ||
failure: stringPointerForString(netxlite.FailureDNSNonRecoverableFailure), | ||
want: stringPointerForString("dns_server_failure"), | ||
}, { | ||
name: "refused", | ||
failure: stringPointerForString(netxlite.FailureDNSRefusedError), | ||
want: stringPointerForString("dns_server_failure"), | ||
}, { | ||
name: "server misbehaving", | ||
failure: stringPointerForString(netxlite.FailureDNSServerMisbehaving), | ||
want: stringPointerForString("dns_server_failure"), | ||
}, { | ||
name: "temporary failure", | ||
failure: stringPointerForString(netxlite.FailureDNSTemporaryFailure), | ||
want: stringPointerForString("dns_server_failure"), | ||
}, { | ||
name: "anything else", | ||
failure: stringPointerForString(netxlite.FailureEOFError), | ||
want: stringPointerForString("unknown_error"), | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := dnsMapFailure(tt.failure) | ||
if diff := cmp.Diff(tt.want, got); diff != "" { | ||
t.Fatal(diff) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestDNSDo(t *testing.T) { | ||
t.Run("returns non-nil addresses list on nxdomin", func(t *testing.T) { | ||
ctx := context.Background() | ||
config := &DNSConfig{ | ||
Domain: "antani.ooni.org", | ||
Out: make(chan webconnectivity.ControlDNSResult, 1), | ||
Resolver: &mocks.Resolver{ | ||
MockLookupHost: func(ctx context.Context, domain string) ([]string, error) { | ||
return nil, netxlite.ErrOODNSNoSuchHost | ||
}, | ||
}, | ||
Wg: &sync.WaitGroup{}, | ||
} | ||
config.Wg.Add(1) | ||
DNSDo(ctx, config) | ||
config.Wg.Wait() | ||
resp := <-config.Out | ||
if resp.Addrs == nil || len(resp.Addrs) != 0 { | ||
t.Fatal("returned nil Addrs or Addrs containing replies") | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.