headscale/hscontrol/dns_test.go

110 lines
2.3 KiB
Go
Raw Normal View History

package hscontrol
2021-10-09 04:22:21 -06:00
import (
2022-09-02 01:15:05 -06:00
"net/netip"
2021-10-09 04:22:21 -06:00
"gopkg.in/check.v1"
)
func (s *Suite) TestMagicDNSRootDomains100(c *check.C) {
2022-09-02 01:15:05 -06:00
prefixes := []netip.Prefix{
netip.MustParsePrefix("100.64.0.0/10"),
2022-01-15 08:18:49 -07:00
}
domains := generateMagicDNSRootDomains(prefixes)
2021-10-09 04:22:21 -06:00
found := false
2021-10-10 04:43:41 -06:00
for _, domain := range domains {
2021-10-09 04:22:21 -06:00
if domain == "64.100.in-addr.arpa." {
found = true
2021-11-14 08:46:09 -07:00
2021-10-09 04:22:21 -06:00
break
}
}
c.Assert(found, check.Equals, true)
found = false
2021-10-10 04:43:41 -06:00
for _, domain := range domains {
2021-10-09 04:22:21 -06:00
if domain == "100.100.in-addr.arpa." {
found = true
2021-11-14 08:46:09 -07:00
2021-10-09 04:22:21 -06:00
break
}
}
c.Assert(found, check.Equals, true)
found = false
2021-10-10 04:43:41 -06:00
for _, domain := range domains {
2021-10-09 04:22:21 -06:00
if domain == "127.100.in-addr.arpa." {
found = true
2021-11-14 08:46:09 -07:00
2021-10-09 04:22:21 -06:00
break
}
}
c.Assert(found, check.Equals, true)
}
func (s *Suite) TestMagicDNSRootDomains172(c *check.C) {
2022-09-02 01:15:05 -06:00
prefixes := []netip.Prefix{
netip.MustParsePrefix("172.16.0.0/16"),
2022-01-15 08:18:49 -07:00
}
domains := generateMagicDNSRootDomains(prefixes)
2021-10-09 04:22:21 -06:00
found := false
2021-10-10 04:43:41 -06:00
for _, domain := range domains {
2021-10-09 04:22:21 -06:00
if domain == "0.16.172.in-addr.arpa." {
found = true
2021-11-14 08:46:09 -07:00
2021-10-09 04:22:21 -06:00
break
}
}
c.Assert(found, check.Equals, true)
found = false
2021-10-10 04:43:41 -06:00
for _, domain := range domains {
2021-10-09 04:22:21 -06:00
if domain == "255.16.172.in-addr.arpa." {
found = true
2021-11-14 08:46:09 -07:00
2021-10-09 04:22:21 -06:00
break
}
}
c.Assert(found, check.Equals, true)
}
2022-01-15 08:18:49 -07:00
// Happens when netmask is a multiple of 4 bits (sounds likely).
func (s *Suite) TestMagicDNSRootDomainsIPv6Single(c *check.C) {
2022-09-02 01:15:05 -06:00
prefixes := []netip.Prefix{
netip.MustParsePrefix("fd7a:115c:a1e0::/48"),
2022-01-15 08:18:49 -07:00
}
domains := generateMagicDNSRootDomains(prefixes)
c.Assert(len(domains), check.Equals, 1)
2022-01-25 15:11:15 -07:00
c.Assert(
domains[0].WithTrailingDot(),
check.Equals,
"0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa.",
)
2022-01-15 08:18:49 -07:00
}
func (s *Suite) TestMagicDNSRootDomainsIPv6SingleMultiple(c *check.C) {
2022-09-02 01:15:05 -06:00
prefixes := []netip.Prefix{
netip.MustParsePrefix("fd7a:115c:a1e0::/50"),
2022-01-15 08:18:49 -07:00
}
domains := generateMagicDNSRootDomains(prefixes)
yieldsRoot := func(dom string) bool {
for _, candidate := range domains {
if candidate.WithTrailingDot() == dom {
return true
}
}
return false
}
c.Assert(len(domains), check.Equals, 4)
c.Assert(yieldsRoot("0.0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa."), check.Equals, true)
c.Assert(yieldsRoot("1.0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa."), check.Equals, true)
c.Assert(yieldsRoot("2.0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa."), check.Equals, true)
c.Assert(yieldsRoot("3.0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa."), check.Equals, true)
}