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	"strconv"
26	"testing"
27	"time"
28
29	"github.com/foxcpp/maddy/internal/testutils"
30	"github.com/foxcpp/maddy/tests"
31)
32
33func TestIssue327(tt *testing.T) {
34	tt.Parallel()
35	t := tests.NewT(tt)
36	t.DNS(nil)
37	t.Port("smtp")
38	tgtPort := t.Port("target")
39	t.Config(`
40		hostname mx.maddy.test
41		tls off
42		smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {
43			deliver_to queue outbound_queue {
44				target remote { } # it will fail
45				autogenerated_msg_domain maddy.test
46				bounce {
47					check {
48						spf
49					}
50					deliver_to lmtp tcp://127.0.0.1:{env:TEST_PORT_target}
51				}
52			}
53		}`)
54	t.Run(1)
55	defer t.Close()
56
57	be, s := testutils.SMTPServer(tt, "127.0.0.1:"+strconv.Itoa(int(tgtPort)))
58	s.LMTP = true
59	be.LMTPDataErr = []error{nil, nil}
60	defer s.Close()
61
62	c := t.Conn("smtp")
63	defer c.Close()
64	c.SMTPNegotation("client.maddy.test", nil, nil)
65	c.Writeln("MAIL FROM:<from@maddy.test>")
66	c.ExpectPattern("250 *")
67	c.Writeln("RCPT TO:<to1@maddy.test>")
68	c.ExpectPattern("250 *")
69	c.Writeln("DATA")
70	c.ExpectPattern("354 *")
71	c.Writeln("From: <from@maddy.test>")
72	c.Writeln("To: <to@maddy.test>")
73	c.Writeln("Subject: Hello!")
74	c.Writeln("")
75	c.Writeln("Hello!")
76	c.Writeln(".")
77	c.ExpectPattern("250 2.0.0 OK: queued")
78	c.Writeln("QUIT")
79	c.ExpectPattern("221 *")
80
81	for i := 0; i < 5; i++ {
82		time.Sleep(1 * time.Second)
83		if len(be.Messages) != 0 {
84			break
85		}
86	}
87
88	if len(be.Messages) != 1 {
89		t.Fatal("No DSN sent?", len(be.Messages))
90	}
91}