1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-01-28 20:56:03 +00:00

courier: Extend MX lookup tests

This patch adds more tests to the MX lookup process, covering some
unusual cases that were missing.
This commit is contained in:
Alberto Bertogli
2018-06-03 23:52:30 +01:00
parent b24f02e3a5
commit 26017548ef
2 changed files with 92 additions and 10 deletions

View File

@@ -26,8 +26,10 @@ var (
smtpPort = flag.String("testing__outgoing_smtp_port", "25",
"port to use for outgoing SMTP connections, ONLY FOR TESTING")
// Fake MX records, used for testing only.
fakeMX = map[string][]string{}
// Allow overriding of net.LookupMX for testing purposes.
// TODO: replace this with proper lookup interception once it is supported
// by Go.
netLookupMX = net.LookupMX
)
// Exported variables.
@@ -198,10 +200,6 @@ retry:
}
func lookupMXs(tr *trace.Trace, domain string) ([]string, error) {
if v, ok := fakeMX[domain]; ok {
return v, nil
}
domain, err := idna.ToASCII(domain)
if err != nil {
return nil, err
@@ -209,7 +207,7 @@ func lookupMXs(tr *trace.Trace, domain string) ([]string, error) {
mxs := []string{}
mxRecords, err := net.LookupMX(domain)
mxRecords, err := netLookupMX(domain)
if err != nil {
// There was an error. It could be that the domain has no MX, in which
// case we have to fall back to A, or a bigger problem.