conversationrepository: detect malformed conversations

For whatever reason, a conversation can be malformed. This should
be detected and the conversation not loaded. The conversation
will be removed and re-synced if necessary.

Change-Id: I40e78564559e7f09159ceba4d263a4ea75b25794
parent ba3a411c
......@@ -1761,7 +1761,7 @@ ConversationRepository::Impl::initMembers()
{
auto repo = repository();
if (!repo)
return;
throw std::logic_error("Invalid git repository");
std::vector<std::string> uris;
std::lock_guard<std::mutex> lk(membersMtx_);
......@@ -2894,7 +2894,10 @@ ConversationRepository::members() const
void
ConversationRepository::refreshMembers() const
{
return pimpl_->initMembers();
try {
pimpl_->initMembers();
} catch (...) {
}
}
void
......
......@@ -5079,6 +5079,7 @@ JamiAccount::loadConversations()
JAMI_INFO("[Account %s] Start loading conversations…", getAccountID().c_str());
auto conversationsRepositories = fileutils::readDirectory(idPath_ + DIR_SEPARATOR_STR
+ "conversations");
conversations_.clear();
for (const auto& repository : conversationsRepositories) {
try {
auto conv = std::make_shared<Conversation>(weak(), repository);
......
......@@ -152,6 +152,7 @@ private:
void testMemberCannotUpdateProfile();
void testUpdateProfileWithBadFile();
void testFetchProfileUnauthorized();
void testDoNotLoadIncorrectConversation();
CPPUNIT_TEST_SUITE(ConversationTest);
CPPUNIT_TEST(testCreateConversation);
......@@ -206,6 +207,7 @@ private:
CPPUNIT_TEST(testMemberCannotUpdateProfile);
CPPUNIT_TEST(testUpdateProfileWithBadFile);
CPPUNIT_TEST(testFetchProfileUnauthorized);
CPPUNIT_TEST(testDoNotLoadIncorrectConversation);
CPPUNIT_TEST_SUITE_END();
};
......@@ -4321,6 +4323,30 @@ END:VCARD";
DRing::unregisterSignalHandlers();
}
void
ConversationTest::testDoNotLoadIncorrectConversation()
{
auto aliceAccount = Manager::instance().getAccount<JamiAccount>(aliceId);
auto uri = aliceAccount->getUsername();
auto convId = aliceAccount->startConversation();
auto conversations = aliceAccount->getConversations();
CPPUNIT_ASSERT(conversations.size() == 1);
CPPUNIT_ASSERT(conversations.front() == convId);
Manager::instance().sendRegister(aliceId, false);
auto repoGitPath = fileutils::get_data_dir() + DIR_SEPARATOR_STR + aliceAccount->getAccountID()
+ DIR_SEPARATOR_STR + "conversations" + DIR_SEPARATOR_STR + convId
+ DIR_SEPARATOR_STR + ".git";
fileutils::removeAll(repoGitPath, true); // This make the repository not usable
aliceAccount->loadConversations(); // Refresh. This should detect the incorrect conversations.
// the conv should be detected as invalid and not added
conversations = aliceAccount->getConversations();
CPPUNIT_ASSERT(conversations.size() == 0);
}
} // namespace test
} // namespace jami
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment