From 2a9b02ff6d2279f7cd301ae1f397d275afa66922 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 28 Nov 2017 14:13:03 +0100 Subject: Fixed imap tests Adjust to cyrus imap settings and use explicit encryption setting. --- examples/imapresource/tests/imapmailsynctest.cpp | 16 ++++++------- examples/imapresource/tests/imapmailtest.cpp | 4 ++-- .../imapresource/tests/imapserverproxytest.cpp | 28 ++++++++++++---------- examples/imapresource/tests/populatemailbox.sh | 2 +- examples/imapresource/tests/resetmailbox.sh | 5 ++-- 5 files changed, 29 insertions(+), 26 deletions(-) (limited to 'examples/imapresource/tests') diff --git a/examples/imapresource/tests/imapmailsynctest.cpp b/examples/imapresource/tests/imapmailsynctest.cpp index 23bb4e5..cdb85dd 100644 --- a/examples/imapresource/tests/imapmailsynctest.cpp +++ b/examples/imapresource/tests/imapmailsynctest.cpp @@ -43,7 +43,7 @@ protected: bool isBackendAvailable() Q_DECL_OVERRIDE { QTcpSocket socket; - socket.connectToHost("localhost", 993); + socket.connectToHost("localhost", 143); return socket.waitForConnected(200); } @@ -56,7 +56,7 @@ protected: { auto resource = ApplicationDomain::ImapResource::create("account1"); resource.setProperty("server", "localhost"); - resource.setProperty("port", 993); + resource.setProperty("port", 143); resource.setProperty("username", "doe"); Sink::SecretStore::instance().insert(resource.identifier(), "doe"); return resource; @@ -67,7 +67,7 @@ protected: auto resource = ApplicationDomain::ImapResource::create("account1"); //Using a bogus ip instead of a bogus hostname avoids getting stuck in the hostname lookup resource.setProperty("server", "111.111.1.1"); - resource.setProperty("port", 993); + resource.setProperty("port", 143); resource.setProperty("username", "doe"); Sink::SecretStore::instance().insert(resource.identifier(), "doe"); return resource; @@ -80,21 +80,21 @@ protected: void createFolder(const QStringList &folderPath) Q_DECL_OVERRIDE { - Imap::ImapServerProxy imap("localhost", 993); + Imap::ImapServerProxy imap("localhost", 143, Imap::NoEncryption); VERIFYEXEC(imap.login("doe", "doe")); VERIFYEXEC(imap.create("INBOX." + folderPath.join('.'))); } void removeFolder(const QStringList &folderPath) Q_DECL_OVERRIDE { - Imap::ImapServerProxy imap("localhost", 993); + Imap::ImapServerProxy imap("localhost", 143, Imap::NoEncryption); VERIFYEXEC(imap.login("doe", "doe")); VERIFYEXEC(imap.remove("INBOX." + folderPath.join('.'))); } QByteArray createMessage(const QStringList &folderPath, const QByteArray &message) Q_DECL_OVERRIDE { - Imap::ImapServerProxy imap("localhost", 993); + Imap::ImapServerProxy imap("localhost", 143, Imap::NoEncryption); VERIFYEXEC_RET(imap.login("doe", "doe"), {}); VERIFYEXEC_RET(imap.append("INBOX." + folderPath.join('.'), message), {}); return "2:*"; @@ -102,14 +102,14 @@ protected: void removeMessage(const QStringList &folderPath, const QByteArray &messages) Q_DECL_OVERRIDE { - Imap::ImapServerProxy imap("localhost", 993); + Imap::ImapServerProxy imap("localhost", 143, Imap::NoEncryption); VERIFYEXEC(imap.login("doe", "doe")); VERIFYEXEC(imap.remove("INBOX." + folderPath.join('.'), messages)); } void markAsImportant(const QStringList &folderPath, const QByteArray &messageIdentifier) Q_DECL_OVERRIDE { - Imap::ImapServerProxy imap("localhost", 993); + Imap::ImapServerProxy imap("localhost", 143, Imap::NoEncryption); VERIFYEXEC(imap.login("doe", "doe")); VERIFYEXEC(imap.select("INBOX." + folderPath.join('.'))); VERIFYEXEC(imap.addFlags(KIMAP2::ImapSet::fromImapSequenceSet(messageIdentifier), QByteArrayList() << Imap::Flags::Flagged)); diff --git a/examples/imapresource/tests/imapmailtest.cpp b/examples/imapresource/tests/imapmailtest.cpp index 60ec1bf..6616811 100644 --- a/examples/imapresource/tests/imapmailtest.cpp +++ b/examples/imapresource/tests/imapmailtest.cpp @@ -23,7 +23,7 @@ protected: bool isBackendAvailable() Q_DECL_OVERRIDE { QTcpSocket socket; - socket.connectToHost("localhost", 993); + socket.connectToHost("localhost", 143); return socket.waitForConnected(200); } @@ -36,7 +36,7 @@ protected: { auto resource = ApplicationDomain::ImapResource::create("account1"); resource.setProperty("server", "localhost"); - resource.setProperty("port", 993); + resource.setProperty("port", 143); resource.setProperty("username", "doe"); Sink::SecretStore::instance().insert(resource.identifier(), "doe"); return resource; diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp index 271b3d9..999665f 100644 --- a/examples/imapresource/tests/imapserverproxytest.cpp +++ b/examples/imapresource/tests/imapserverproxytest.cpp @@ -25,7 +25,7 @@ private slots: { Sink::Test::initTest(); QTcpSocket socket; - socket.connectToHost("localhost", 993); + socket.connectToHost("localhost", 143); QVERIFY(socket.waitForConnected(200)); system("resetmailbox.sh"); } @@ -43,45 +43,47 @@ private slots: void testLogin() { - ImapServerProxy imap("localhost", 993); + ImapServerProxy imap("localhost", 143, Imap::EncryptionMode::NoEncryption); VERIFYEXEC(imap.login("doe", "doe")); } void testLoginFailure() { //Using a bogus ip instead of a bogus hostname avoids getting stuck in the hostname lookup - ImapServerProxy imap("111.111.1.1", 993); + ImapServerProxy imap("111.111.1.1", 143, Imap::EncryptionMode::NoEncryption); VERIFYEXEC_FAIL(imap.login("doe", "doe")); } void testFetchFolders() { - QMap expectedFolderAndParent; - expectedFolderAndParent.insert("INBOX", ""); - expectedFolderAndParent.insert("Drafts", ""); - expectedFolderAndParent.insert("Trash", ""); - expectedFolderAndParent.insert("test", ""); - ImapServerProxy imap("localhost", 993); + QMap expectedFolderAndParent { + {"INBOX", ""}, + {"Drafts", ""}, + {"Trash", ""}, + {"test", ""} + }; + ImapServerProxy imap("localhost", 143, Imap::EncryptionMode::NoEncryption); VERIFYEXEC(imap.login("doe", "doe")); QVector list; VERIFYEXEC(imap.fetchFolders([&](const Folder &f){ list << f;})); for (const auto &f : list) { - QVERIFY(expectedFolderAndParent.contains(f.name())); + QVERIFY2(expectedFolderAndParent.contains(f.name()), QString{"Didn't expect folder %1"}.arg(f.name()).toUtf8()); QCOMPARE(expectedFolderAndParent.value(f.name()), f.parentPath()); expectedFolderAndParent.remove(f.name()); } QVERIFY(expectedFolderAndParent.isEmpty()); +//examples/imapresource/tests/imapserverproxytest testFetchFolders } void testFetchFoldersFailure() { - ImapServerProxy imap("foobar", 993); + ImapServerProxy imap("foobar", 143, Imap::EncryptionMode::NoEncryption); VERIFYEXEC_FAIL(imap.fetchFolders([](const Folder &){})); } void testFetchMail() { - ImapServerProxy imap("localhost", 993); + ImapServerProxy imap("localhost", 143, Imap::EncryptionMode::NoEncryption); VERIFYEXEC(imap.login("doe", "doe")); KIMAP2::FetchJob::FetchScope scope; @@ -98,7 +100,7 @@ private slots: void testRemoveMail() { - ImapServerProxy imap("localhost", 993); + ImapServerProxy imap("localhost", 143, Imap::EncryptionMode::NoEncryption); VERIFYEXEC(imap.login("doe", "doe")); VERIFYEXEC(imap.remove("INBOX.test", "1:*")); diff --git a/examples/imapresource/tests/populatemailbox.sh b/examples/imapresource/tests/populatemailbox.sh index 0889790..a5949fc 100644 --- a/examples/imapresource/tests/populatemailbox.sh +++ b/examples/imapresource/tests/populatemailbox.sh @@ -23,7 +23,7 @@ sudo echo "sub INBOX.Trash" | cyradm --auth PLAIN -u doe -w doe localhost # # sudo cp /src/sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S /var/spool/imap/d/user/doe/test/$i. # done # Because this is way faster than a loop -FOLDERPATH=/var/spool/imap/u/'user^doe^test' +FOLDERPATH=/var/spool/imap/d/user/doe/test sudo tee /dev/null $FOLDERPATH/{1..1000}. sudo tee /dev/null $FOLDERPATH/{1001..2000}. sudo tee /dev/null $FOLDERPATH/{2001..3000}. diff --git a/examples/imapresource/tests/resetmailbox.sh b/examples/imapresource/tests/resetmailbox.sh index f3a9391..8e6b1b1 100644 --- a/examples/imapresource/tests/resetmailbox.sh +++ b/examples/imapresource/tests/resetmailbox.sh @@ -9,6 +9,7 @@ sudo echo "subscribe INBOX.Drafts" | cyradm --auth PLAIN -u doe -w doe localhost sudo echo "cm user.doe.Trash" | cyradm --auth PLAIN -u cyrus -w admin localhost sudo echo "subscribe INBOX.Trash" | cyradm --auth PLAIN -u doe -w doe localhost sudo echo "sam user.doe cyrus c" | cyradm --auth PLAIN -u cyrus -w admin localhost -sudo cp /src/sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S /var/spool/imap/u/'user^doe^test'/1. -sudo chown cyrus:mail /var/spool/imap/u/'user^doe^test'/1. +FOLDERPATH=/var/spool/imap/d/user/doe/test +sudo cp /src/sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S $FOLDERPATH/1. +sudo chown cyrus:mail $FOLDERPATH/1. sudo reconstruct "user.doe.test" -- cgit v1.2.3