1//go:build integration2// +build integration34/*5Maddy Mail Server - Composable all-in-one email server.6Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors78This program is free software: you can redistribute it and/or modify9it under the terms of the GNU General Public License as published by10the Free Software Foundation, either version 3 of the License, or11(at your option) any later version.1213This program is distributed in the hope that it will be useful,14but WITHOUT ANY WARRANTY; without even the implied warranty of15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16GNU General Public License for more details.1718You should have received a copy of the GNU General Public License19along with this program. If not, see <https://www.gnu.org/licenses/>.20*/2122package tests_test2324import (25 "strconv"26 "strings"27 "testing"2829 "github.com/foxcpp/maddy/internal/testutils"30 "github.com/foxcpp/maddy/tests"31)3233func TestLMTPServer_Is_Actually_LMTP(tt *testing.T) {34 tt.Parallel()3536 t := tests.NewT(tt)37 t.DNS(nil)38 t.Port("lmtp")39 t.Config(`40 lmtp tcp://127.0.0.1:{env:TEST_PORT_lmtp} {41 hostname mx.maddy.test42 tls off43 deliver_to dummy44 }`)45 t.Run(1)46 defer t.Close()4748 c := t.Conn("lmtp")49 defer c.Close()5051 c.Writeln("LHLO client.maddy.test")52 c.ExpectPattern("220 *")53capsloop:54 for {55 line, err := c.Readln()56 if err != nil {57 t.Fatal("I/O error:", err)58 }59 switch {60 case strings.HasPrefix(line, "250-"):61 case strings.HasPrefix(line, "250 "):62 break capsloop63 default:64 t.Fatal("Unexpected deply:", line)65 }66 }6768 c.Writeln("MAIL FROM:<from@maddy.test>")69 c.ExpectPattern("250 *")70 c.Writeln("RCPT TO:<to1@maddy.test>")71 c.ExpectPattern("250 *")72 c.Writeln("RCPT TO:<to2@maddy.test>")73 c.ExpectPattern("250 *")74 c.Writeln("DATA")75 c.ExpectPattern("354 *")76 c.Writeln("From: <from@maddy.test>")77 c.Writeln("To: <to@maddy.test>")78 c.Writeln("Subject: Hello!")79 c.Writeln("")80 c.Writeln("Hello!")81 c.Writeln(".")82 c.ExpectPattern("250 2.0.0 <to1@maddy.test> OK: queued")83 c.ExpectPattern("250 2.0.0 <to2@maddy.test> OK: queued")84 c.Writeln("QUIT")85 c.ExpectPattern("221 *")86}8788func TestLMTPClient_Is_Actually_LMTP(tt *testing.T) {89 t := tests.NewT(tt)90 t.DNS(nil)91 t.Port("smtp")92 tgtPort := t.Port("target")93 t.Config(`94 hostname mx.maddy.test95 tls off96 smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {97 deliver_to lmtp tcp://127.0.0.1:{env:TEST_PORT_target}98 }`)99 t.Run(1)100 defer t.Close()101102 be, s := testutils.SMTPServer(tt, "127.0.0.1:"+strconv.Itoa(int(tgtPort)))103 s.LMTP = true104 be.LMTPDataErr = []error{nil, nil}105 defer s.Close()106107 c := t.Conn("smtp")108 defer c.Close()109 c.SMTPNegotation("client.maddy.test", nil, nil)110 c.Writeln("MAIL FROM:<from@maddy.test>")111 c.ExpectPattern("250 *")112 c.Writeln("RCPT TO:<to1@maddy.test>")113 c.ExpectPattern("250 *")114 c.Writeln("RCPT TO:<to2@maddy.test>")115 c.ExpectPattern("250 *")116 c.Writeln("DATA")117 c.ExpectPattern("354 *")118 c.Writeln("From: <from@maddy.test>")119 c.Writeln("To: <to@maddy.test>")120 c.Writeln("Subject: Hello!")121 c.Writeln("")122 c.Writeln("Hello!")123 c.Writeln(".")124 c.ExpectPattern("250 2.0.0 OK: queued")125 c.Writeln("QUIT")126 c.ExpectPattern("221 *")127128 if be.SessionCounter != 1 {129 t.Fatal("No actual connection made?", be.SessionCounter)130 }131}132133func TestLMTPClient_Issue308(tt *testing.T) {134 t := tests.NewT(tt)135 t.DNS(nil)136 t.Port("smtp")137 tgtPort := t.Port("target")138 t.Config(`139 hostname mx.maddy.test140 tls off141142 target.lmtp local_mailboxes {143 targets tcp://127.0.0.1:{env:TEST_PORT_target}144 }145146 smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {147 deliver_to &local_mailboxes148 }`)149 t.Run(1)150 defer t.Close()151152 be, s := testutils.SMTPServer(tt, "127.0.0.1:"+strconv.Itoa(int(tgtPort)))153 s.LMTP = true154 be.LMTPDataErr = []error{nil, nil}155 defer s.Close()156157 c := t.Conn("smtp")158 defer c.Close()159 c.SMTPNegotation("client.maddy.test", nil, nil)160 c.Writeln("MAIL FROM:<from@maddy.test>")161 c.ExpectPattern("250 *")162 c.Writeln("RCPT TO:<to1@maddy.test>")163 c.ExpectPattern("250 *")164 c.Writeln("RCPT TO:<to2@maddy.test>")165 c.ExpectPattern("250 *")166 c.Writeln("DATA")167 c.ExpectPattern("354 *")168 c.Writeln("From: <from@maddy.test>")169 c.Writeln("To: <to@maddy.test>")170 c.Writeln("Subject: Hello!")171 c.Writeln("")172 c.Writeln("Hello!")173 c.Writeln(".")174 c.ExpectPattern("250 2.0.0 OK: queued")175 c.Writeln("QUIT")176 c.ExpectPattern("221 *")177178 if be.SessionCounter != 1 {179 t.Fatal("No actual connection made?", be.SessionCounter)180 }181}