0
0
mirror of https://github.com/keepassxreboot/keepassxc.git synced 2024-09-20 04:12:15 +02:00

Repair UUID of inconsistent history items.

Closes #130
This commit is contained in:
Florian Geyer 2016-08-03 00:00:56 +02:00
parent cd1192b409
commit 8d16522d39
5 changed files with 53 additions and 1 deletions

View File

@ -372,7 +372,6 @@ const QList<Entry*>& Entry::historyItems() const
void Entry::addHistoryItem(Entry* entry)
{
Q_ASSERT(!entry->parent());
Q_ASSERT(entry->uuid() == uuid());
m_history.append(entry);
Q_EMIT modified();

View File

@ -778,6 +778,13 @@ Entry* KeePass2XmlReader::parseEntry(bool history)
}
Q_FOREACH (Entry* historyItem, historyItems) {
if (historyItem->uuid() != entry->uuid()) {
if (m_strictMode) {
raiseError("History element with different uuid");
} else {
historyItem->setUuid(entry->uuid());
}
}
entry->addHistoryItem(historyItem);
}

View File

@ -407,6 +407,8 @@ void TestKeePass2XmlReader::testBroken_data()
QTest::newRow("BrokenGroupReference (not strict)") << "BrokenGroupReference" << false << false;
QTest::newRow("BrokenDeletedObjects (strict)") << "BrokenDeletedObjects" << true << true;
QTest::newRow("BrokenDeletedObjects (not strict)") << "BrokenDeletedObjects" << false << false;
QTest::newRow("BrokenDifferentEntryHistoryUuid (strict)") << "BrokenDifferentEntryHistoryUuid" << true << true;
QTest::newRow("BrokenDifferentEntryHistoryUuid (not strict)") << "BrokenDifferentEntryHistoryUuid" << false << false;
}
void TestKeePass2XmlReader::testEmptyUuids()
@ -487,6 +489,32 @@ void TestKeePass2XmlReader::testInvalidXmlChars()
QCOMPARE(strToBytes(attrRead->value("SurrogateValid2")), strToBytes(strSurrogateValid2));
}
void TestKeePass2XmlReader::testRepairUuidHistoryItem()
{
KeePass2XmlReader reader;
QString xmlFile = QString("%1/%2.xml").arg(KEEPASSX_TEST_DATA_DIR, "BrokenDifferentEntryHistoryUuid");
QVERIFY(QFile::exists(xmlFile));
QScopedPointer<Database> db(reader.readDatabase(xmlFile));
if (reader.hasError()) {
qWarning("Database read error: %s", qPrintable(reader.errorString()));
}
QVERIFY(!reader.hasError());
QList<Entry*> entries = db.data()->rootGroup()->entries();
QCOMPARE(entries.size(), 1);
Entry* entry = entries.at(0);
QList<Entry*> historyItems = entry->historyItems();
QCOMPARE(historyItems.size(), 1);
Entry* historyItem = historyItems.at(0);
QVERIFY(!entry->uuid().isNull());
QVERIFY(!historyItem->uuid().isNull());
QCOMPARE(historyItem->uuid(), entry->uuid());
}
void TestKeePass2XmlReader::cleanupTestCase()
{
delete m_db;

View File

@ -43,6 +43,7 @@ private Q_SLOTS:
void testBroken_data();
void testEmptyUuids();
void testInvalidXmlChars();
void testRepairUuidHistoryItem();
void cleanupTestCase();
private:

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<KeePassFile>
<Root>
<Group>
<UUID>lmU+9n0aeESKZvcEze+bRg==</UUID>
<Name>Test</Name>
<Entry>
<UUID>MTExMTExMTExMTExMTExMQ==</UUID>
<History>
<Entry>
<UUID>MjIyMjIyMjIyMjIyMjIyMg==</UUID>
</Entry>
</History>
</Entry>
</Group>
</Root>
</KeePassFile>