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	"testing"
 26
 27	"github.com/foxcpp/maddy/tests"
 28)
 29
 30func TestReplaceAddr_Rcpt(tt *testing.T) {
 31	test := func(name, cfg string) {
 32		tt.Run(name, func(tt *testing.T) {
 33			t := tests.NewT(tt)
 34			t.DNS(nil)
 35			t.Port("smtp")
 36			t.Config(cfg)
 37			t.Run(1)
 38			defer t.Close()
 39
 40			c := t.Conn("smtp")
 41			defer c.Close()
 42			c.SMTPNegotation("client.maddy.test", nil, nil)
 43			c.Writeln("MAIL FROM:<a@maddy.test>")
 44			c.ExpectPattern("250 *")
 45			c.Writeln("RCPT TO:<a@maddy.test>")
 46			c.ExpectPattern("250 *")
 47			c.Writeln("DATA")
 48			c.ExpectPattern("354 *")
 49			c.Writeln("From: <from@maddy.test>")
 50			c.Writeln("To: <to@maddy.test>")
 51			c.Writeln("Subject: Hello!")
 52			c.Writeln("")
 53			c.Writeln("Hello!")
 54			c.Writeln(".")
 55			c.ExpectPattern("250 2.0.0 OK: queued")
 56			c.Writeln("QUIT")
 57			c.ExpectPattern("221 *")
 58		})
 59	}
 60
 61	test("inline", `
 62			hostname mx.maddy.test
 63			tls off
 64
 65			smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {
 66				modify {
 67					replace_rcpt static {
 68						entry a@maddy.test b@maddy.test
 69					}
 70				}
 71				destination a@maddy.test {
 72					reject
 73				}
 74				destination b@maddy.test {
 75					deliver_to dummy
 76				}
 77				default_destination {
 78					reject
 79				}
 80			}`)
 81	test("inline qualified", `
 82			hostname mx.maddy.test
 83			tls off
 84
 85			smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {
 86				modify {
 87					modify.replace_rcpt static {
 88						entry a@maddy.test b@maddy.test
 89					}
 90				}
 91				destination a@maddy.test {
 92					reject
 93				}
 94				destination b@maddy.test {
 95					deliver_to dummy
 96				}
 97				default_destination {
 98					reject
 99				}
100			}`)
101
102	// FIXME: Not implemented
103	// test("external", `
104	//		hostname mx.maddy.test
105	//		tls off
106
107	//		modify.replace_rcpt local_aliases {
108	//			table static {
109	//				entry a@maddy.test b@maddy.test
110	//			}
111	//		}
112
113	//		smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {
114	//			modify {
115	//				&local_aliases
116	//			}
117	//			source a@maddy.test {
118	//				destination a@maddy.test {
119	//					reject
120	//				}
121	//				destination b@maddy.test {
122	//					deliver_to dummy
123	//				}
124	//				default_destination {
125	//					reject
126	//				}
127	//			}
128	//			default_source {
129	//				reject
130	//			}
131	//		}`)
132}
133
134func TestReplaceAddr_Sender(tt *testing.T) {
135	test := func(name, cfg string) {
136		tt.Run(name, func(tt *testing.T) {
137			t := tests.NewT(tt)
138			t.DNS(nil)
139			t.Port("smtp")
140			t.Config(cfg)
141			t.Run(1)
142			defer t.Close()
143
144			c := t.Conn("smtp")
145			defer c.Close()
146			c.SMTPNegotation("client.maddy.test", nil, nil)
147			c.Writeln("MAIL FROM:<a@maddy.test>")
148			c.ExpectPattern("250 *")
149			c.Writeln("RCPT TO:<a@maddy.test>")
150			c.ExpectPattern("250 *")
151			c.Writeln("DATA")
152			c.ExpectPattern("354 *")
153			c.Writeln("From: <from@maddy.test>")
154			c.Writeln("To: <to@maddy.test>")
155			c.Writeln("Subject: Hello!")
156			c.Writeln("")
157			c.Writeln("Hello!")
158			c.Writeln(".")
159			c.ExpectPattern("250 2.0.0 OK: queued")
160			c.Writeln("QUIT")
161			c.ExpectPattern("221 *")
162		})
163	}
164
165	test("inline", `
166			hostname mx.maddy.test
167			tls off
168
169			smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {
170				modify {
171					replace_sender static {
172						entry a@maddy.test b@maddy.test
173					}
174				}
175				source a@maddy.test {
176					reject
177				}
178				source b@maddy.test {
179					destination a@maddy.test {
180						deliver_to dummy
181					}
182					default_destination {
183						reject
184					}
185				}
186				default_source {
187					reject
188				}
189			}`)
190	test("inline qualified", `
191			hostname mx.maddy.test
192			tls off
193
194			smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {
195				modify {
196					modify.replace_sender static {
197						entry a@maddy.test b@maddy.test
198					}
199				}
200				source a@maddy.test {
201					reject
202				}
203				source b@maddy.test {
204					destination a@maddy.test {
205						deliver_to dummy
206					}
207					default_destination {
208						reject
209					}
210				}
211				default_source {
212					reject
213				}
214			}`)
215	// FIXME: Not implemented
216	// test("external", `
217	//		hostname mx.maddy.test
218	//		tls off
219
220	//		modify.replace_sender local_aliases {
221	//			table static {
222	//				entry a@maddy.test b@maddy.test
223	//			}
224	//		}
225
226	//		smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {
227	//			modify {
228	//				&local_aliases
229	//			}
230	//			source a@maddy.test {
231	//				reject
232	//			}
233	//			source b@maddy.test {
234	//				destination a@maddy.test {
235	//					deliver_to dummy
236	//				}
237	//				default_destination {
238	//					reject
239	//				}
240	//			}
241	//			default_source {
242	//				reject
243	//			}
244	//		}`)
245}