diff options
| author | Tobias Markmann <tm@ayena.de> | 2019-01-15 10:53:33 (GMT) |
|---|---|---|
| committer | Tobias Markmann <tm@ayena.de> | 2019-01-15 10:55:04 (GMT) |
| commit | e618ab44aa09d6b69b08b14d43ee9ff2dd6abb0e (patch) | |
| tree | 8e84092fba2f6a01b75b8cf313208aa2c8897216 /Swiften | |
| parent | 6f6ad903d9e248f59bddedb3ab4cae41a7d8bec0 (diff) | |
| parent | 6874d64ed2684d83cb3e340f58f6c8c5089aa857 (diff) | |
| download | swift-e618ab44aa09d6b69b08b14d43ee9ff2dd6abb0e.zip swift-e618ab44aa09d6b69b08b14d43ee9ff2dd6abb0e.tar.bz2 | |
Merge tag 'swift-4.x' into master
* branch 'swift-4.x':
Update for Debian
Don't crash on missing bookmark result
Add missing include for QAbstractItemModel
Update Debian changelog
Fix convertToWindowsVersion() function to handle more RCs
Fix error response handling when requesting VCards
Test-Information:
./scons test=all succeeded on macOS 10.14.2.
Change-Id: I99d20a8b0e1b0be501fbbe95adebbff15f510184
Diffstat (limited to 'Swiften')
| -rw-r--r-- | Swiften/ChangeLog.md | 6 | ||||
| -rw-r--r-- | Swiften/VCards/UnitTest/VCardManagerTest.cpp | 127 | ||||
| -rw-r--r-- | Swiften/VCards/VCardManager.cpp | 5 |
3 files changed, 121 insertions, 17 deletions
diff --git a/Swiften/ChangeLog.md b/Swiften/ChangeLog.md index a656292..60355b4 100644 --- a/Swiften/ChangeLog.md +++ b/Swiften/ChangeLog.md @@ -1,14 +1,18 @@ 5-in-progress ------------- - Update build system from scons 2.4.0 to 3.0.1 -4.0 (2017-03-20) +4.0.1 (2018-03-28) +------------------ +- Fix handling errors when fetching own vCard + +4.0 (2018-03-20) ---------------- - Moved code-base to C++11 - Use C++11 threading instead of Boost.Thread library - Use C++11 smart pointers instead of Boost's - Migrated from Boost.Signals to Boost.Signals2 - Build without warnings on our CI platforms - General cleanup like remove of superflous files and #include statements. This means header files that previously were included implictly need to be explicitly included now - Support IPv6 addresses in URLs - Handle sessions being closed by the server diff --git a/Swiften/VCards/UnitTest/VCardManagerTest.cpp b/Swiften/VCards/UnitTest/VCardManagerTest.cpp index 3d5338d..669c3ff 100644 --- a/Swiften/VCards/UnitTest/VCardManagerTest.cpp +++ b/Swiften/VCards/UnitTest/VCardManagerTest.cpp @@ -1,11 +1,11 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <memory> #include <vector> #include <boost/bind.hpp> @@ -25,19 +25,29 @@ using namespace Swift; class VCardManagerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(VCardManagerTest); CPPUNIT_TEST(testGet_NewVCardRequestsVCard); CPPUNIT_TEST(testGet_ExistingVCard); CPPUNIT_TEST(testRequest_RequestsVCard); CPPUNIT_TEST(testRequest_ReceiveEmitsNotification); CPPUNIT_TEST(testRequest_Error); CPPUNIT_TEST(testRequest_VCardAlreadyRequested); CPPUNIT_TEST(testRequest_AfterPreviousRequest); - CPPUNIT_TEST(testRequestOwnVCard); + + CPPUNIT_TEST(testRequestVCard_ReturnFullVCard); + CPPUNIT_TEST(testRequestVCard_ReturnEmptyVCard); + CPPUNIT_TEST(testRequestVCard_ReturnItemNotFoundError); + CPPUNIT_TEST(testRequestVCard_ReturnFeatureNotImplementedError); + + CPPUNIT_TEST(testRequestOwnVCard_ReturnFullVCard); + CPPUNIT_TEST(testRequestOwnVCard_ReturnEmptyVCard); + CPPUNIT_TEST(testRequestOwnVCard_ReturnItemNotFoundError); + CPPUNIT_TEST(testRequestOwnVCard_ReturnFeatureNotImplementedError); + CPPUNIT_TEST(testCreateSetVCardRequest); CPPUNIT_TEST(testCreateSetVCardRequest_Error); CPPUNIT_TEST_SUITE_END(); public: void setUp() { changes.clear(); ownChanges.clear(); ownJID = JID("baz@fum.com/dum"); @@ -48,119 +58,210 @@ class VCardManagerTest : public CppUnit::TestFixture { } void tearDown() { delete vcardStorage; delete iqRouter; delete stanzaChannel; } void testGet_NewVCardRequestsVCard() { - std::shared_ptr<VCardManager> testling = createManager(); + auto testling = createManager(); VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("foo@bar.com/baz")); CPPUNIT_ASSERT(!result); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size())); CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get)); } void testGet_ExistingVCard() { - std::shared_ptr<VCardManager> testling = createManager(); + auto testling = createManager(); VCard::ref vcard(new VCard()); vcard->setFullName("Foo Bar"); vcardStorage->setVCard(JID("foo@bar.com/baz"), vcard); VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("foo@bar.com/baz")); CPPUNIT_ASSERT_EQUAL(std::string("Foo Bar"), result->getFullName()); CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(stanzaChannel->sentStanzas.size())); } void testRequest_RequestsVCard() { - std::shared_ptr<VCardManager> testling = createManager(); + auto testling = createManager(); testling->requestVCard(JID("foo@bar.com/baz")); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size())); CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get)); } void testRequest_ReceiveEmitsNotification() { - std::shared_ptr<VCardManager> testling = createManager(); + auto testling = createManager(); testling->requestVCard(JID("foo@bar.com/baz")); stanzaChannel->onIQReceived(createVCardResult()); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size())); CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), changes[0].first); CPPUNIT_ASSERT_EQUAL(std::string("Foo Bar"), changes[0].second->getFullName()); CPPUNIT_ASSERT_EQUAL(std::string("Foo Bar"), vcardStorage->getVCard(JID("foo@bar.com/baz"))->getFullName()); CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(ownChanges.size())); } void testRequest_Error() { - std::shared_ptr<VCardManager> testling = createManager(); + auto testling = createManager(); testling->requestVCard(JID("foo@bar.com/baz")); stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID())); // On error, cached vCards should not be changed. CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changes.size())); } void testRequest_VCardAlreadyRequested() { - std::shared_ptr<VCardManager> testling = createManager(); + auto testling = createManager(); testling->requestVCard(JID("foo@bar.com/baz")); VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("foo@bar.com/baz")); CPPUNIT_ASSERT(!result); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size())); } void testRequest_AfterPreviousRequest() { - std::shared_ptr<VCardManager> testling = createManager(); + auto testling = createManager(); testling->requestVCard(JID("foo@bar.com/baz")); stanzaChannel->onIQReceived(createVCardResult()); testling->requestVCard(JID("foo@bar.com/baz")); CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(stanzaChannel->sentStanzas.size())); CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(1, JID("foo@bar.com/baz"), IQ::Get)); } - void testRequestOwnVCard() { - std::shared_ptr<VCardManager> testling = createManager(); + void testRequestVCard_ReturnFullVCard() { + auto testling = createManager(); + testling->requestVCard(JID("foo@bar.com/baz")); + stanzaChannel->onIQReceived(createVCardResult()); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size())); + CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size())); + CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), changes[0].first); + CPPUNIT_ASSERT_EQUAL(std::string("Foo Bar"), changes[0].second->getFullName()); + CPPUNIT_ASSERT_EQUAL(false, changes[0].second->isEmpty()); + } + + void testRequestVCard_ReturnEmptyVCard() { + auto testling = createManager(); + testling->requestVCard(JID("foo@bar.com/baz")); + stanzaChannel->onIQReceived([&](){ + auto vcard = std::make_shared<VCard>(); + return IQ::createResult(JID("foo@bar.com/baz"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), vcard); + }()); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size())); + CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size())); + CPPUNIT_ASSERT_EQUAL(true, changes[0].second->isEmpty()); + } + + void testRequestVCard_ReturnItemNotFoundError() { + auto testling = createManager(); + testling->requestVCard(JID("foo@bar.com/baz")); + stanzaChannel->onIQReceived([&](){ + return IQ::createError(JID("foo@bar.com/baz"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), ErrorPayload::ItemNotFound); + }()); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size())); + CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size())); + CPPUNIT_ASSERT_EQUAL(true, changes[0].second->isEmpty()); + } + + void testRequestVCard_ReturnFeatureNotImplementedError() { + auto testling = createManager(); + testling->requestVCard(JID("foo@bar.com/baz")); + stanzaChannel->onIQReceived([&](){ + return IQ::createError(JID("foo@bar.com/baz"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), ErrorPayload::FeatureNotImplemented); + }()); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size())); + CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changes.size())); + } + + void testRequestOwnVCard_ReturnFullVCard() { + auto testling = createManager(); testling->requestVCard(ownJID); stanzaChannel->onIQReceived(createOwnVCardResult()); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size())); CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID(), IQ::Get)); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size())); CPPUNIT_ASSERT_EQUAL(ownJID.toBare(), changes[0].first); CPPUNIT_ASSERT_EQUAL(std::string("Myself"), changes[0].second->getFullName()); CPPUNIT_ASSERT_EQUAL(std::string("Myself"), vcardStorage->getVCard(ownJID.toBare())->getFullName()); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(ownChanges.size())); CPPUNIT_ASSERT_EQUAL(std::string("Myself"), ownChanges[0]->getFullName()); } + void testRequestOwnVCard_ReturnEmptyVCard() { + auto testling = createManager(); + testling->requestVCard(ownJID); + stanzaChannel->onIQReceived([&](){ + auto vcard = std::make_shared<VCard>(); + return IQ::createResult(JID(), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), vcard); + }()); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size())); + CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID(), IQ::Get)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size())); + CPPUNIT_ASSERT_EQUAL(true, changes[0].second->isEmpty()); + } + + void testRequestOwnVCard_ReturnItemNotFoundError() { + auto testling = createManager(); + testling->requestVCard(ownJID); + stanzaChannel->onIQReceived([&](){ + return IQ::createError(JID(), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), ErrorPayload::ItemNotFound); + }()); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size())); + CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID(), IQ::Get)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size())); + CPPUNIT_ASSERT_EQUAL(true, changes[0].second->isEmpty()); + } + + void testRequestOwnVCard_ReturnFeatureNotImplementedError() { + auto testling = createManager(); + testling->requestVCard(ownJID); + stanzaChannel->onIQReceived([&](){ + return IQ::createError(JID(), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), ErrorPayload::FeatureNotImplemented); + }()); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size())); + CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID(), IQ::Get)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changes.size())); + } + void testCreateSetVCardRequest() { - std::shared_ptr<VCardManager> testling = createManager(); + auto testling = createManager(); VCard::ref vcard = std::make_shared<VCard>(); vcard->setFullName("New Name"); SetVCardRequest::ref request = testling->createSetVCardRequest(vcard); request->send(); stanzaChannel->onIQReceived(createSetVCardResult()); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size())); CPPUNIT_ASSERT_EQUAL(ownJID.toBare(), changes[0].first); CPPUNIT_ASSERT_EQUAL(std::string("New Name"), changes[0].second->getFullName()); } void testCreateSetVCardRequest_Error() { - std::shared_ptr<VCardManager> testling = createManager(); + auto testling = createManager(); VCard::ref vcard = std::make_shared<VCard>(); vcard->setFullName("New Name"); SetVCardRequest::ref request = testling->createSetVCardRequest(vcard); request->send(); stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getID())); CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changes.size())); } diff --git a/Swiften/VCards/VCardManager.cpp b/Swiften/VCards/VCardManager.cpp index 95b96fa..9423702 100644 --- a/Swiften/VCards/VCardManager.cpp +++ b/Swiften/VCards/VCardManager.cpp @@ -1,11 +1,11 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/VCards/VCardManager.h> #include <boost/bind.hpp> #include <Swiften/Base/Log.h> @@ -44,22 +44,21 @@ void VCardManager::requestVCard(const JID& requestedJID) { request->onResponse.connect(boost::bind(&VCardManager::handleVCardReceived, this, jid, _1, _2)); request->send(); requestedVCards.insert(jid); } void VCardManager::requestOwnVCard() { requestVCard(JID()); } - void VCardManager::handleVCardReceived(const JID& actualJID, VCard::ref vcard, ErrorPayload::ref error) { requestedVCards.erase(actualJID); - if (!error) { + if (!error || (error && error->getCondition() == ErrorPayload::ItemNotFound)) { if (!vcard) { vcard = VCard::ref(new VCard()); } JID jid = actualJID.isValid() ? actualJID : ownJID.toBare(); setVCard(jid, vcard); } else { onVCardRetrievalError(actualJID, error); } |
Swift