| 186 | } |
| 187 | |
| 188 | func TestImapsqlAuthMap(tt *testing.T) { |
| 189 | tt.Parallel() |
| 190 | t := tests.NewT(tt) |
| 191 | |
| 192 | t.DNS(nil) |
| 193 | t.Port("imap") |
| 194 | t.Port("smtp") |
| 195 | t.Config(` |
| 196 | storage.imapsql test_store { |
| 197 | auth_map regexp "(.*)" "$1@maddy.test" |
| 198 | auth_normalize precis |
| 199 | |
| 200 | driver sqlite3 |
| 201 | dsn imapsql.db |
| 202 | } |
| 203 | |
| 204 | imap tcp://127.0.0.1:{env:TEST_PORT_imap} { |
| 205 | tls off |
| 206 | |
| 207 | auth dummy |
| 208 | storage &test_store |
| 209 | } |
| 210 | |
| 211 | smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} { |
| 212 | hostname maddy.test |
| 213 | tls off |
| 214 | |
| 215 | deliver_to &test_store |
| 216 | } |
| 217 | `) |
| 218 | t.Run(2) |
| 219 | defer t.Close() |
| 220 | |
| 221 | imapConn := t.Conn("imap") |
| 222 | defer imapConn.Close() |
| 223 | imapConn.ExpectPattern(`\* OK *`) |
| 224 | imapConn.Writeln(". LOGIN testusr 1234") |
| 225 | imapConn.ExpectPattern(". OK *") |
| 226 | imapConn.Writeln(". SELECT INBOX") |
| 227 | imapConn.ExpectPattern(`\* *`) |
| 228 | imapConn.ExpectPattern(`\* *`) |
| 229 | imapConn.ExpectPattern(`\* *`) |
| 230 | imapConn.ExpectPattern(`\* *`) |
| 231 | imapConn.ExpectPattern(`\* *`) |
| 232 | imapConn.ExpectPattern(`\* *`) |
| 233 | imapConn.ExpectPattern(`. OK *`) |
| 234 | |
| 235 | smtpConn := t.Conn("smtp") |
| 236 | defer smtpConn.Close() |
| 237 | smtpConn.SMTPNegotation("localhost", nil, nil) |
| 238 | smtpConn.Writeln("MAIL FROM:<sender@maddy.test>") |
| 239 | smtpConn.ExpectPattern("2*") |
| 240 | smtpConn.Writeln("RCPT TO:<testusr@maddy.test>") |
| 241 | smtpConn.ExpectPattern("2*") |
| 242 | smtpConn.Writeln("DATA") |
| 243 | smtpConn.ExpectPattern("354 *") |
| 244 | smtpConn.Writeln("From: <sender@maddy.test>") |
| 245 | smtpConn.Writeln("To: <testusr@maddy.test>") |