From 54cce0c2bf1003f7e102660afa3488a5efe952b5 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Tue, 25 Oct 2016 20:42:08 +0100 Subject: [PATCH] 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. --- internal/smtpsrv/conn.go | 11 +++++++++-- test/t-09-loop/run.sh | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/smtpsrv/conn.go b/internal/smtpsrv/conn.go index 877475d..29920f4 100644 --- a/internal/smtpsrv/conn.go +++ b/internal/smtpsrv/conn.go @@ -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 diff --git a/test/t-09-loop/run.sh b/test/t-09-loop/run.sh index 3c51145..efddcb7 100755 --- a/test/t-09-loop/run.sh +++ b/test/t-09-loop/run.sh @@ -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 &