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 "testing"2627 "github.com/foxcpp/maddy/tests"28)2930func 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()3940 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 }6061 test("inline", `62 hostname mx.maddy.test63 tls off6465 smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {66 modify {67 replace_rcpt static {68 entry a@maddy.test b@maddy.test69 }70 }71 destination a@maddy.test {72 reject73 }74 destination b@maddy.test {75 deliver_to dummy76 }77 default_destination {78 reject79 }80 }`)81 test("inline qualified", `82 hostname mx.maddy.test83 tls off8485 smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {86 modify {87 modify.replace_rcpt static {88 entry a@maddy.test b@maddy.test89 }90 }91 destination a@maddy.test {92 reject93 }94 destination b@maddy.test {95 deliver_to dummy96 }97 default_destination {98 reject99 }100 }`)101102 // FIXME: Not implemented103 // test("external", `104 // hostname mx.maddy.test105 // tls off106107 // modify.replace_rcpt local_aliases {108 // table static {109 // entry a@maddy.test b@maddy.test110 // }111 // }112113 // smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {114 // modify {115 // &local_aliases116 // }117 // source a@maddy.test {118 // destination a@maddy.test {119 // reject120 // }121 // destination b@maddy.test {122 // deliver_to dummy123 // }124 // default_destination {125 // reject126 // }127 // }128 // default_source {129 // reject130 // }131 // }`)132}133134func 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()143144 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 }164165 test("inline", `166 hostname mx.maddy.test167 tls off168169 smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {170 modify {171 replace_sender static {172 entry a@maddy.test b@maddy.test173 }174 }175 source a@maddy.test {176 reject177 }178 source b@maddy.test {179 destination a@maddy.test {180 deliver_to dummy181 }182 default_destination {183 reject184 }185 }186 default_source {187 reject188 }189 }`)190 test("inline qualified", `191 hostname mx.maddy.test192 tls off193194 smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {195 modify {196 modify.replace_sender static {197 entry a@maddy.test b@maddy.test198 }199 }200 source a@maddy.test {201 reject202 }203 source b@maddy.test {204 destination a@maddy.test {205 deliver_to dummy206 }207 default_destination {208 reject209 }210 }211 default_source {212 reject213 }214 }`)215 // FIXME: Not implemented216 // test("external", `217 // hostname mx.maddy.test218 // tls off219220 // modify.replace_sender local_aliases {221 // table static {222 // entry a@maddy.test b@maddy.test223 // }224 // }225226 // smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {227 // modify {228 // &local_aliases229 // }230 // source a@maddy.test {231 // reject232 // }233 // source b@maddy.test {234 // destination a@maddy.test {235 // deliver_to dummy236 // }237 // default_destination {238 // reject239 // }240 // }241 // default_source {242 // reject243 // }244 // }`)245}