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 "net"26 "strconv"27 "testing"2829 "github.com/foxcpp/go-mockdns"30 "github.com/foxcpp/maddy/internal/testutils"31 "github.com/foxcpp/maddy/tests"32)3334func TestMTA_Outbound(tt *testing.T) {35 t := tests.NewT(tt)36 t.DNS(map[string]mockdns.Zone{37 "example.invalid.": {38 MX: []net.MX{{Host: "mx.example.invalid.", Pref: 10}},39 },40 "mx.example.invalid.": {41 A: []string{"127.0.0.1"},42 },43 })44 t.Port("smtp")45 tgtPort := t.Port("remote_smtp")46 t.Config(`47 hostname mx.maddy.test48 tls off49 smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {50 deliver_to remote51 }`)52 t.Run(1)53 defer t.Close()5455 be, s := testutils.SMTPServer(tt, "127.0.0.1:"+strconv.Itoa(int(tgtPort)))56 defer s.Close()5758 c := t.Conn("smtp")59 defer c.Close()60 c.SMTPNegotation("client.maddy.test", nil, nil)61 c.Writeln("MAIL FROM:<from@maddy.test>")62 c.ExpectPattern("250 *")63 c.Writeln("RCPT TO:<to1@example.invalid>")64 c.ExpectPattern("250 *")65 c.Writeln("RCPT TO:<to2@example.invalid>")66 c.ExpectPattern("250 *")67 c.Writeln("DATA")68 c.ExpectPattern("354 *")69 c.Writeln("From: <from@maddy.test>")70 c.Writeln("To: <to@maddy.test>")71 c.Writeln("Subject: Hello!")72 c.Writeln("")73 c.Writeln("Hello!")74 c.Writeln(".")75 c.ExpectPattern("250 2.0.0 OK: queued")76 c.Writeln("QUIT")77 c.ExpectPattern("221 *")7879 if be.SessionCounter != 1 {80 t.Fatal("No actual connection made?", be.SessionCounter)81 }82}8384func TestIssue321(tt *testing.T) {85 t := tests.NewT(tt)86 t.DNS(map[string]mockdns.Zone{87 "example.invalid.": {88 AD: true,89 A: []string{"127.0.0.1"},90 },91 })92 t.Port("smtp")93 tgtPort := t.Port("remote_smtp")94 t.Config(`95 hostname mx.maddy.test96 tls off97 smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {98 deliver_to remote {99 mx_auth {100 dnssec101 dane102 }103 }104 }`)105 t.Run(1)106 defer t.Close()107108 be, s := testutils.SMTPServer(tt, "127.0.0.1:"+strconv.Itoa(int(tgtPort)))109 defer s.Close()110111 c := t.Conn("smtp")112 defer c.Close()113 c.SMTPNegotation("client.maddy.test", nil, nil)114 c.Writeln("MAIL FROM:<from@maddy.test>")115 c.ExpectPattern("250 *")116 c.Writeln("RCPT TO:<to1@example.invalid>")117 c.ExpectPattern("250 *")118 c.Writeln("RCPT TO:<to2@example.invalid>")119 c.ExpectPattern("250 *")120 c.Writeln("DATA")121 c.ExpectPattern("354 *")122 c.Writeln("From: <from@maddy.test>")123 c.Writeln("To: <to@maddy.test>")124 c.Writeln("Subject: Hello!")125 c.Writeln("")126 c.Writeln("Hello!")127 c.Writeln(".")128 c.ExpectPattern("250 2.0.0 OK: queued")129 c.Writeln("QUIT")130 c.ExpectPattern("221 *")131132 if be.SessionCounter != 1 {133 t.Fatal("No actual connection made?", be.SessionCounter)134 }135}