diff --git a/src/jamidht/conversationrepository.cpp b/src/jamidht/conversationrepository.cpp index 5f6aa82c6..66f96ab2f 100644 --- a/src/jamidht/conversationrepository.cpp +++ b/src/jamidht/conversationrepository.cpp @@ -1506,9 +1506,21 @@ ConversationRepository::Impl::checkValidProfileUpdate(const std::string& userDev auto changedFiles = ConversationRepository::changedFiles(diffStats(commitId, parentId)); // Check that no weird file is added nor removed + std::string userDeviceFile = fmt::format("devices/{}.crt", userDevice); for (const auto& f : changedFiles) { if (f == "profile.vcf") { // Ignore + } else if (f == userDeviceFile) { + // In this case, device is added or modified (certificate expiration) + auto oldFile = fileAtTree(f, treeOld); + std::string_view oldCert; + if (oldFile) + oldCert = as_view(oldFile); + auto newFile = fileAtTree(f, treeNew); + if (!verifyCertificate(as_view(newFile), userUri, oldCert)) { + JAMI_ERROR("Invalid certificate {}", f); + return false; + } } else { JAMI_ERROR("Unwanted changed file detected: {}", f); return false; @@ -3844,7 +3856,7 @@ ConversationRepository::updateInfos(const std::map& pr wbuilder["commentStyle"] = "None"; wbuilder["indentation"] = ""; - return pimpl_->commit(Json::writeString(wbuilder, json)); + return commitMessage(Json::writeString(wbuilder, json)); } std::map diff --git a/test/unitTest/conversation/conversation.cpp b/test/unitTest/conversation/conversation.cpp index 2f02b115f..845a0acb2 100644 --- a/test/unitTest/conversation/conversation.cpp +++ b/test/unitTest/conversation/conversation.cpp @@ -158,6 +158,7 @@ private: void testMessageReaction(); void testLoadPartiallyRemovedConversation(); void testReactionsOnEditedMessage(); + void testUpdateProfileMultiDevice(); CPPUNIT_TEST_SUITE(ConversationTest); CPPUNIT_TEST(testCreateConversation); @@ -211,6 +212,7 @@ private: CPPUNIT_TEST(testMessageReaction); CPPUNIT_TEST(testLoadPartiallyRemovedConversation); CPPUNIT_TEST(testReactionsOnEditedMessage); + CPPUNIT_TEST(testUpdateProfileMultiDevice); CPPUNIT_TEST_SUITE_END(); }; @@ -2488,6 +2490,41 @@ ConversationTest::testReactionsOnEditedMessage() CPPUNIT_ASSERT(emojiId == aliceData.messagesUpdated[0].reactions[0]["id"]); } +void +ConversationTest::testUpdateProfileMultiDevice() +{ + std::cout << "\nRunning test: " << __func__ << std::endl; + connectSignals(); + + auto bobAccount = Manager::instance().getAccount(bobId); + + // Bob creates a second device + auto bobArchive = std::filesystem::current_path().string() + "/bob.gz"; + std::remove(bobArchive.c_str()); + bobAccount->exportArchive(bobArchive); + std::map details = libjami::getAccountTemplate("RING"); + details[ConfProperties::TYPE] = "RING"; + details[ConfProperties::DISPLAYNAME] = "BOB2"; + details[ConfProperties::ALIAS] = "BOB2"; + details[ConfProperties::UPNP_ENABLED] = "true"; + details[ConfProperties::ARCHIVE_PASSWORD] = ""; + details[ConfProperties::ARCHIVE_PIN] = ""; + details[ConfProperties::ARCHIVE_PATH] = bobArchive; + bob2Id = Manager::instance().addAccount(details); + CPPUNIT_ASSERT(cv.wait_for(lk, 30s, [&]() { return bob2Data.registered; })); + + // Bob creates a conversation + auto convId = libjami::startConversation(bobId); + CPPUNIT_ASSERT(cv.wait_for(lk, 30s, [&]() { return !bob2Data.conversationId.empty(); })); + + + auto bobMsgSize = bobData.messages.size(); + auto bob2Account = Manager::instance().getAccount(bob2Id); + bob2Account->convModule()->updateConversationInfos(bob2Data.conversationId, {{"title", "My awesome swarm"}}); + CPPUNIT_ASSERT(cv.wait_for(lk, 30s, [&]() { return bobMsgSize + 1 == bobData.messages.size(); })); + +} + } // namespace test } // namespace jami