2022-04-14 21:15:54 +00:00
|
|
|
// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package publicdns
|
|
|
|
|
|
|
|
import (
|
2022-07-26 03:55:44 +00:00
|
|
|
"net/netip"
|
2022-04-14 21:15:54 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-07-25 03:08:42 +00:00
|
|
|
"tailscale.com/net/netaddr"
|
2022-04-14 21:15:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestInit(t *testing.T) {
|
|
|
|
for baseKey, baseSet := range DoHIPsOfBase() {
|
|
|
|
for _, addr := range baseSet {
|
|
|
|
if KnownDoH()[addr] != baseKey {
|
|
|
|
t.Errorf("Expected %v to map to %s, got %s", addr, baseKey, KnownDoH()[addr])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDohV6(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
in string
|
|
|
|
firstIP netaddr.IP
|
|
|
|
want bool
|
|
|
|
}{
|
2022-07-26 03:55:44 +00:00
|
|
|
{"https://cloudflare-dns.com/dns-query", netip.MustParseAddr("2606:4700:4700::1111"), true},
|
|
|
|
{"https://dns.google/dns-query", netip.MustParseAddr("2001:4860:4860::8888"), true},
|
2022-04-14 21:15:54 +00:00
|
|
|
{"bogus", netaddr.IP{}, false},
|
|
|
|
}
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.in, func(t *testing.T) {
|
|
|
|
ip, ok := DoHV6(test.in)
|
|
|
|
if ok != test.want || ip != test.firstIP {
|
|
|
|
t.Errorf("DohV6 got (%v: IPv6 %v) for %v, want (%v: IPv6 %v)", ip, ok, test.in, test.firstIP, test.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|