diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-07 16:20:00 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-07 16:20:00 +0200 |
commit | c210d8c434d5fa8f6c56bbbdb0cb993ddd697213 (patch) | |
tree | f3f62d8b6ff8665605d3c22997c0e58f233f20c9 | |
parent | 41c69690d866414cf90d603629fd488ba9a981b5 (diff) | |
download | sink-c210d8c434d5fa8f6c56bbbdb0cb993ddd697213.tar.gz sink-c210d8c434d5fa8f6c56bbbdb0cb993ddd697213.zip |
Avoid crashing if we fail to resolve the local id.
-rw-r--r-- | examples/imapresource/imapresource.cpp | 7 | ||||
-rw-r--r-- | tests/mailsynctest.cpp | 37 | ||||
-rw-r--r-- | tests/mailsynctest.h | 2 |
3 files changed, 46 insertions, 0 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 50deacd..afa72fa 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -400,6 +400,9 @@ public: | |||
400 | QByteArray getFolderFromLocalId(const QByteArray &id) | 400 | QByteArray getFolderFromLocalId(const QByteArray &id) |
401 | { | 401 | { |
402 | auto mailRemoteId = syncStore().resolveLocalId(ApplicationDomain::getTypeName<ApplicationDomain::Mail>(), id); | 402 | auto mailRemoteId = syncStore().resolveLocalId(ApplicationDomain::getTypeName<ApplicationDomain::Mail>(), id); |
403 | if (mailRemoteId.isEmpty()) { | ||
404 | return {}; | ||
405 | } | ||
403 | return folderIdFromMailRid(mailRemoteId); | 406 | return folderIdFromMailRid(mailRemoteId); |
404 | } | 407 | } |
405 | 408 | ||
@@ -419,6 +422,10 @@ public: | |||
419 | if (isIndividualMailSync(request)) { | 422 | if (isIndividualMailSync(request)) { |
420 | auto newId = request.query.ids().first(); | 423 | auto newId = request.query.ids().first(); |
421 | auto requestFolder = getFolderFromLocalId(newId); | 424 | auto requestFolder = getFolderFromLocalId(newId); |
425 | if (requestFolder.isEmpty()) { | ||
426 | SinkWarningCtx(mLogCtx) << "Failed to find folder for local id. Ignoring request: " << request.query; | ||
427 | return; | ||
428 | } | ||
422 | for (auto &r : queue) { | 429 | for (auto &r : queue) { |
423 | if (isIndividualMailSync(r)) { | 430 | if (isIndividualMailSync(r)) { |
424 | auto queueFolder = getFolderFromLocalId(r.query.ids().first()); | 431 | auto queueFolder = getFolderFromLocalId(r.query.ids().first()); |
diff --git a/tests/mailsynctest.cpp b/tests/mailsynctest.cpp index 3e5a928..c8ba9f1 100644 --- a/tests/mailsynctest.cpp +++ b/tests/mailsynctest.cpp | |||
@@ -411,6 +411,43 @@ void MailSyncTest::testSyncSingleFolder() | |||
411 | 411 | ||
412 | } | 412 | } |
413 | 413 | ||
414 | void MailSyncTest::testSyncSingleMail() | ||
415 | { | ||
416 | VERIFYEXEC(Store::synchronize(Sink::SyncScope{}.resourceFilter(mResourceInstanceIdentifier))); | ||
417 | VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); | ||
418 | |||
419 | Mail::Ptr mail; | ||
420 | { | ||
421 | auto job = Store::fetchAll<Mail>(Sink::Query{}.resourceFilter(mResourceInstanceIdentifier)).template then([&](const QList<Mail::Ptr> &mails) { | ||
422 | QVERIFY(mails.size() >= 1); | ||
423 | mail = mails.first(); | ||
424 | }); | ||
425 | VERIFYEXEC(job); | ||
426 | } | ||
427 | |||
428 | auto syncScope = Sink::SyncScope{ApplicationDomain::getTypeName<Mail>()}; | ||
429 | syncScope.resourceFilter(mResourceInstanceIdentifier); | ||
430 | syncScope.filter(mail->identifier()); | ||
431 | |||
432 | // Ensure all local data is processed | ||
433 | VERIFYEXEC(Store::synchronize(syncScope)); | ||
434 | VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); | ||
435 | } | ||
436 | |||
437 | void MailSyncTest::testSyncSingleMailWithBogusId() | ||
438 | { | ||
439 | VERIFYEXEC(Store::synchronize(Sink::SyncScope{}.resourceFilter(mResourceInstanceIdentifier))); | ||
440 | VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); | ||
441 | |||
442 | auto syncScope = Sink::SyncScope{ApplicationDomain::getTypeName<Mail>()}; | ||
443 | syncScope.resourceFilter(mResourceInstanceIdentifier); | ||
444 | syncScope.filter("WTFisThisEven?"); | ||
445 | |||
446 | // Ensure all local data is processed | ||
447 | VERIFYEXEC(Store::synchronize(syncScope)); | ||
448 | VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); | ||
449 | } | ||
450 | |||
414 | void MailSyncTest::testFailingSync() | 451 | void MailSyncTest::testFailingSync() |
415 | { | 452 | { |
416 | auto resource = createFaultyResource(); | 453 | auto resource = createFaultyResource(); |
diff --git a/tests/mailsynctest.h b/tests/mailsynctest.h index 8ad3bb3..0decf00 100644 --- a/tests/mailsynctest.h +++ b/tests/mailsynctest.h | |||
@@ -70,6 +70,8 @@ private slots: | |||
70 | void testFlagChange(); | 70 | void testFlagChange(); |
71 | 71 | ||
72 | void testSyncSingleFolder(); | 72 | void testSyncSingleFolder(); |
73 | void testSyncSingleMail(); | ||
74 | void testSyncSingleMailWithBogusId(); | ||
73 | 75 | ||
74 | void testFailingSync(); | 76 | void testFailingSync(); |
75 | }; | 77 | }; |