summaryrefslogtreecommitdiffstats
path: root/examples/imapresource/tests/imapmailtest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-05-18 11:38:29 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-05-18 11:38:29 +0200
commit78d9ca435ff06675da79426e09fe9be32106ce35 (patch)
tree112de3968faa8ea6f3f6b6db5c5ae477c64c496c /examples/imapresource/tests/imapmailtest.cpp
parent4cb1c1e6103459e54d931b8672674f5f49f8ac2f (diff)
downloadsink-78d9ca435ff06675da79426e09fe9be32106ce35.tar.gz
sink-78d9ca435ff06675da79426e09fe9be32106ce35.zip
Moved the bogus message test to the imap test.
Maildir will happly store anything.
Diffstat (limited to 'examples/imapresource/tests/imapmailtest.cpp')
-rw-r--r--examples/imapresource/tests/imapmailtest.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/examples/imapresource/tests/imapmailtest.cpp b/examples/imapresource/tests/imapmailtest.cpp
index e1dee0d..cab529b 100644
--- a/examples/imapresource/tests/imapmailtest.cpp
+++ b/examples/imapresource/tests/imapmailtest.cpp
@@ -1,11 +1,32 @@
1/*
2 * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
1#include <QtTest> 19#include <QtTest>
2#include <QTcpSocket> 20#include <QTcpSocket>
21#include <KMime/Message>
3 22
4#include <tests/mailtest.h> 23#include <tests/mailtest.h>
5 24
6#include "common/test.h" 25#include "common/test.h"
7#include "common/domain/applicationdomaintype.h" 26#include "common/domain/applicationdomaintype.h"
8#include "common/secretstore.h" 27#include "common/secretstore.h"
28#include "common/resourcecontrol.h"
29#include "common/store.h"
9 30
10using namespace Sink; 31using namespace Sink;
11using namespace Sink::ApplicationDomain; 32using namespace Sink::ApplicationDomain;
@@ -42,6 +63,70 @@ protected:
42 Sink::SecretStore::instance().insert(resource.identifier(), "doe"); 63 Sink::SecretStore::instance().insert(resource.identifier(), "doe");
43 return resource; 64 return resource;
44 } 65 }
66
67private slots:
68
69 void testBogusMessageAppend()
70 {
71 using namespace Sink;
72 using namespace Sink::ApplicationDomain;
73
74 auto folder = Folder::create(mResourceInstanceIdentifier);
75 folder.setName("bogusfolder");
76 VERIFYEXEC(Store::create(folder));
77
78 Mail bogusMail;
79 {
80 auto mail = Mail::create(mResourceInstanceIdentifier);
81 mail.setMimeMessage("Bogus message: \0 this doesn't make any sense and contains NUL.");
82 mail.setFolder(folder);
83
84 VERIFYEXEC(Store::create(mail));
85
86 VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier));
87 auto mails = Store::read<Mail>(Query().request<Mail::Folder>().request<Mail::Subject>().request<Mail::MimeMessage>());
88 QCOMPARE(mails.size(), 1);
89 bogusMail = mails.at(0);
90
91 VERIFYEXEC(ResourceControl::flushReplayQueue(mResourceInstanceIdentifier));
92 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, false)));
93 //The cache will be off by one (because we failed to replay)
94 // VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Folder>(ResourceControl::Inspection::CacheIntegrityInspection(folder)));
95 }
96
97
98 //Ensure we can still append further messages:
99 {
100 auto mail = Mail::create(mResourceInstanceIdentifier);
101 {
102 auto message = KMime::Message::Ptr::create();
103 message->subject(true)->fromUnicodeString("Subject", "utf8");
104 message->assemble();
105 mail.setMimeMessage(message->encodedContent(true));
106 }
107 mail.setFolder(folder);
108 VERIFYEXEC(Store::create(mail));
109
110 VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier));
111 auto mails = Store::read<Mail>(Query().request<Mail::Folder>().request<Mail::Subject>().request<Mail::MimeMessage>());
112 QCOMPARE(mails.size(), 2);
113
114 VERIFYEXEC(ResourceControl::flushReplayQueue(mResourceInstanceIdentifier));
115 //The mail is still not available, because we'll end up trying to replay the bogus mail again.
116 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, false)));
117
118 //Fix the situation by deleting the bogus mail and retrying to sync.
119 VERIFYEXEC(Store::remove(bogusMail));
120 VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier));
121 VERIFYEXEC(ResourceControl::flushReplayQueue(mResourceInstanceIdentifier));
122
123 //This will fail because we still try to resync the previous mail
124 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, true)));
125 //The cache will be off by one (because we failed to replay)
126 VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Folder>(ResourceControl::Inspection::CacheIntegrityInspection(folder)));
127 }
128
129 }
45}; 130};
46 131
47QTEST_MAIN(ImapMailTest) 132QTEST_MAIN(ImapMailTest)