From c210d8c434d5fa8f6c56bbbdb0cb993ddd697213 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 7 Apr 2017 16:20:00 +0200 Subject: Avoid crashing if we fail to resolve the local id. --- examples/imapresource/imapresource.cpp | 7 +++++++ tests/mailsynctest.cpp | 37 ++++++++++++++++++++++++++++++++++ tests/mailsynctest.h | 2 ++ 3 files changed, 46 insertions(+) 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: QByteArray getFolderFromLocalId(const QByteArray &id) { auto mailRemoteId = syncStore().resolveLocalId(ApplicationDomain::getTypeName(), id); + if (mailRemoteId.isEmpty()) { + return {}; + } return folderIdFromMailRid(mailRemoteId); } @@ -419,6 +422,10 @@ public: if (isIndividualMailSync(request)) { auto newId = request.query.ids().first(); auto requestFolder = getFolderFromLocalId(newId); + if (requestFolder.isEmpty()) { + SinkWarningCtx(mLogCtx) << "Failed to find folder for local id. Ignoring request: " << request.query; + return; + } for (auto &r : queue) { if (isIndividualMailSync(r)) { 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() } +void MailSyncTest::testSyncSingleMail() +{ + VERIFYEXEC(Store::synchronize(Sink::SyncScope{}.resourceFilter(mResourceInstanceIdentifier))); + VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); + + Mail::Ptr mail; + { + auto job = Store::fetchAll(Sink::Query{}.resourceFilter(mResourceInstanceIdentifier)).template then([&](const QList &mails) { + QVERIFY(mails.size() >= 1); + mail = mails.first(); + }); + VERIFYEXEC(job); + } + + auto syncScope = Sink::SyncScope{ApplicationDomain::getTypeName()}; + syncScope.resourceFilter(mResourceInstanceIdentifier); + syncScope.filter(mail->identifier()); + + // Ensure all local data is processed + VERIFYEXEC(Store::synchronize(syncScope)); + VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); +} + +void MailSyncTest::testSyncSingleMailWithBogusId() +{ + VERIFYEXEC(Store::synchronize(Sink::SyncScope{}.resourceFilter(mResourceInstanceIdentifier))); + VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); + + auto syncScope = Sink::SyncScope{ApplicationDomain::getTypeName()}; + syncScope.resourceFilter(mResourceInstanceIdentifier); + syncScope.filter("WTFisThisEven?"); + + // Ensure all local data is processed + VERIFYEXEC(Store::synchronize(syncScope)); + VERIFYEXEC(ResourceControl::flushMessageQueue(mResourceInstanceIdentifier)); +} + void MailSyncTest::testFailingSync() { 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: void testFlagChange(); void testSyncSingleFolder(); + void testSyncSingleMail(); + void testSyncSingleMailWithBogusId(); void testFailingSync(); }; -- cgit v1.2.3