summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2018-02-21 11:20:54 (GMT)
committerTobias Markmann <tm@ayena.de>2018-02-21 14:04:09 (GMT)
commit7a9c3d136e8d5be70869950489036b665c462294 (patch)
tree8d4bee5bdf1fe2aa6560423085b8f0ea63fa63b3 /Swift/Controllers/Chat
parent9f63c4a1456e154e6b48de2f9a8fa5105c8c020b (diff)
downloadswift-7a9c3d136e8d5be70869950489036b665c462294.zip
swift-7a9c3d136e8d5be70869950489036b665c462294.tar.bz2
Fix handling of unusual JIDs in room bookmarks
Test-Information: Added unit tests for bookmark handling for domain-only, bare, and full JIDs. Builds and unit tests pass on macOS 10.13.3. Change-Id: I2855f4e9bdce4aa971575b2bad01e6dd166042bb
Diffstat (limited to 'Swift/Controllers/Chat')
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp12
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp84
2 files changed, 88 insertions, 8 deletions
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index a6f7fe0..19400f9 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2017 Isode Limited. 2 * Copyright (c) 2010-2018 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -331,11 +331,13 @@ void ChatsManager::handleBookmarksReady() {
331} 331}
332 332
333void ChatsManager::handleMUCBookmarkAdded(const MUCBookmark& bookmark) { 333void ChatsManager::handleMUCBookmarkAdded(const MUCBookmark& bookmark) {
334 std::map<JID, MUCController*>::iterator it = mucControllers_.find(bookmark.getRoom()); 334 if (bookmark.getRoom().isBare() && !bookmark.getRoom().getNode().empty()) {
335 if (it == mucControllers_.end() && bookmark.getAutojoin()) { 335 std::map<JID, MUCController*>::iterator it = mucControllers_.find(bookmark.getRoom());
336 handleJoinMUCRequest(bookmark.getRoom(), bookmark.getPassword(), bookmark.getNick(), false, false, false ); 336 if (it == mucControllers_.end() && bookmark.getAutojoin()) {
337 handleJoinMUCRequest(bookmark.getRoom(), bookmark.getPassword(), bookmark.getNick(), false, false, false );
338 }
339 chatListWindow_->addMUCBookmark(bookmark);
337 } 340 }
338 chatListWindow_->addMUCBookmark(bookmark);
339} 341}
340 342
341void ChatsManager::handleMUCBookmarkRemoved(const MUCBookmark& bookmark) { 343void ChatsManager::handleMUCBookmarkRemoved(const MUCBookmark& bookmark) {
diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
index 1502dc9..08609ee 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2017 Isode Limited. 2 * Copyright (c) 2010-2018 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -32,9 +32,12 @@
32#include <Swiften/Elements/Forwarded.h> 32#include <Swiften/Elements/Forwarded.h>
33#include <Swiften/Elements/MUCInvitationPayload.h> 33#include <Swiften/Elements/MUCInvitationPayload.h>
34#include <Swiften/Elements/MUCUserPayload.h> 34#include <Swiften/Elements/MUCUserPayload.h>
35#include <Swiften/Elements/PrivateStorage.h>
36#include <Swiften/Elements/Storage.h>
35#include <Swiften/FileTransfer/UnitTest/DummyFileTransferManager.h> 37#include <Swiften/FileTransfer/UnitTest/DummyFileTransferManager.h>
36#include <Swiften/Jingle/JingleSessionManager.h> 38#include <Swiften/Jingle/JingleSessionManager.h>
37#include <Swiften/MUC/MUCManager.h> 39#include <Swiften/MUC/MUCManager.h>
40#include <Swiften/MUC/UnitTest/MockMUC.h>
38#include <Swiften/Network/DummyTimerFactory.h> 41#include <Swiften/Network/DummyTimerFactory.h>
39#include <Swiften/Presence/DirectedPresenceSender.h> 42#include <Swiften/Presence/DirectedPresenceSender.h>
40#include <Swiften/Presence/PresenceOracle.h> 43#include <Swiften/Presence/PresenceOracle.h>
@@ -71,7 +74,6 @@
71#include <SwifTools/Notifier/Notifier.h> 74#include <SwifTools/Notifier/Notifier.h>
72 75
73#include <Swift/QtUI/QtSwiftUtil.h> 76#include <Swift/QtUI/QtSwiftUtil.h>
74#include <Swiften/MUC/UnitTest/MockMUC.h>
75 77
76using namespace Swift; 78using namespace Swift;
77 79
@@ -155,6 +157,11 @@ class ChatsManagerTest : public CppUnit::TestFixture {
155 CPPUNIT_TEST(testImpromptuChatWindowTitle); 157 CPPUNIT_TEST(testImpromptuChatWindowTitle);
156 CPPUNIT_TEST(testStandardMUCChatWindowTitle); 158 CPPUNIT_TEST(testStandardMUCChatWindowTitle);
157 159
160 // Bookmark tests
161 CPPUNIT_TEST(testReceivingBookmarksWithDomainJID);
162 CPPUNIT_TEST(testReceivingBookmarksWithBareJID);
163 CPPUNIT_TEST(testReceivingBookmarksWithFullJID);
164
158 CPPUNIT_TEST_SUITE_END(); 165 CPPUNIT_TEST_SUITE_END();
159 166
160public: 167public:
@@ -1598,6 +1605,78 @@ public:
1598 CPPUNIT_ASSERT_EQUAL(std::string("mucroom"), window->name_); 1605 CPPUNIT_ASSERT_EQUAL(std::string("mucroom"), window->name_);
1599 } 1606 }
1600 1607
1608 static std::shared_ptr<Storage> createBookmarkStorageWithJID(const JID& jid) {
1609 auto storage = std::make_shared<Storage>();
1610 auto room = Storage::Room();
1611 room.jid = jid;
1612 room.autoJoin = true;
1613 storage->addRoom(room);
1614 return storage;
1615 }
1616
1617 void testReceivingBookmarksWithDomainJID() {
1618 auto bookmarkRequest = std::dynamic_pointer_cast<IQ>(stanzaChannel_->sentStanzas[0]);
1619 CPPUNIT_ASSERT(bookmarkRequest);
1620 CPPUNIT_ASSERT_EQUAL(IQ::Get, bookmarkRequest->getType());
1621
1622 auto privateStorage = bookmarkRequest->getPayload<PrivateStorage>();
1623 CPPUNIT_ASSERT(privateStorage);
1624
1625 auto storage = std::dynamic_pointer_cast<Storage>(privateStorage->getPayload());
1626 CPPUNIT_ASSERT(storage);
1627
1628 auto response = IQ::createResult(
1629 bookmarkRequest->getFrom(),
1630 bookmarkRequest->getTo(),
1631 bookmarkRequest->getID(),
1632 std::make_shared<PrivateStorage>(createBookmarkStorageWithJID("montague.lit"))
1633 );
1634 stanzaChannel_->onIQReceived(response);
1635 }
1636
1637 void testReceivingBookmarksWithBareJID() {
1638 auto bookmarkRequest = std::dynamic_pointer_cast<IQ>(stanzaChannel_->sentStanzas[0]);
1639 CPPUNIT_ASSERT(bookmarkRequest);
1640 CPPUNIT_ASSERT_EQUAL(IQ::Get, bookmarkRequest->getType());
1641
1642 auto privateStorage = bookmarkRequest->getPayload<PrivateStorage>();
1643 CPPUNIT_ASSERT(privateStorage);
1644
1645 auto storage = std::dynamic_pointer_cast<Storage>(privateStorage->getPayload());
1646 CPPUNIT_ASSERT(storage);
1647
1648 MockChatWindow* window = new MockChatWindow();
1649 mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID("example@montague.lit"), uiEventStream_).Return(window);
1650
1651 auto response = IQ::createResult(
1652 bookmarkRequest->getFrom(),
1653 bookmarkRequest->getTo(),
1654 bookmarkRequest->getID(),
1655 std::make_shared<PrivateStorage>(createBookmarkStorageWithJID("example@montague.lit"))
1656 );
1657 stanzaChannel_->onIQReceived(response);
1658 }
1659
1660 void testReceivingBookmarksWithFullJID() {
1661 auto bookmarkRequest = std::dynamic_pointer_cast<IQ>(stanzaChannel_->sentStanzas[0]);
1662 CPPUNIT_ASSERT(bookmarkRequest);
1663 CPPUNIT_ASSERT_EQUAL(IQ::Get, bookmarkRequest->getType());
1664
1665 auto privateStorage = bookmarkRequest->getPayload<PrivateStorage>();
1666 CPPUNIT_ASSERT(privateStorage);
1667
1668 auto storage = std::dynamic_pointer_cast<Storage>(privateStorage->getPayload());
1669 CPPUNIT_ASSERT(storage);
1670
1671 auto response = IQ::createResult(
1672 bookmarkRequest->getFrom(),
1673 bookmarkRequest->getTo(),
1674 bookmarkRequest->getID(),
1675 std::make_shared<PrivateStorage>(createBookmarkStorageWithJID("example@montague.lit/someresource"))
1676 );
1677 stanzaChannel_->onIQReceived(response);
1678 }
1679
1601private: 1680private:
1602 std::shared_ptr<Message> makeDeliveryReceiptTestMessage(const JID& from, const std::string& id) { 1681 std::shared_ptr<Message> makeDeliveryReceiptTestMessage(const JID& from, const std::string& id) {
1603 std::shared_ptr<Message> message = std::make_shared<Message>(); 1682 std::shared_ptr<Message> message = std::make_shared<Message>();
@@ -1664,4 +1743,3 @@ private:
1664}; 1743};
1665 1744
1666CPPUNIT_TEST_SUITE_REGISTRATION(ChatsManagerTest); 1745CPPUNIT_TEST_SUITE_REGISTRATION(ChatsManagerTest);
1667