diff --git a/tests/imapsql_test.go b/tests/imapsql_test.go new file mode 100644 index 0000000..d0658ad --- /dev/null +++ b/tests/imapsql_test.go @@ -0,0 +1,113 @@ +//+build integration,cgo,!nosqlite3 + +/* +Maddy Mail Server - Composable all-in-one email server. +Copyright © 2019-2020 Max Mazurov , Maddy Mail Server contributors + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package tests_test + +import ( + "testing" + "time" + + "github.com/foxcpp/maddy/tests" +) + +// Smoke test to ensure message delivery is handled correctly. + +func TestImapsqlDelivery(tt *testing.T) { + tt.Parallel() + t := tests.NewT(tt) + + t.DNS(nil) + t.Port("imap") + t.Port("smtp") + t.Config(` + storage.imapsql test_store { + driver sqlite3 + dsn imapsql.db + } + + imap tcp://127.0.0.1:{env:TEST_PORT_imap} { + tls off + + auth dummy + storage &test_store + } + + smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} { + hostname maddy.test + tls off + + deliver_to &test_store + } + `) + t.Run(2) + defer t.Close() + + imapConn := t.Conn("imap") + defer imapConn.Close() + imapConn.ExpectPattern(`\* OK *`) + imapConn.Writeln(". LOGIN testusr@maddy.test 1234") + imapConn.ExpectPattern(". OK *") + imapConn.Writeln(". SELECT INBOX") + imapConn.ExpectPattern(`\* *`) + imapConn.ExpectPattern(`\* *`) + imapConn.ExpectPattern(`\* *`) + imapConn.ExpectPattern(`\* *`) + imapConn.ExpectPattern(`\* *`) + imapConn.ExpectPattern(`\* *`) + imapConn.ExpectPattern(`. OK *`) + + smtpConn := t.Conn("smtp") + defer smtpConn.Close() + smtpConn.SMTPNegotation("localhost", nil, nil) + smtpConn.Writeln("MAIL FROM:") + smtpConn.ExpectPattern("2*") + smtpConn.Writeln("RCPT TO:") + smtpConn.ExpectPattern("2*") + smtpConn.Writeln("DATA") + smtpConn.ExpectPattern("354 *") + smtpConn.Writeln("From: ") + smtpConn.Writeln("To: ") + smtpConn.Writeln("Subject: Hi!") + smtpConn.Writeln("") + smtpConn.Writeln("Hi!") + smtpConn.Writeln(".") + smtpConn.ExpectPattern("2*") + + time.Sleep(500 * time.Millisecond) + + imapConn.Writeln(". NOOP") + imapConn.ExpectPattern(`\* 1 EXISTS`) + imapConn.ExpectPattern(". OK *") + + imapConn.Writeln(". FETCH 1 (BODY.PEEK[])") + imapConn.ExpectPattern(`\* 1 FETCH (BODY\[\] {304}*`) + imapConn.Expect(`Delivered-To: testusr@maddy.test`) + imapConn.Expect(`Return-Path: `) + imapConn.Expect(`Received: from localhost (localhost [127.0.0.1]) by maddy.test`) + imapConn.ExpectPattern(` (envelope-sender ) with ESMTP id *; *`) + imapConn.ExpectPattern(` *`) + imapConn.Expect("From: ") + imapConn.Expect("To: ") + imapConn.Expect("Subject: Hi!") + imapConn.Expect("") + imapConn.Expect("Hi!") + imapConn.Expect(")") + imapConn.ExpectPattern(`. OK *`) +}