1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-06-09 19:33:35 +00:00

test: Update expected strings to Go 1.25.11/1.26.4

In Go 1.25.11/1.26.4, net/textproto error formatting was changed, and
now the message is quoted. This is to protect from general string
injections.

See https://go-review.googlesource.com/c/go/+/778182 and
ec1c380418ec6a0da28d4519872e2b81ba9152ba.

After this change, the error strings from net/textproto (and net/smtp
which uses it) now include quotes.

For chasquid, the only user-observable change in the server is that the
errors included in the DSN messages are now quoted, which should not be
a problem.

However, some of the tests which validate error strings need to be
adjusted.

The patch also updates go.mod to set the Go version to match this new
minimum.
This commit is contained in:
Alberto Bertogli
2026-06-07 00:07:42 +01:00
parent 2b8f206842
commit ab2a6e7eb3
5 changed files with 30 additions and 31 deletions
+1 -1
View File
@@ -26,6 +26,6 @@ nc <- .
nc -> 452 Nananana nc -> 452 Nananana
mda <- Delivery failed remotely: 452 Nananana mda <- Delivery failed remotely: 452 "Nananana"
mda wait 75 mda wait 75
+1 -1
View File
@@ -1,6 +1,6 @@
module blitiri.com.ar/go/chasquid module blitiri.com.ar/go/chasquid
go 1.25.0 go 1.25.11
require ( require (
blitiri.com.ar/go/log v1.1.0 blitiri.com.ar/go/log v1.1.0
+24 -25
View File
@@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/smtp" "net/smtp"
"net/textproto"
"os" "os"
"strings" "strings"
"testing" "testing"
@@ -141,6 +142,23 @@ func sendEmailWithAuth(tb testing.TB, c *smtp.Client, auth smtp.Auth) {
localC.Wait() localC.Wait()
} }
// Checks err is a textproto.Error with the given code and message.
func expectTPErr(tb testing.TB, err error, code int, msg string) {
tb.Helper()
if err == nil {
tb.Fatalf("Expected error %d %q, got nil", code, msg)
}
netErr, ok := err.(*textproto.Error)
if !ok {
tb.Fatalf("Expected textproto.Error(%d %q), got %T: %v",
code, msg, err, err)
}
if netErr.Code != code || netErr.Msg != msg {
tb.Fatalf("Expected textproto.Error(%d %q), got %d %q",
code, msg, netErr.Code, netErr.Msg)
}
}
func TestSimple(t *testing.T) { func TestSimple(t *testing.T) {
c := mustDial(t, ModeSMTP, false) c := mustDial(t, ModeSMTP, false)
defer c.Close() defer c.Close()
@@ -203,11 +221,7 @@ func TestBrokenAuth(t *testing.T) {
auth := smtp.PlainAuth("", "user@broken", "passwd", "127.0.0.1") auth := smtp.PlainAuth("", "user@broken", "passwd", "127.0.0.1")
err := c.Auth(auth) err := c.Auth(auth)
if err == nil { expectTPErr(t, err, 454, "4.7.0 Temporary authentication failure")
t.Errorf("Broken auth succeeded")
} else if err.Error() != "454 4.7.0 Temporary authentication failure" {
t.Errorf("Broken auth returned unexpected error %q", err.Error())
}
} }
func TestWrongMailParsing(t *testing.T) { func TestWrongMailParsing(t *testing.T) {
@@ -300,9 +314,7 @@ func TestTooManyRecipients(t *testing.T) {
} }
err := c.Rcpt("to102@somewhere") err := c.Rcpt("to102@somewhere")
if err == nil || err.Error() != "452 4.5.3 Too many recipients" { expectTPErr(t, err, 452, "4.5.3 Too many recipients")
t.Errorf("Expected too many recipients, got: %v", err)
}
} }
func TestRcptBrokenExists(t *testing.T) { func TestRcptBrokenExists(t *testing.T) {
@@ -314,13 +326,7 @@ func TestRcptBrokenExists(t *testing.T) {
} }
err := c.Rcpt("to@broken") err := c.Rcpt("to@broken")
if err == nil { expectTPErr(t, err, 451, "4.4.3 Temporary error checking address")
t.Errorf("Accepted RCPT with broken Exists")
}
expect := "451 4.4.3 Temporary error checking address"
if err.Error() != expect {
t.Errorf("RCPT returned unexpected error %q", err.Error())
}
} }
func TestRcptUserDoesNotExist(t *testing.T) { func TestRcptUserDoesNotExist(t *testing.T) {
@@ -332,13 +338,8 @@ func TestRcptUserDoesNotExist(t *testing.T) {
} }
err := c.Rcpt("doesnotexist@localhost") err := c.Rcpt("doesnotexist@localhost")
if err == nil { expectTPErr(t, err, 550,
t.Errorf("Accepted RCPT for non-existent user") "5.1.1 Destination address is unknown (user does not exist)")
}
expect := "550 5.1.1 Destination address is unknown (user does not exist)"
if err.Error() != expect {
t.Errorf("RCPT returned unexpected error %q", err.Error())
}
} }
var str1MiB string var str1MiB string
@@ -392,9 +393,7 @@ func TestTooMuchData(t *testing.T) {
localC.Wait() localC.Wait()
err = sendLargeEmail(t, c, maxDataSizeMiB+1) err = sendLargeEmail(t, c, maxDataSizeMiB+1)
if err == nil || err.Error() != "552 5.3.4 Message too big" { expectTPErr(t, err, 552, "5.3.4 Message too big")
t.Fatalf("Expected message too big, got: %v", err)
}
// Repeat the test once again, the limit should not prevent connection // Repeat the test once again, the limit should not prevent connection
// from continuing. // from continuing.
+2 -2
View File
@@ -54,7 +54,7 @@ check "SPF_PASS=0"
if smtpc blockme@testserver < content >.logs/smtpc.log 2>&1; then if smtpc blockme@testserver < content >.logs/smtpc.log 2>&1; then
fail "ERROR: hook did not block email as expected" fail "ERROR: hook did not block email as expected"
fi fi
if ! grep -q "451 ¡No pasarán!" .logs/smtpc.log; then if ! grep -q '451 "¡No pasarán!"' .logs/smtpc.log; then
cat .logs/smtpc.log cat .logs/smtpc.log
fail "ERROR: transient hook error not returned correctly" fail "ERROR: transient hook error not returned correctly"
fi fi
@@ -63,7 +63,7 @@ fi
if smtpc permanent@testserver < content >.logs/smtpc.log 2>&1; then if smtpc permanent@testserver < content >.logs/smtpc.log 2>&1; then
fail "ERROR: hook did not block email as expected" fail "ERROR: hook did not block email as expected"
fi fi
if ! grep -q "554 Nos hacemos la permanente" .logs/smtpc.log; then if ! grep -q '554 "Nos hacemos la permanente"' .logs/smtpc.log; then
cat .logs/smtpc.log cat .logs/smtpc.log
fail "ERROR: permanent hook error not returned correctly" fail "ERROR: permanent hook error not returned correctly"
fi fi
+2 -2
View File
@@ -26,7 +26,7 @@ Delivery of your message to the following recipient(s) failed permanently:
Technical details: Technical details:
- "userB@srv-b" (EMAIL) failed permanently with error: - "userB@srv-b" (EMAIL) failed permanently with error:
MAIL+RCPT 550 5.7.23 SPF check failed: matched all MAIL+RCPT 550 "5.7.23 SPF check failed: matched all"
--??????????? --???????????
@@ -40,7 +40,7 @@ Original-Recipient: utf-8; userB@srv-b
Final-Recipient: utf-8; userB@srv-b Final-Recipient: utf-8; userB@srv-b
Action: failed Action: failed
Status: 5.0.0 Status: 5.0.0
Diagnostic-Code: smtp; MAIL+RCPT 550 5.7.23 SPF check failed: matched all Diagnostic-Code: smtp; MAIL+RCPT 550 "5.7.23 SPF check failed: matched all"