Skip to content

Commit dec4c64

Browse files
committed
test: Update expected strings to Go 1.26.4
In Go 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, this means some of the tests which validate error strings need to be adjusted. 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.
1 parent 2b8f206 commit dec4c64

4 files changed

Lines changed: 29 additions & 30 deletions

File tree

cmd/mda-lmtp/test_unix_failure.cmy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ nc <- .
2626

2727
nc -> 452 Nananana
2828

29-
mda <- Delivery failed remotely: 452 Nananana
29+
mda <- Delivery failed remotely: 452 "Nananana"
3030
mda wait 75
3131

internal/smtpsrv/server_test.go

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net"
99
"net/smtp"
10+
"net/textproto"
1011
"os"
1112
"strings"
1213
"testing"
@@ -141,6 +142,23 @@ func sendEmailWithAuth(tb testing.TB, c *smtp.Client, auth smtp.Auth) {
141142
localC.Wait()
142143
}
143144

145+
// Checks err is a textproto.Error with the given code and message.
146+
func expectTPErr(tb testing.TB, err error, code int, msg string) {
147+
tb.Helper()
148+
if err == nil {
149+
tb.Fatalf("Expected error %d %q, got nil", code, msg)
150+
}
151+
netErr, ok := err.(*textproto.Error)
152+
if !ok {
153+
tb.Fatalf("Expected textproto.Error(%d %q), got %T: %v",
154+
code, msg, err, err)
155+
}
156+
if netErr.Code != code || netErr.Msg != msg {
157+
tb.Fatalf("Expected textproto.Error(%d %q), got %d %q",
158+
code, msg, netErr.Code, netErr.Msg)
159+
}
160+
}
161+
144162
func TestSimple(t *testing.T) {
145163
c := mustDial(t, ModeSMTP, false)
146164
defer c.Close()
@@ -203,11 +221,7 @@ func TestBrokenAuth(t *testing.T) {
203221

204222
auth := smtp.PlainAuth("", "user@broken", "passwd", "127.0.0.1")
205223
err := c.Auth(auth)
206-
if err == nil {
207-
t.Errorf("Broken auth succeeded")
208-
} else if err.Error() != "454 4.7.0 Temporary authentication failure" {
209-
t.Errorf("Broken auth returned unexpected error %q", err.Error())
210-
}
224+
expectTPErr(t, err, 454, "4.7.0 Temporary authentication failure")
211225
}
212226

213227
func TestWrongMailParsing(t *testing.T) {
@@ -300,9 +314,7 @@ func TestTooManyRecipients(t *testing.T) {
300314
}
301315

302316
err := c.Rcpt("to102@somewhere")
303-
if err == nil || err.Error() != "452 4.5.3 Too many recipients" {
304-
t.Errorf("Expected too many recipients, got: %v", err)
305-
}
317+
expectTPErr(t, err, 452, "4.5.3 Too many recipients")
306318
}
307319

308320
func TestRcptBrokenExists(t *testing.T) {
@@ -314,13 +326,7 @@ func TestRcptBrokenExists(t *testing.T) {
314326
}
315327

316328
err := c.Rcpt("to@broken")
317-
if err == nil {
318-
t.Errorf("Accepted RCPT with broken Exists")
319-
}
320-
expect := "451 4.4.3 Temporary error checking address"
321-
if err.Error() != expect {
322-
t.Errorf("RCPT returned unexpected error %q", err.Error())
323-
}
329+
expectTPErr(t, err, 451, "4.4.3 Temporary error checking address")
324330
}
325331

326332
func TestRcptUserDoesNotExist(t *testing.T) {
@@ -332,13 +338,8 @@ func TestRcptUserDoesNotExist(t *testing.T) {
332338
}
333339

334340
err := c.Rcpt("doesnotexist@localhost")
335-
if err == nil {
336-
t.Errorf("Accepted RCPT for non-existent user")
337-
}
338-
expect := "550 5.1.1 Destination address is unknown (user does not exist)"
339-
if err.Error() != expect {
340-
t.Errorf("RCPT returned unexpected error %q", err.Error())
341-
}
341+
expectTPErr(t, err, 550,
342+
"5.1.1 Destination address is unknown (user does not exist)")
342343
}
343344

344345
var str1MiB string
@@ -392,9 +393,7 @@ func TestTooMuchData(t *testing.T) {
392393
localC.Wait()
393394

394395
err = sendLargeEmail(t, c, maxDataSizeMiB+1)
395-
if err == nil || err.Error() != "552 5.3.4 Message too big" {
396-
t.Fatalf("Expected message too big, got: %v", err)
397-
}
396+
expectTPErr(t, err, 552, "5.3.4 Message too big")
398397

399398
// Repeat the test once again, the limit should not prevent connection
400399
// from continuing.

test/t-10-hooks/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ check "SPF_PASS=0"
5454
if smtpc blockme@testserver < content >.logs/smtpc.log 2>&1; then
5555
fail "ERROR: hook did not block email as expected"
5656
fi
57-
if ! grep -q "451 ¡No pasarán!" .logs/smtpc.log; then
57+
if ! grep -q '451 "¡No pasarán!"' .logs/smtpc.log; then
5858
cat .logs/smtpc.log
5959
fail "ERROR: transient hook error not returned correctly"
6060
fi
@@ -63,7 +63,7 @@ fi
6363
if smtpc permanent@testserver < content >.logs/smtpc.log 2>&1; then
6464
fail "ERROR: hook did not block email as expected"
6565
fi
66-
if ! grep -q "554 Nos hacemos la permanente" .logs/smtpc.log; then
66+
if ! grep -q '554 "Nos hacemos la permanente"' .logs/smtpc.log; then
6767
cat .logs/smtpc.log
6868
fail "ERROR: permanent hook error not returned correctly"
6969
fi

test/t-16-spf/expected_dsn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Delivery of your message to the following recipient(s) failed permanently:
2626

2727
Technical details:
2828
- "userB@srv-b" (EMAIL) failed permanently with error:
29-
MAIL+RCPT 550 5.7.23 SPF check failed: matched all
29+
MAIL+RCPT 550 "5.7.23 SPF check failed: matched all"
3030

3131

3232
--???????????
@@ -40,7 +40,7 @@ Original-Recipient: utf-8; userB@srv-b
4040
Final-Recipient: utf-8; userB@srv-b
4141
Action: failed
4242
Status: 5.0.0
43-
Diagnostic-Code: smtp; MAIL+RCPT 550 5.7.23 SPF check failed: matched all
43+
Diagnostic-Code: smtp; MAIL+RCPT 550 "5.7.23 SPF check failed: matched all"
4444

4545

4646

0 commit comments

Comments
 (0)