From a12875162f7afae8c427c362b7de1b3a366d60be Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sun, 1 Dec 2019 19:37:47 +0000 Subject: [PATCH] smtpsrv: Test too many recipients This patch adds a test to make sure we don't allow too many recipients. --- internal/smtpsrv/server_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/internal/smtpsrv/server_test.go b/internal/smtpsrv/server_test.go index 3e46726..835231d 100644 --- a/internal/smtpsrv/server_test.go +++ b/internal/smtpsrv/server_test.go @@ -270,6 +270,31 @@ func TestRelayForbidden(t *testing.T) { } } +func TestTooManyRecipients(t *testing.T) { + c := mustDial(t, ModeSubmission, true) + defer c.Close() + + auth := smtp.PlainAuth("", "testuser@localhost", "testpasswd", "127.0.0.1") + if err := c.Auth(auth); err != nil { + t.Fatalf("Auth: %v", err) + } + + if err := c.Mail("testuser@localhost"); err != nil { + t.Fatalf("Mail: %v", err) + } + + for i := 0; i < 101; i++ { + if err := c.Rcpt(fmt.Sprintf("to%d@somewhere", i)); err != nil { + t.Fatalf("Rcpt: %v", err) + } + } + + 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) + } +} + var str1MiB string func sendLargeEmail(tb testing.TB, c *smtp.Client, sizeMiB int) error {