maddy

Fork https://github.com/foxcpp/maddy

git clone git://git.lin.moe/go/maddy.git

  1//go:build integration
  2// +build integration
  3
  4/*
  5Maddy Mail Server - Composable all-in-one email server.
  6Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors
  7
  8This program is free software: you can redistribute it and/or modify
  9it under the terms of the GNU General Public License as published by
 10the Free Software Foundation, either version 3 of the License, or
 11(at your option) any later version.
 12
 13This program is distributed in the hope that it will be useful,
 14but WITHOUT ANY WARRANTY; without even the implied warranty of
 15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16GNU General Public License for more details.
 17
 18You should have received a copy of the GNU General Public License
 19along with this program.  If not, see <https://www.gnu.org/licenses/>.
 20*/
 21
 22package tests_test
 23
 24import (
 25	"net"
 26	"strconv"
 27	"testing"
 28
 29	"github.com/foxcpp/go-mockdns"
 30	"github.com/foxcpp/maddy/internal/testutils"
 31	"github.com/foxcpp/maddy/tests"
 32)
 33
 34func 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.test
 48		tls off
 49		smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {
 50			deliver_to remote
 51		}`)
 52	t.Run(1)
 53	defer t.Close()
 54
 55	be, s := testutils.SMTPServer(tt, "127.0.0.1:"+strconv.Itoa(int(tgtPort)))
 56	defer s.Close()
 57
 58	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 *")
 78
 79	if be.SessionCounter != 1 {
 80		t.Fatal("No actual connection made?", be.SessionCounter)
 81	}
 82}
 83
 84func 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.test
 96		tls off
 97		smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {
 98			deliver_to remote {
 99				mx_auth {
100					dnssec
101					dane
102				}
103			}
104		}`)
105	t.Run(1)
106	defer t.Close()
107
108	be, s := testutils.SMTPServer(tt, "127.0.0.1:"+strconv.Itoa(int(tgtPort)))
109	defer s.Close()
110
111	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 *")
131
132	if be.SessionCounter != 1 {
133		t.Fatal("No actual connection made?", be.SessionCounter)
134	}
135}