aboutsummaryrefslogtreecommitdiff
path: root/src/net/dnsclient_unix_test.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2016-03-30 23:08:44 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2016-04-02 20:32:36 +0000
commit72c1180852d5b059cd1e51d1db1956ea208b7f2f (patch)
tree8a43bffdeb94549fc47786009fbeadadcc14c4d6 /src/net/dnsclient_unix_test.go
parent0d40dfa745b176a83d91cf0981bdbd3a92e2e547 (diff)
downloadgo-72c1180852d5b059cd1e51d1db1956ea208b7f2f.tar.gz
go-72c1180852d5b059cd1e51d1db1956ea208b7f2f.zip
net: don't do DNS for onion and local addresses
Fixes #13705 Change-Id: I86c60c78ce0394f830f904c9cba83ebbf3efc046 Reviewed-on: https://go-review.googlesource.com/21328 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/dnsclient_unix_test.go')
-rw-r--r--src/net/dnsclient_unix_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/net/dnsclient_unix_test.go b/src/net/dnsclient_unix_test.go
index 4a5c438e46..6845481e17 100644
--- a/src/net/dnsclient_unix_test.go
+++ b/src/net/dnsclient_unix_test.go
@@ -94,6 +94,57 @@ func TestSpecialDomainName(t *testing.T) {
}
}
+// Issue 13705: don't try to resolve onion addresses, etc
+func TestAvoidDNSName(t *testing.T) {
+ tests := []struct {
+ name string
+ avoid bool
+ }{
+ {"foo.com", false},
+ {"foo.com.", false},
+
+ {"foo.onion.", true},
+ {"foo.onion", true},
+ {"foo.ONION", true},
+ {"foo.ONION.", true},
+
+ {"foo.local.", true},
+ {"foo.local", true},
+ {"foo.LOCAL", true},
+ {"foo.LOCAL.", true},
+
+ {"", true}, // will be rejected earlier too
+
+ // Without stuff before onion/local, they're fine to
+ // use DNS. With a search path,
+ // "onion.vegegtables.com" can use DNS. Without a
+ // search path (or with a trailing dot), the queries
+ // are just kinda useless, but don't reveal anything
+ // private.
+ {"local", false},
+ {"onion", false},
+ {"local.", false},
+ {"onion.", false},
+ }
+ for _, tt := range tests {
+ got := avoidDNS(tt.name)
+ if got != tt.avoid {
+ t.Errorf("avoidDNS(%q) = %v; want %v", tt.name, got, tt.avoid)
+ }
+ }
+}
+
+// Issue 13705: don't try to resolve onion addresses, etc
+func TestLookupTorOnion(t *testing.T) {
+ addrs, err := goLookupIP("foo.onion")
+ if len(addrs) > 0 {
+ t.Errorf("unexpected addresses: %v", addrs)
+ }
+ if err != nil {
+ t.Fatalf("lookup = %v; want nil", err)
+ }
+}
+
type resolvConfTest struct {
dir string
path string