diff --git a/src/jamidht/conversationrepository.cpp b/src/jamidht/conversationrepository.cpp index 899d574cd88fa91059219c7f6637720c54be6973..1cfe6dca9abbb0afbbd2b20b4b4edb5f747dad91 100644 --- a/src/jamidht/conversationrepository.cpp +++ b/src/jamidht/conversationrepository.cpp @@ -145,7 +145,7 @@ public: void addUserDevice(); // Verify that the device in the repository is still valid bool validateDevice(); - std::string commit(const std::string& msg); + std::string commit(const std::string& msg, bool verifyDevice = true); ConversationMode mode() const; // NOTE! GitDiff needs to be deteleted before repo @@ -1639,9 +1639,9 @@ ConversationRepository::Impl::validateDevice() auto memberPath = fmt::format("members/{}.crt", account->getUsername()); std::string parentPath = git_repository_workdir(repo.get()); std::string relativeParentPath; - if (fileutils::isFile(git_repository_workdir(repo.get()) + adminPath)) + if (fileutils::isFile(parentPath + adminPath)) relativeParentPath = adminPath; - else if (fileutils::isFile(git_repository_workdir(repo.get()) + memberPath)) + else if (fileutils::isFile(parentPath + memberPath)) relativeParentPath = memberPath; parentPath += relativeParentPath; if (relativeParentPath.empty()) { @@ -1673,9 +1673,9 @@ ConversationRepository::Impl::validateDevice() } std::string -ConversationRepository::Impl::commit(const std::string& msg) +ConversationRepository::Impl::commit(const std::string& msg, bool verifyDevice) { - if (!validateDevice()) + if (verifyDevice && !validateDevice()) return {}; auto account = account_.lock(); auto name = getDisplayName(); @@ -3027,10 +3027,10 @@ ConversationRepository::Impl::addUserDevice() } std::string -ConversationRepository::commitMessage(const std::string& msg) +ConversationRepository::commitMessage(const std::string& msg, bool verifyDevice) { pimpl_->addUserDevice(); - return pimpl_->commit(msg); + return pimpl_->commit(msg, verifyDevice); } std::vector<std::string> @@ -3350,7 +3350,7 @@ ConversationRepository::leave() }); } - return commitMessage(Json::writeString(wbuilder, json)); + return pimpl_->commit(Json::writeString(wbuilder, json), false); } void diff --git a/src/jamidht/conversationrepository.h b/src/jamidht/conversationrepository.h index d49777711098eefeb98fd1587ca4c151d06cb728..b90b184cbd29527280986b79a416c278dccff8f2 100644 --- a/src/jamidht/conversationrepository.h +++ b/src/jamidht/conversationrepository.h @@ -198,10 +198,11 @@ public: /** * Add a new commit to the conversation - * @param msg The commit message of the commit + * @param msg The commit message of the commit + * @param verifyDevice If we need to validate that certificates are correct (used for testing) * @return <empty> on failure, else the message id */ - std::string commitMessage(const std::string& msg); + std::string commitMessage(const std::string& msg, bool verifyDevice = true); std::vector<std::string> commitMessages(const std::vector<std::string>& msgs); diff --git a/test/unitTest/conversation/conversationMembersEvent.cpp b/test/unitTest/conversation/conversationMembersEvent.cpp index 418a864042bd554ba2acfa52c2b9a61207b6fa1a..1718765b1bce481177bdc8fa5966695f00784306 100644 --- a/test/unitTest/conversation/conversationMembersEvent.cpp +++ b/test/unitTest/conversation/conversationMembersEvent.cpp @@ -156,7 +156,6 @@ ConversationMembersEventTest::tearDown() { auto bobArchive = std::filesystem::current_path().string() + "/bob.gz"; std::remove(bobArchive.c_str()); - if (bob2Id.empty()) { wait_for_removal_of({aliceId, bobId, carlaId}); } else { @@ -1588,6 +1587,25 @@ ConversationMembersEventTest::testMemberJoinsNoBadFile() // Accept for alice and makes different heads addFile(carlaAccount, convId, "BADFILE"); + // add /members + /devices + auto cert = carlaAccount->identity().second; + auto parentCert = cert->issuer; + auto uri = parentCert->getId().toString(); + std::string membersPath = fmt::format("{}/{}/members/", repoPathCarla, convId); + std::string devicesPath = fmt::format("{}/{}/devices/", repoPathCarla, convId); + std::string memberFile = fmt::format("{}{}.crt", membersPath, carlaUri); + // Add members/uri.crt + fileutils::recursive_mkdir(membersPath, 0700); + fileutils::recursive_mkdir(devicesPath, 0700); + auto file = fileutils::ofstream(memberFile, std::ios::trunc | std::ios::binary); + file << parentCert->toString(true); + file.close(); + std::string invitedPath = fmt::format("{}/{}/invited/{}", repoPathCarla, convId, carlaUri); + fileutils::remove(invitedPath); + std::string devicePath = fmt::format("{}{}.crt", devicesPath, carlaAccount->currentDeviceId()); + file = fileutils::ofstream(devicePath, std::ios::trunc | std::ios::binary); + file << cert->toString(false); + addAll(carlaAccount, convId); ConversationRepository repo(carlaAccount, convId); // Start Carla, should merge and all messages should be there @@ -1684,7 +1702,7 @@ ConversationMembersEventTest::testMemberAddedNoCertificate() wbuilder["commentStyle"] = "None"; wbuilder["indentation"] = ""; ConversationRepository cr(carlaAccount->weak(), convId); - cr.commitMessage(Json::writeString(wbuilder, json)); + cr.commitMessage(Json::writeString(wbuilder, json), false); // Start Carla, should merge and all messages should be there carlaAccount->convModule()->loadConversations(); // Because of the copy @@ -1768,18 +1786,22 @@ ConversationMembersEventTest::testMemberJoinsInviteRemoved() std::remove(ciPathCarla.c_str()); std::filesystem::copy(ciPathAlice, ciPathCarla); - // Let invited, but add /members + /devices + // add /members + /devices auto cert = carlaAccount->identity().second; auto parentCert = cert->issuer; auto uri = parentCert->getId().toString(); - std::string membersPath = repoPathCarla + "members" + DIR_SEPARATOR_STR; - std::string memberFile = membersPath + DIR_SEPARATOR_STR + carlaUri + ".crt"; + std::string membersPath = fmt::format("{}/{}/members/", repoPathCarla, convId); + std::string devicesPath = fmt::format("{}/{}/devices/", repoPathCarla, convId); + std::string memberFile = fmt::format("{}{}.crt", membersPath, carlaUri); // Add members/uri.crt fileutils::recursive_mkdir(membersPath, 0700); + fileutils::recursive_mkdir(devicesPath, 0700); auto file = fileutils::ofstream(memberFile, std::ios::trunc | std::ios::binary); file << parentCert->toString(true); file.close(); - + std::string devicePath = fmt::format("{}{}.crt", devicesPath, carlaAccount->currentDeviceId()); + file = fileutils::ofstream(devicePath, std::ios::trunc | std::ios::binary); + file << cert->toString(false); addAll(carlaAccount, convId); Json::Value json; json["action"] = "join"; diff --git a/test/unitTest/conversation/conversationcommon.cpp b/test/unitTest/conversation/conversationcommon.cpp index 035500d1260ef3aa07b5b9f2ba3cfd1fb268cfcb..01e019be5c8c65f5d262c5b12415b79d37bb3f16 100644 --- a/test/unitTest/conversation/conversationcommon.cpp +++ b/test/unitTest/conversation/conversationcommon.cpp @@ -72,7 +72,7 @@ addVote(std::shared_ptr<JamiAccount> account, wbuilder["commentStyle"] = "None"; wbuilder["indentation"] = ""; ConversationRepository cr(account->weak(), convId); - cr.commitMessage(Json::writeString(wbuilder, json)); + cr.commitMessage(Json::writeString(wbuilder, json), false); } void