// (currently restricted to hostname-compatible "preferred name" LDH labels and
// SRV-like "underscore labels"; see golang.org/issue/12421).
func isDomainName(s string) bool {
+ // The root domain name is valid. See golang.org/issue/45715.
+ if s == "." {
+ return true
+ }
+
// See RFC 1035, RFC 3696.
// Presentation format has dots before every label except the first, and the
// terminal empty label is optional here because we assume fully-qualified
t.Errorf("records = [%v]; want [%v]", strings.Join(records, " "), want[0])
}
}
+
+func TestRootNS(t *testing.T) {
+ // See https://golang.org/issue/45715.
+ fake := fakeDNSServer{
+ rh: func(n, _ string, q dnsmessage.Message, _ time.Time) (dnsmessage.Message, error) {
+ r := dnsmessage.Message{
+ Header: dnsmessage.Header{
+ ID: q.Header.ID,
+ Response: true,
+ RCode: dnsmessage.RCodeSuccess,
+ },
+ Questions: q.Questions,
+ Answers: []dnsmessage.Resource{
+ {
+ Header: dnsmessage.ResourceHeader{
+ Name: q.Questions[0].Name,
+ Type: dnsmessage.TypeNS,
+ Class: dnsmessage.ClassINET,
+ },
+ Body: &dnsmessage.NSResource{
+ NS: dnsmessage.MustNewName("i.root-servers.net."),
+ },
+ },
+ },
+ }
+ return r, nil
+ },
+ }
+ r := Resolver{PreferGo: true, Dial: fake.DialContext}
+ rrset, err := r.LookupNS(context.Background(), ".")
+ if err != nil {
+ t.Fatalf("LookupNS: %v", err)
+ }
+ if want := []*NS{&NS{Host: "i.root-servers.net."}}; !reflect.DeepEqual(rrset, want) {
+ records := []string{}
+ for _, rr := range rrset {
+ records = append(records, fmt.Sprintf("%v", rr))
+ }
+ t.Errorf("records = [%v]; want [%v]", strings.Join(records, " "), want[0])
+ }
+}
if mx == nil {
continue
}
- // Bypass the hostname validity check for targets which contain only a dot,
- // as this is used to represent a 'Null' MX record.
- if mx.Host != "." && !isDomainName(mx.Host) {
+ if !isDomainName(mx.Host) {
continue
}
filteredMX = append(filteredMX, mx)