mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-20 15:07:03 +00:00
test: Reduce the loop detection threshold from 50 down to 5
The loop test can be quite slow, specially on computers without cryptography-friendly instructions. This patch introduces a new flag for testing, so that we can bring the threshold down to 5. The test is just as useful but now runs in a few seconds, as opposed to a few minutes.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"expvar"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -44,6 +45,11 @@ var (
|
||||
hookResults = expvar.NewMap("chasquid/smtpIn/hookResults")
|
||||
)
|
||||
|
||||
var (
|
||||
maxReceivedHeaders = flag.Int("testing__max_received_headers", 50,
|
||||
"max Received headers, for loop detection; ONLY FOR TESTING")
|
||||
)
|
||||
|
||||
// Mode for a socket (listening or connection).
|
||||
// We keep them distinct, as policies can differ between them.
|
||||
type SocketMode string
|
||||
@@ -619,9 +625,10 @@ func checkData(data []byte) error {
|
||||
// This serves as a basic form of loop prevention. It's not infallible but
|
||||
// should catch most instances of accidental looping.
|
||||
// https://tools.ietf.org/html/rfc5321#section-6.3
|
||||
if len(msg.Header["Received"]) > 50 {
|
||||
if len(msg.Header["Received"]) > *maxReceivedHeaders {
|
||||
loopsDetected.Add(1)
|
||||
return fmt.Errorf("email passed through more than 50 MTAs, looping?")
|
||||
return fmt.Errorf("email passed through more than %d MTAs, looping?",
|
||||
*maxReceivedHeaders)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -22,6 +22,7 @@ CONFDIR=B generate_certs_for srv-B
|
||||
mkdir -p .logs-A .logs-B
|
||||
|
||||
chasquid -v=2 --logfile=.logs-A/chasquid.log --config_dir=A \
|
||||
--testing__max_received_headers=5 \
|
||||
--testing__outgoing_smtp_port=2025 &
|
||||
chasquid -v=2 --logfile=.logs-B/chasquid.log --config_dir=B \
|
||||
--testing__outgoing_smtp_port=1025 &
|
||||
|
||||
Reference in New Issue
Block a user