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:
@@ -26,6 +26,6 @@ nc <- .
|
||||
|
||||
nc -> 452 Nananana
|
||||
|
||||
mda <- Delivery failed remotely: 452 Nananana
|
||||
mda <- Delivery failed remotely: 452 "Nananana"
|
||||
mda wait 75
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module blitiri.com.ar/go/chasquid
|
||||
|
||||
go 1.25.0
|
||||
go 1.25.11
|
||||
|
||||
require (
|
||||
blitiri.com.ar/go/log v1.1.0
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/smtp"
|
||||
"net/textproto"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -141,6 +142,23 @@ func sendEmailWithAuth(tb testing.TB, c *smtp.Client, auth smtp.Auth) {
|
||||
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) {
|
||||
c := mustDial(t, ModeSMTP, false)
|
||||
defer c.Close()
|
||||
@@ -203,11 +221,7 @@ func TestBrokenAuth(t *testing.T) {
|
||||
|
||||
auth := smtp.PlainAuth("", "user@broken", "passwd", "127.0.0.1")
|
||||
err := c.Auth(auth)
|
||||
if err == nil {
|
||||
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())
|
||||
}
|
||||
expectTPErr(t, err, 454, "4.7.0 Temporary authentication failure")
|
||||
}
|
||||
|
||||
func TestWrongMailParsing(t *testing.T) {
|
||||
@@ -300,9 +314,7 @@ func TestTooManyRecipients(t *testing.T) {
|
||||
}
|
||||
|
||||
err := c.Rcpt("to102@somewhere")
|
||||
if err == nil || err.Error() != "452 4.5.3 Too many recipients" {
|
||||
t.Errorf("Expected too many recipients, got: %v", err)
|
||||
}
|
||||
expectTPErr(t, err, 452, "4.5.3 Too many recipients")
|
||||
}
|
||||
|
||||
func TestRcptBrokenExists(t *testing.T) {
|
||||
@@ -314,13 +326,7 @@ func TestRcptBrokenExists(t *testing.T) {
|
||||
}
|
||||
|
||||
err := c.Rcpt("to@broken")
|
||||
if err == nil {
|
||||
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())
|
||||
}
|
||||
expectTPErr(t, err, 451, "4.4.3 Temporary error checking address")
|
||||
}
|
||||
|
||||
func TestRcptUserDoesNotExist(t *testing.T) {
|
||||
@@ -332,13 +338,8 @@ func TestRcptUserDoesNotExist(t *testing.T) {
|
||||
}
|
||||
|
||||
err := c.Rcpt("doesnotexist@localhost")
|
||||
if err == nil {
|
||||
t.Errorf("Accepted RCPT for non-existent user")
|
||||
}
|
||||
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())
|
||||
}
|
||||
expectTPErr(t, err, 550,
|
||||
"5.1.1 Destination address is unknown (user does not exist)")
|
||||
}
|
||||
|
||||
var str1MiB string
|
||||
@@ -392,9 +393,7 @@ func TestTooMuchData(t *testing.T) {
|
||||
localC.Wait()
|
||||
|
||||
err = sendLargeEmail(t, c, maxDataSizeMiB+1)
|
||||
if err == nil || err.Error() != "552 5.3.4 Message too big" {
|
||||
t.Fatalf("Expected message too big, got: %v", err)
|
||||
}
|
||||
expectTPErr(t, err, 552, "5.3.4 Message too big")
|
||||
|
||||
// Repeat the test once again, the limit should not prevent connection
|
||||
// from continuing.
|
||||
|
||||
@@ -54,7 +54,7 @@ check "SPF_PASS=0"
|
||||
if smtpc blockme@testserver < content >.logs/smtpc.log 2>&1; then
|
||||
fail "ERROR: hook did not block email as expected"
|
||||
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
|
||||
fail "ERROR: transient hook error not returned correctly"
|
||||
fi
|
||||
@@ -63,7 +63,7 @@ fi
|
||||
if smtpc permanent@testserver < content >.logs/smtpc.log 2>&1; then
|
||||
fail "ERROR: hook did not block email as expected"
|
||||
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
|
||||
fail "ERROR: permanent hook error not returned correctly"
|
||||
fi
|
||||
|
||||
@@ -26,7 +26,7 @@ Delivery of your message to the following recipient(s) failed permanently:
|
||||
|
||||
Technical details:
|
||||
- "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
|
||||
Action: failed
|
||||
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"
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user