maddy

git clone git://git.lin.moe/fmaddy/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	"strconv"
 26	"strings"
 27	"testing"
 28
 29	"github.com/foxcpp/maddy/internal/testutils"
 30	"github.com/foxcpp/maddy/tests"
 31)
 32
 33func TestLMTPServer_Is_Actually_LMTP(tt *testing.T) {
 34	tt.Parallel()
 35
 36	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.test
 42			tls off
 43			deliver_to dummy
 44		}`)
 45	t.Run(1)
 46	defer t.Close()
 47
 48	c := t.Conn("lmtp")
 49	defer c.Close()
 50
 51	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 capsloop
 63		default:
 64			t.Fatal("Unexpected deply:", line)
 65		}
 66	}
 67
 68	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}
 87
 88func 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.test
 95		tls off
 96		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()
101
102	be, s := testutils.SMTPServer(tt, "127.0.0.1:"+strconv.Itoa(int(tgtPort)))
103	s.LMTP = true
104	be.LMTPDataErr = []error{nil, nil}
105	defer s.Close()
106
107	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 *")
127
128	if be.SessionCounter != 1 {
129		t.Fatal("No actual connection made?", be.SessionCounter)
130	}
131}
132
133func 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.test
140		tls off
141
142		target.lmtp local_mailboxes {
143			targets tcp://127.0.0.1:{env:TEST_PORT_target}
144		}
145
146		smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {
147			deliver_to &local_mailboxes
148		}`)
149	t.Run(1)
150	defer t.Close()
151
152	be, s := testutils.SMTPServer(tt, "127.0.0.1:"+strconv.Itoa(int(tgtPort)))
153	s.LMTP = true
154	be.LMTPDataErr = []error{nil, nil}
155	defer s.Close()
156
157	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 *")
177
178	if be.SessionCounter != 1 {
179		t.Fatal("No actual connection made?", be.SessionCounter)
180	}
181}