ooni-probe-cli/internal/engine/experiment/webconnectivity/httpget_test.go
Simone Basso 2ef5fb503a
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
2021-03-08 12:05:43 +01:00

45 lines
1.0 KiB
Go

package webconnectivity_test
import (
"context"
"net/url"
"testing"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
)
func TestHTTPGet(t *testing.T) {
if testing.Short() {
t.Skip("skip test in short mode")
}
ctx := context.Background()
r := webconnectivity.HTTPGet(ctx, webconnectivity.HTTPGetConfig{
Addresses: []string{"104.16.249.249", "104.16.248.249"},
Session: newsession(t, false),
TargetURL: &url.URL{Scheme: "https", Host: "cloudflare-dns.com", Path: "/"},
})
if r.TestKeys.Failure != nil {
t.Fatal(*r.TestKeys.Failure)
}
if r.Failure != nil {
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")
}
}