fix(webconnectivity): allow measuring https://1.1.1.1 (#241)
* fix(webconnectivity): allow measuring https://1.1.1.1 There were two issues preventing us from doing so: 1. in netx, the address resolver was too later in the resolver chain. Therefore, its result wasn't added to the events. 2. when building the DNSCache (in httpget.go), we didn't consider the case where the input is an address. We need to treat this case specially to make sure there is no DNSCache. See https://github.com/ooni/probe/issues/1376. * fix: add unit tests for code making the dnscache * fix(netx): make sure all tests pass * chore: bump webconnectivity version
This commit is contained in:
@@ -57,13 +57,13 @@ func Control(
|
||||
HTTPClient: sess.DefaultHTTPClient(),
|
||||
Logger: sess.Logger(),
|
||||
}
|
||||
sess.Logger().Infof("control %s...", creq.HTTPRequest)
|
||||
sess.Logger().Infof("control for %s...", creq.HTTPRequest)
|
||||
// make sure error is wrapped
|
||||
err = errorx.SafeErrWrapperBuilder{
|
||||
Error: clnt.PostJSON(ctx, "/", creq, &out),
|
||||
Operation: errorx.TopLevelOperation,
|
||||
}.MaybeBuild()
|
||||
sess.Logger().Infof("control %s... %+v", creq.HTTPRequest, err)
|
||||
sess.Logger().Infof("control for %s... %+v", creq.HTTPRequest, err)
|
||||
(&out.DNS).FillASNs(sess)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ func DNSLookup(ctx context.Context, config DNSLookupConfig) (out DNSLookupResult
|
||||
}
|
||||
if answer.IPv6 != "" {
|
||||
out.Addrs[answer.IPv6] = answer.ASN
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package webconnectivity
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
@@ -25,6 +26,22 @@ type HTTPGetResult struct {
|
||||
Failure *string
|
||||
}
|
||||
|
||||
// TODO(bassosimone): Web Connectivity uses too much external testing
|
||||
// and we should actually expose much less to the outside by using
|
||||
// internal testing and by making _many_ functions private.
|
||||
|
||||
// HTTPGetMakeDNSCache constructs the DNSCache option for HTTPGet
|
||||
// by combining domain and addresses into a single string. As a
|
||||
// corner case, if the domain is an IP address, we return an empty
|
||||
// string. This corner case corresponds to Web Connectivity
|
||||
// inputs like https://1.1.1.1.
|
||||
func HTTPGetMakeDNSCache(domain, addresses string) string {
|
||||
if net.ParseIP(domain) != nil {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%s %s", domain, addresses)
|
||||
}
|
||||
|
||||
// HTTPGet performs the HTTP/HTTPS part of Web Connectivity.
|
||||
func HTTPGet(ctx context.Context, config HTTPGetConfig) (out HTTPGetResult) {
|
||||
addresses := strings.Join(config.Addresses, " ")
|
||||
@@ -38,7 +55,7 @@ func HTTPGet(ctx context.Context, config HTTPGetConfig) (out HTTPGetResult) {
|
||||
domain := config.TargetURL.Hostname()
|
||||
result, err := urlgetter.Getter{
|
||||
Config: urlgetter.Config{
|
||||
DNSCache: fmt.Sprintf("%s %s", domain, addresses),
|
||||
DNSCache: HTTPGetMakeDNSCache(domain, addresses),
|
||||
},
|
||||
Session: config.Session,
|
||||
Target: target,
|
||||
|
||||
@@ -25,3 +25,20 @@ func TestHTTPGet(t *testing.T) {
|
||||
t.Fatal(*r.Failure)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPGetMakeDNSCache(t *testing.T) {
|
||||
// test for input being an IP
|
||||
out := webconnectivity.HTTPGetMakeDNSCache(
|
||||
"1.1.1.1", "1.1.1.1",
|
||||
)
|
||||
if out != "" {
|
||||
t.Fatal("expected empty output here")
|
||||
}
|
||||
// test for input being a domain
|
||||
out = webconnectivity.HTTPGetMakeDNSCache(
|
||||
"dns.google", "8.8.8.8 8.8.4.4",
|
||||
)
|
||||
if out != "dns.google 8.8.8.8 8.8.4.4" {
|
||||
t.Fatal("expected ordinary output here")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
const (
|
||||
testName = "web_connectivity"
|
||||
testVersion = "0.2.0"
|
||||
testVersion = "0.3.0"
|
||||
)
|
||||
|
||||
// Config contains the experiment config.
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestNewExperimentMeasurer(t *testing.T) {
|
||||
if measurer.ExperimentName() != "web_connectivity" {
|
||||
t.Fatal("unexpected name")
|
||||
}
|
||||
if measurer.ExperimentVersion() != "0.2.0" {
|
||||
if measurer.ExperimentVersion() != "0.3.0" {
|
||||
t.Fatal("unexpected version")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user