bdns: Remove LookupMX. (#4202)

We used to use this for checking email domains on registration, but not
anymore.
This commit is contained in:
Jacob Hoffman-Andrews 2019-05-06 06:29:44 -07:00 committed by Daniel McCarney
parent 825277f62e
commit 4c420e2bc2
3 changed files with 1 additions and 57 deletions

View File

@ -148,7 +148,6 @@ type DNSClient interface {
LookupTXT(context.Context, string) (txts []string, authorities []string, err error)
LookupHost(context.Context, string) ([]net.IP, error)
LookupCAA(context.Context, string) ([]*dns.CAA, error)
LookupMX(context.Context, string) ([]string, error)
}
// DNSClientImpl represents a client that talks to an external resolver
@ -481,25 +480,3 @@ func (dnsClient *DNSClientImpl) LookupCAA(ctx context.Context, hostname string)
}
return CAAs, nil
}
// LookupMX sends a DNS query to find a MX record associated hostname and returns the
// record target.
func (dnsClient *DNSClientImpl) LookupMX(ctx context.Context, hostname string) ([]string, error) {
dnsType := dns.TypeMX
r, err := dnsClient.exchangeOne(ctx, hostname, dnsType)
if err != nil {
return nil, &DNSError{dnsType, hostname, err, -1}
}
if r.Rcode != dns.RcodeSuccess {
return nil, &DNSError{dnsType, hostname, nil, r.Rcode}
}
var results []string
for _, answer := range r.Answer {
if mx, ok := answer.(*dns.MX); ok {
results = append(results, mx.Mx)
}
}
return results, nil
}

View File

@ -5,7 +5,6 @@ import (
"fmt"
"net"
"os"
"strings"
"github.com/miekg/dns"
"golang.org/x/net/context"
@ -65,13 +64,9 @@ func (t timeoutError) Timeout() bool {
}
// LookupHost is a mock
//
// Note: see comments on LookupMX regarding email.only
//
func (mock *MockDNSClient) LookupHost(_ context.Context, hostname string) ([]net.IP, error) {
if hostname == "always.invalid" ||
hostname == "invalid.invalid" ||
hostname == "email.only" {
hostname == "invalid.invalid" {
return []net.IP{}, nil
}
if hostname == "always.timeout" {
@ -102,27 +97,3 @@ func (mock *MockDNSClient) LookupHost(_ context.Context, hostname string) ([]net
func (mock *MockDNSClient) LookupCAA(_ context.Context, domain string) ([]*dns.CAA, error) {
return nil, nil
}
// LookupMX is a mock
//
// Note: the email.only domain must have an MX but no A or AAAA
// records. The mock LookupHost returns an address of 127.0.0.1 for
// all domains except for special cases, so MX-only domains must be
// handled in both LookupHost and LookupMX.
//
func (mock *MockDNSClient) LookupMX(_ context.Context, domain string) ([]string, error) {
switch strings.TrimRight(domain, ".") {
case "letsencrypt.org":
fallthrough
case "email.only":
fallthrough
case "email.com":
return []string{"mail.email.com"}, nil
case "always.error":
return []string{}, &DNSError{dns.TypeA, "always.error",
&net.OpError{Err: errors.New("always.error always errors")}, -1}
case "always.timeout":
return []string{}, &DNSError{dns.TypeA, "always.timeout", MockTimeoutError(), -1}
}
return nil, nil
}

View File

@ -33,10 +33,6 @@ func (mock caaMockDNS) LookupHost(_ context.Context, hostname string) ([]net.IP,
return []net.IP{ip}, nil
}
func (mock caaMockDNS) LookupMX(_ context.Context, domain string) ([]string, error) {
return nil, nil
}
func (mock caaMockDNS) LookupCAA(_ context.Context, domain string) ([]*dns.CAA, error) {
var results []*dns.CAA
var record dns.CAA