mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-01-07 17:47:14 +00:00
test: Add a test for Exim interactions
This patch adds a new test which makes chasquid send and receive email to/from Exim. To make it work we need to add two testing flags to the SMTP courier, which is not ideal but doesn't muddle the code much. The test is not very portable, and assumes an exim binary is available, but does not have to be installed in the system. It includes a helper script to fetch one from the Debian archives.
This commit is contained in:
@@ -2,6 +2,7 @@ package courier
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"flag"
|
||||
"net"
|
||||
"net/smtp"
|
||||
"time"
|
||||
@@ -19,7 +20,12 @@ var (
|
||||
|
||||
// Port for outgoing SMTP.
|
||||
// Tests can override this.
|
||||
smtpPort = "25"
|
||||
smtpPort = flag.String("testing__outgoing_smtp_port", "25",
|
||||
"port to use for outgoing SMTP connections, ONLY FOR TESTING")
|
||||
|
||||
// Bypass the MX lookup, for testing purposes.
|
||||
bypassMX = flag.Bool("testing__bypass_mx_lookup", false,
|
||||
"bypass MX lookup, ONLY FOR TESTING")
|
||||
|
||||
// Fake MX records, used for testing only.
|
||||
fakeMX = map[string]string{}
|
||||
@@ -45,7 +51,7 @@ func (s *SMTP) Deliver(from string, to string, data []byte) error {
|
||||
insecure := false
|
||||
|
||||
retry:
|
||||
conn, err := net.DialTimeout("tcp", mx+":"+smtpPort, smtpDialTimeout)
|
||||
conn, err := net.DialTimeout("tcp", mx+":"+*smtpPort, smtpDialTimeout)
|
||||
if err != nil {
|
||||
return tr.Errorf("Could not dial: %v", err)
|
||||
}
|
||||
@@ -117,6 +123,10 @@ func lookupMX(domain string) (string, error) {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
if *bypassMX {
|
||||
return domain, nil
|
||||
}
|
||||
|
||||
mxs, err := net.LookupMX(domain)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
Reference in New Issue
Block a user