conversationrepository: add user device on profile update

If the first interaction from a device in a conversation is a
profile update, the certificate was not added correctly causing
the conversation to be illformed

GitLab: #946
Change-Id: I07f1735639c2dbf89ba2b2e6b7d9c3f57e5823e4
This commit is contained in:
Sébastien Blin
2024-01-19 10:32:25 -05:00
committed by Adrien Béraud
parent 321b485da8
commit b122e248f3
2 changed files with 50 additions and 1 deletions

View File

@ -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<std::string, std::string>& pr
wbuilder["commentStyle"] = "None";
wbuilder["indentation"] = "";
return pimpl_->commit(Json::writeString(wbuilder, json));
return commitMessage(Json::writeString(wbuilder, json));
}
std::map<std::string, std::string>

View File

@ -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<JamiAccount>(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<std::string, std::string> 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<JamiAccount>(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