mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
smtpsrv: Disable SPF lookups in tests
When testing, we don't want the server to do SPF lookups, as those cause real DNS queries which can be problematic and add a dependency on the environment. This patch adds an internal boolean to disable the SPF lookups, which is only set from the tests.
This commit is contained in:
@@ -48,6 +48,9 @@ var (
|
||||
var (
|
||||
maxReceivedHeaders = flag.Int("testing__max_received_headers", 50,
|
||||
"max Received headers, for loop detection; ONLY FOR TESTING")
|
||||
|
||||
// Some go tests disable SPF, to avoid leaking DNS lookups.
|
||||
disableSPFForTesting = false
|
||||
)
|
||||
|
||||
// Mode for a socket (listening or connection).
|
||||
@@ -385,6 +388,10 @@ func (c *Conn) checkSPF(addr string) (spf.Result, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
if disableSPFForTesting {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
if tcp, ok := c.conn.RemoteAddr().(*net.TCPAddr); ok {
|
||||
res, err := spf.CheckHost(
|
||||
tcp.IP, envelope.DomainOf(addr))
|
||||
|
||||
@@ -453,6 +453,9 @@ func realMain(m *testing.M) int {
|
||||
s.AddDomain("localhost")
|
||||
s.AddUserDB("localhost", udb)
|
||||
|
||||
// Disable SPF lookups, to avoid leaking DNS queries.
|
||||
disableSPFForTesting = true
|
||||
|
||||
go s.ListenAndServe()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user