Differential D20750 Diff 56819 messageviewer/src/messagepartthemes/default/autotests/unencryptedmessagetest.cpp
Changeset View
Changeset View
Standalone View
Standalone View
messageviewer/src/messagepartthemes/default/autotests/unencryptedmessagetest.cpp
- This file was copied to mimetreeparser/autotests/basicobjecttreeparsertest.cpp.
Show All 31 Lines | |||||
32 | 32 | | |||
33 | QTEST_MAIN(UnencryptedMessageTest) | 33 | QTEST_MAIN(UnencryptedMessageTest) | ||
34 | 34 | | |||
35 | void UnencryptedMessageTest::initTestCase() | 35 | void UnencryptedMessageTest::initTestCase() | ||
36 | { | 36 | { | ||
37 | Test::setupEnv(); | 37 | Test::setupEnv(); | ||
38 | } | 38 | } | ||
39 | 39 | | |||
40 | void UnencryptedMessageTest::testMailWithoutEncryption() | | |||
41 | { | | |||
42 | KMime::Message::Ptr originalMessage | | |||
43 | = Test::readAndParseMail(QStringLiteral("encapsulated-with-attachment.mbox")); | | |||
44 | MimeTreeParser::NodeHelper nodeHelper; | | |||
45 | Test::ObjectTreeSource emptySource(nullptr, nullptr); | | |||
46 | MimeTreeParser::ObjectTreeParser otp(&emptySource, &nodeHelper); | | |||
47 | otp.parseObjectTree(originalMessage.data()); | | |||
48 | QVERIFY(!nodeHelper.unencryptedMessage(originalMessage)); | | |||
49 | } | | |||
50 | | ||||
51 | void UnencryptedMessageTest::testSignedForwardedOpenPGPSignedEncrypted() | | |||
52 | { | | |||
53 | KMime::Message::Ptr originalMessage | | |||
54 | = Test::readAndParseMail(QStringLiteral("signed-forward-openpgp-signed-encrypted.mbox")); | | |||
55 | | ||||
56 | MimeTreeParser::NodeHelper nodeHelper; | | |||
57 | BufferedHtmlWriter testWriter; | | |||
58 | testWriter.begin(); | | |||
59 | Test::CSSHelper testCSSHelper; | | |||
60 | Test::ObjectTreeSource emptySource(&testWriter, &testCSSHelper); | | |||
61 | MimeTreeParser::ObjectTreeParser otp(&emptySource, &nodeHelper); | | |||
62 | otp.parseObjectTree(originalMessage.data()); | | |||
63 | testWriter.end(); | | |||
64 | | ||||
65 | QCOMPARE(otp.plainTextContent().toLatin1().data(), "bla bla bla"); // The textual content doesn't include the encrypted encapsulated message by design | | |||
66 | QCOMPARE(nodeHelper.overallEncryptionState( | | |||
67 | originalMessage.data()), MimeTreeParser::KMMsgPartiallyEncrypted); | | |||
68 | QCOMPARE(nodeHelper.overallSignatureState( | | |||
69 | originalMessage.data()), MimeTreeParser::KMMsgFullySigned); | | |||
70 | | ||||
71 | KMime::Message::Ptr unencryptedMessage = nodeHelper.unencryptedMessage(originalMessage); | | |||
72 | QVERIFY(!unencryptedMessage); // We must not invalidate the outer signature | | |||
73 | } | | |||
74 | | ||||
75 | void UnencryptedMessageTest::testForwardedOpenPGPSignedEncrypted() | | |||
76 | { | | |||
77 | KMime::Message::Ptr originalMessage | | |||
78 | = Test::readAndParseMail(QStringLiteral("forward-openpgp-signed-encrypted.mbox")); | | |||
79 | | ||||
80 | MimeTreeParser::NodeHelper nodeHelper; | | |||
81 | BufferedHtmlWriter testWriter; | | |||
82 | testWriter.begin(); | | |||
83 | Test::CSSHelper testCSSHelper; | | |||
84 | Test::ObjectTreeSource emptySource(&testWriter, &testCSSHelper); | | |||
85 | emptySource.setAllowDecryption(true); | | |||
86 | MimeTreeParser::ObjectTreeParser otp(&emptySource, &nodeHelper); | | |||
87 | otp.parseObjectTree(originalMessage.data()); | | |||
88 | testWriter.end(); | | |||
89 | | ||||
90 | QCOMPARE(otp.plainTextContent().toLatin1().data(), "bla bla bla"); // The textual content doesn't include the encrypted encapsulated message by design | | |||
91 | QCOMPARE(nodeHelper.overallEncryptionState( | | |||
92 | originalMessage.data()), MimeTreeParser::KMMsgPartiallyEncrypted); | | |||
93 | | ||||
94 | QCOMPARE(nodeHelper.overallSignatureState( | | |||
95 | originalMessage.data()), MimeTreeParser::KMMsgPartiallySigned); | | |||
96 | | ||||
97 | // Now, test that the unencrypted message is generated correctly | | |||
98 | KMime::Message::Ptr unencryptedMessage = nodeHelper.unencryptedMessage(originalMessage); | | |||
99 | QVERIFY(unencryptedMessage.data()); | | |||
100 | QCOMPARE(unencryptedMessage->contentType()->mimeType().data(), "multipart/mixed"); | | |||
101 | QCOMPARE(unencryptedMessage->contents().size(), 2); | | |||
102 | QCOMPARE(unencryptedMessage->contents().first()->contentType()->mimeType().data(), | | |||
103 | "text/plain"); | | |||
104 | QCOMPARE(unencryptedMessage->contents().first()->decodedContent().data(), "bla bla bla"); | | |||
105 | QCOMPARE(unencryptedMessage->contents().at( | | |||
106 | 1)->contentType()->mimeType().data(), "message/rfc822"); | | |||
107 | KMime::Message::Ptr encapsulated = unencryptedMessage->contents().at(1)->bodyAsMessage(); | | |||
108 | QCOMPARE(encapsulated->contentType()->mimeType().data(), "multipart/signed"); | | |||
109 | QCOMPARE(encapsulated->contents().size(), 2); | | |||
110 | QCOMPARE(encapsulated->contents().first()->contentType()->mimeType().data(), "text/plain"); | | |||
111 | QCOMPARE(encapsulated->contents().at( | | |||
112 | 1)->contentType()->mimeType().data(), "application/pgp-signature"); | | |||
113 | QCOMPARE(encapsulated->contents().first()->decodedContent().data(), "encrypted message text"); | | |||
114 | | ||||
115 | // TODO: Check that the signature is valid | | |||
116 | } | | |||
117 | | ||||
118 | void UnencryptedMessageTest::testSMIMESignedEncrypted() | | |||
119 | { | | |||
120 | KMime::Message::Ptr originalMessage | | |||
121 | = Test::readAndParseMail(QStringLiteral("smime-signed-encrypted.mbox")); | | |||
122 | | ||||
123 | MimeTreeParser::NodeHelper nodeHelper; | | |||
124 | Test::ObjectTreeSource emptySource(nullptr, nullptr); | | |||
125 | emptySource.setAllowDecryption(true); | | |||
126 | MimeTreeParser::ObjectTreeParser otp(&emptySource, &nodeHelper); | | |||
127 | otp.parseObjectTree(originalMessage.data()); | | |||
128 | | ||||
129 | QCOMPARE(otp.plainTextContent().toLatin1().data(), "encrypted message text"); | | |||
130 | QCOMPARE(nodeHelper.overallEncryptionState( | | |||
131 | originalMessage.data()), MimeTreeParser::KMMsgFullyEncrypted); | | |||
132 | | ||||
133 | QCOMPARE(nodeHelper.overallSignatureState( | | |||
134 | originalMessage.data()), MimeTreeParser::KMMsgFullySigned); | | |||
135 | | ||||
136 | // Now, test that the unencrypted message is generated correctly | | |||
137 | KMime::Message::Ptr unencryptedMessage = nodeHelper.unencryptedMessage(originalMessage); | | |||
138 | QCOMPARE(unencryptedMessage->contentType()->mimeType().data(), "multipart/signed"); | | |||
139 | QCOMPARE(unencryptedMessage->contents().size(), 2); | | |||
140 | QCOMPARE(unencryptedMessage->contents().first()->contentType()->mimeType().data(), | | |||
141 | "text/plain"); | | |||
142 | QCOMPARE(unencryptedMessage->contents().at( | | |||
143 | 1)->contentType()->mimeType().data(), "application/pkcs7-signature"); | | |||
144 | QCOMPARE( | | |||
145 | unencryptedMessage->contents().first()->decodedContent().data(), "encrypted message text"); | | |||
146 | | ||||
147 | // TODO: Check that the signature is valid | | |||
148 | } | | |||
149 | | ||||
150 | void UnencryptedMessageTest::testOpenPGPSignedEncrypted() | | |||
151 | { | | |||
152 | KMime::Message::Ptr originalMessage | | |||
153 | = Test::readAndParseMail(QStringLiteral("openpgp-signed-encrypted.mbox")); | | |||
154 | | ||||
155 | MimeTreeParser::NodeHelper nodeHelper; | | |||
156 | Test::ObjectTreeSource emptySource(nullptr, nullptr); | | |||
157 | emptySource.setAllowDecryption(true); | | |||
158 | MimeTreeParser::ObjectTreeParser otp(&emptySource, &nodeHelper); | | |||
159 | otp.parseObjectTree(originalMessage.data()); | | |||
160 | | ||||
161 | QCOMPARE(otp.plainTextContent().toLatin1().data(), "encrypted message text"); | | |||
162 | QCOMPARE(nodeHelper.overallEncryptionState( | | |||
163 | originalMessage.data()), MimeTreeParser::KMMsgFullyEncrypted); | | |||
164 | | ||||
165 | QCOMPARE(nodeHelper.overallSignatureState( | | |||
166 | originalMessage.data()), MimeTreeParser::KMMsgFullySigned); | | |||
167 | | ||||
168 | // Now, test that the unencrypted message is generated correctly | | |||
169 | KMime::Message::Ptr unencryptedMessage = nodeHelper.unencryptedMessage(originalMessage); | | |||
170 | QCOMPARE(unencryptedMessage->contentType()->mimeType().data(), "multipart/signed"); | | |||
171 | QCOMPARE(unencryptedMessage->contents().size(), 2); | | |||
172 | QCOMPARE(unencryptedMessage->contents().first()->contentType()->mimeType().data(), | | |||
173 | "text/plain"); | | |||
174 | QCOMPARE(unencryptedMessage->contents().at( | | |||
175 | 1)->contentType()->mimeType().data(), "application/pgp-signature"); | | |||
176 | QCOMPARE( | | |||
177 | unencryptedMessage->contents().first()->decodedContent().data(), "encrypted message text"); | | |||
178 | | ||||
179 | // TODO: Check that the signature is valid | | |||
180 | } | | |||
181 | | ||||
182 | void UnencryptedMessageTest::testOpenPGPEncryptedAndSigned() | | |||
183 | { | | |||
184 | KMime::Message::Ptr originalMessage | | |||
185 | = Test::readAndParseMail(QStringLiteral("openpgp-encrypted+signed.mbox")); | | |||
186 | | ||||
187 | MimeTreeParser::NodeHelper nodeHelper; | | |||
188 | Test::ObjectTreeSource emptySource(nullptr, nullptr); | | |||
189 | emptySource.setAllowDecryption(true); | | |||
190 | MimeTreeParser::ObjectTreeParser otp(&emptySource, &nodeHelper); | | |||
191 | otp.parseObjectTree(originalMessage.data()); | | |||
192 | | ||||
193 | QCOMPARE(otp.plainTextContent().toLatin1().data(), "encrypted message text"); | | |||
194 | QCOMPARE(nodeHelper.overallEncryptionState( | | |||
195 | originalMessage.data()), MimeTreeParser::KMMsgFullyEncrypted); | | |||
196 | | ||||
197 | QCOMPARE(nodeHelper.overallSignatureState( | | |||
198 | originalMessage.data()), MimeTreeParser::KMMsgFullySigned); | | |||
199 | | ||||
200 | // Now, test that the unencrypted message is generated correctly | | |||
201 | KMime::Message::Ptr unencryptedMessage = nodeHelper.unencryptedMessage(originalMessage); | | |||
202 | QCOMPARE(unencryptedMessage->contentType()->mimeType().data(), "text/plain"); | | |||
203 | QCOMPARE(unencryptedMessage->contents().size(), 0); | | |||
204 | QCOMPARE(unencryptedMessage->decodedContent().data(), "encrypted message text"); | | |||
205 | | ||||
206 | // TODO: Check that the signature is valid | | |||
207 | } | | |||
208 | | ||||
209 | void UnencryptedMessageTest::testOpenPGPEncrypted() | | |||
210 | { | | |||
211 | KMime::Message::Ptr originalMessage | | |||
212 | = Test::readAndParseMail(QStringLiteral("openpgp-encrypted.mbox")); | | |||
213 | | ||||
214 | MimeTreeParser::NodeHelper nodeHelper; | | |||
215 | Test::ObjectTreeSource emptySource(nullptr, nullptr); | | |||
216 | emptySource.setAllowDecryption(true); | | |||
217 | MimeTreeParser::ObjectTreeParser otp(&emptySource, &nodeHelper); | | |||
218 | otp.parseObjectTree(originalMessage.data()); | | |||
219 | | ||||
220 | QCOMPARE(otp.plainTextContent().toLatin1().data(), "encrypted message text"); | | |||
221 | QCOMPARE(nodeHelper.overallEncryptionState( | | |||
222 | originalMessage.data()), MimeTreeParser::KMMsgFullyEncrypted); | | |||
223 | | ||||
224 | // Now, test that the unencrypted message is generated correctly | | |||
225 | KMime::Message::Ptr unencryptedMessage = nodeHelper.unencryptedMessage(originalMessage); | | |||
226 | QCOMPARE(unencryptedMessage->contentType()->mimeType().data(), "text/plain"); | | |||
227 | QCOMPARE(unencryptedMessage->decodedContent().data(), "encrypted message text"); | | |||
228 | QCOMPARE(unencryptedMessage->contents().size(), 0); | | |||
229 | } | | |||
230 | | ||||
231 | void UnencryptedMessageTest::testOpenPGPEncryptedNotDecrypted() | | |||
232 | { | | |||
233 | KMime::Message::Ptr originalMessage | | |||
234 | = Test::readAndParseMail(QStringLiteral("openpgp-encrypted.mbox")); | | |||
235 | | ||||
236 | MimeTreeParser::NodeHelper nodeHelper; | | |||
237 | Test::ObjectTreeSource emptySource(nullptr, nullptr); | | |||
238 | emptySource.setAllowDecryption(false); | | |||
239 | MimeTreeParser::ObjectTreeParser otp(&emptySource, &nodeHelper); | | |||
240 | otp.parseObjectTree(originalMessage.data()); | | |||
241 | | ||||
242 | QCOMPARE(nodeHelper.overallEncryptionState( | | |||
243 | originalMessage.data()), MimeTreeParser::KMMsgFullyEncrypted); | | |||
244 | QCOMPARE(otp.plainTextContent().toLatin1().data(), ""); | | |||
245 | | ||||
246 | KMime::Message::Ptr unencryptedMessage = nodeHelper.unencryptedMessage(originalMessage); | | |||
247 | QVERIFY(!unencryptedMessage); | | |||
248 | } | | |||
249 | | ||||
250 | void UnencryptedMessageTest::testAsync_data() | | |||
251 | { | | |||
252 | QTest::addColumn<QString>("mailFileName"); | | |||
253 | QTest::addColumn<QString>("output"); | | |||
254 | | ||||
255 | QTest::newRow("openpgp-encrypt") << QStringLiteral("openpgp-encrypted.mbox") << QStringLiteral( | | |||
256 | "encrypted message text"); | | |||
257 | QTest::newRow("smime-opaque-sign") << QStringLiteral("smime-opaque-sign.mbox") | | |||
258 | << QStringLiteral("A simple signed only test."); | | |||
259 | QTest::newRow("smime-encrypt") << QStringLiteral("smime-encrypted.mbox") << QStringLiteral( | | |||
260 | "The quick brown fox jumped over the lazy dog."); | | |||
261 | QTest::newRow("openpgp-inline-encrypt") << QStringLiteral( | | |||
262 | "openpgp-inline-charset-encrypted.mbox") << QStringLiteral( | | |||
263 | "asdasd asd asd asdf sadf sdaf sadf \u00F6\u00E4\u00FC"); | | |||
264 | } | | |||
265 | | ||||
266 | void UnencryptedMessageTest::testAsync() | | |||
267 | { | | |||
268 | QFETCH(QString, mailFileName); | | |||
269 | QFETCH(QString, output); | | |||
270 | | ||||
271 | KMime::Message::Ptr originalMessage = Test::readAndParseMail(mailFileName); | | |||
272 | MimeTreeParser::NodeHelper nodeHelper; | | |||
273 | Test::ObjectTreeSource emptySource(nullptr, nullptr); | | |||
274 | emptySource.setAllowDecryption(true); | | |||
275 | { | | |||
276 | QEventLoop loop; | | |||
277 | MimeTreeParser::ObjectTreeParser otp(&emptySource, &nodeHelper); | | |||
278 | | ||||
279 | connect(&nodeHelper, &MimeTreeParser::NodeHelper::update, &loop, &QEventLoop::quit); | | |||
280 | otp.setAllowAsync(true); | | |||
281 | otp.parseObjectTree(originalMessage.data()); | | |||
282 | loop.exec(); | | |||
283 | } | | |||
284 | // Job ended | | |||
285 | { | | |||
286 | MimeTreeParser::ObjectTreeParser otp(&emptySource, &nodeHelper); | | |||
287 | otp.setAllowAsync(true); | | |||
288 | otp.parseObjectTree(originalMessage.data()); | | |||
289 | QCOMPARE(otp.plainTextContent(), output); | | |||
290 | } | | |||
291 | } | | |||
292 | | ||||
293 | void UnencryptedMessageTest::testNotDecrypted_data() | 40 | void UnencryptedMessageTest::testNotDecrypted_data() | ||
294 | { | 41 | { | ||
295 | QTest::addColumn<QString>("mailFileName"); | 42 | QTest::addColumn<QString>("mailFileName"); | ||
296 | QTest::addColumn<bool>("decryptMessage"); | 43 | QTest::addColumn<bool>("decryptMessage"); | ||
297 | 44 | | |||
298 | QTest::newRow("openpgp-inline") << QStringLiteral("inlinepgpencrypted.mbox") << true; | 45 | QTest::newRow("openpgp-inline") << QStringLiteral("inlinepgpencrypted.mbox") << true; | ||
299 | QTest::newRow("openpgp-encrypt") << QStringLiteral("openpgp-encrypted.mbox") << true; | 46 | QTest::newRow("openpgp-encrypt") << QStringLiteral("openpgp-encrypted.mbox") << true; | ||
300 | QTest::newRow("smime-encrypt") << QStringLiteral("smime-encrypted.mbox") << true; | 47 | QTest::newRow("smime-encrypt") << QStringLiteral("smime-encrypted.mbox") << true; | ||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |