|
|
|
|
@@ -37,7 +37,9 @@ int main(int argc, char* argv[])
|
|
|
|
|
|
|
|
|
|
TestKdbx4Argon2 argon2Test;
|
|
|
|
|
TestKdbx4AesKdf aesKdfTest;
|
|
|
|
|
return QTest::qExec(&argon2Test, argc, argv) | QTest::qExec(&aesKdfTest, argc, argv);
|
|
|
|
|
TestKdbx4Format kdbx4Test;
|
|
|
|
|
return QTest::qExec(&argon2Test, argc, argv) || QTest::qExec(&aesKdfTest, argc, argv)
|
|
|
|
|
|| QTest::qExec(&kdbx4Test, argc, argv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestKdbx4Argon2::initTestCaseImpl()
|
|
|
|
|
@@ -119,8 +121,14 @@ void TestKdbx4Argon2::writeKdbx(QIODevice* device, Database* db, bool& hasError,
|
|
|
|
|
QCOMPARE(writer.version(), KeePass2::FILE_VERSION_4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestKdbx4AesKdf::initTestCaseImpl()
|
|
|
|
|
{
|
|
|
|
|
m_xmlDb->changeKdf(fastKdf(KeePass2::uuidToKdf(KeePass2::KDF_AES_KDBX4)));
|
|
|
|
|
m_kdbxSourceDb->changeKdf(fastKdf(KeePass2::uuidToKdf(KeePass2::KDF_AES_KDBX4)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(QUuid)
|
|
|
|
|
void TestKdbx4Argon2::testFormat400()
|
|
|
|
|
void TestKdbx4Format::testFormat400()
|
|
|
|
|
{
|
|
|
|
|
QString filename = QString(KEEPASSX_TEST_DATA_DIR).append("/Format400.kdbx");
|
|
|
|
|
auto key = QSharedPointer<CompositeKey>::create();
|
|
|
|
|
@@ -145,7 +153,7 @@ void TestKdbx4Argon2::testFormat400()
|
|
|
|
|
QCOMPARE(entry->attachments()->value("Format400"), QByteArray("Format400\n"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestKdbx4Argon2::testFormat400Upgrade()
|
|
|
|
|
void TestKdbx4Format::testFormat400Upgrade()
|
|
|
|
|
{
|
|
|
|
|
QFETCH(QUuid, kdfUuid);
|
|
|
|
|
QFETCH(QUuid, cipherUuid);
|
|
|
|
|
@@ -203,7 +211,7 @@ void TestKdbx4Argon2::testFormat400Upgrade()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
|
void TestKdbx4Argon2::testFormat400Upgrade_data()
|
|
|
|
|
void TestKdbx4Format::testFormat400Upgrade_data()
|
|
|
|
|
{
|
|
|
|
|
QTest::addColumn<QUuid>("kdfUuid");
|
|
|
|
|
QTest::addColumn<QUuid>("cipherUuid");
|
|
|
|
|
@@ -242,7 +250,68 @@ void TestKdbx4Argon2::testFormat400Upgrade_data()
|
|
|
|
|
}
|
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
|
|
void TestKdbx4Argon2::testUpgradeMasterKeyIntegrity()
|
|
|
|
|
void TestKdbx4Format::testFormat410Upgrade()
|
|
|
|
|
{
|
|
|
|
|
Database db;
|
|
|
|
|
db.changeKdf(fastKdf(db.kdf()));
|
|
|
|
|
QCOMPARE(db.kdf()->uuid(), KeePass2::KDF_AES_KDBX3);
|
|
|
|
|
QVERIFY(!KeePass2Writer::implicitKDBXUpgradeNeeded(&db));
|
|
|
|
|
|
|
|
|
|
auto group1 = new Group();
|
|
|
|
|
group1->setUuid(QUuid::createUuid());
|
|
|
|
|
group1->setParent(db.rootGroup());
|
|
|
|
|
|
|
|
|
|
auto group2 = new Group();
|
|
|
|
|
group2->setUuid(QUuid::createUuid());
|
|
|
|
|
group2->setParent(db.rootGroup());
|
|
|
|
|
|
|
|
|
|
auto entry = new Entry();
|
|
|
|
|
entry->setUuid(QUuid::createUuid());
|
|
|
|
|
entry->setGroup(group1);
|
|
|
|
|
|
|
|
|
|
// Groups with tags
|
|
|
|
|
group1->setTags("tag");
|
|
|
|
|
QVERIFY(KeePass2Writer::implicitKDBXUpgradeNeeded(&db));
|
|
|
|
|
group1->setTags("");
|
|
|
|
|
QVERIFY(!KeePass2Writer::implicitKDBXUpgradeNeeded(&db));
|
|
|
|
|
|
|
|
|
|
// PasswordQuality flag set
|
|
|
|
|
entry->setExcludeFromReports(true);
|
|
|
|
|
QVERIFY(KeePass2Writer::implicitKDBXUpgradeNeeded(&db));
|
|
|
|
|
entry->setExcludeFromReports(false);
|
|
|
|
|
QVERIFY(!KeePass2Writer::implicitKDBXUpgradeNeeded(&db));
|
|
|
|
|
|
|
|
|
|
// Previous parent group set on group
|
|
|
|
|
group1->setPreviousParentGroup(group2);
|
|
|
|
|
QCOMPARE(group1->previousParentGroup(), group2);
|
|
|
|
|
QVERIFY(KeePass2Writer::implicitKDBXUpgradeNeeded(&db));
|
|
|
|
|
group1->setPreviousParentGroup(nullptr);
|
|
|
|
|
QVERIFY(!KeePass2Writer::implicitKDBXUpgradeNeeded(&db));
|
|
|
|
|
|
|
|
|
|
// Previous parent group set on entry
|
|
|
|
|
entry->setPreviousParentGroup(group2);
|
|
|
|
|
QCOMPARE(entry->previousParentGroup(), group2);
|
|
|
|
|
QVERIFY(KeePass2Writer::implicitKDBXUpgradeNeeded(&db));
|
|
|
|
|
entry->setPreviousParentGroup(nullptr);
|
|
|
|
|
QVERIFY(!KeePass2Writer::implicitKDBXUpgradeNeeded(&db));
|
|
|
|
|
|
|
|
|
|
// Custom icons with name or modification date
|
|
|
|
|
Metadata::CustomIconData customIcon;
|
|
|
|
|
auto iconUuid = QUuid::createUuid();
|
|
|
|
|
db.metadata()->addCustomIcon(iconUuid, customIcon);
|
|
|
|
|
QVERIFY(!KeePass2Writer::implicitKDBXUpgradeNeeded(&db));
|
|
|
|
|
customIcon.name = "abc";
|
|
|
|
|
db.metadata()->removeCustomIcon(iconUuid);
|
|
|
|
|
db.metadata()->addCustomIcon(iconUuid, customIcon);
|
|
|
|
|
QVERIFY(KeePass2Writer::implicitKDBXUpgradeNeeded(&db));
|
|
|
|
|
customIcon.name.clear();
|
|
|
|
|
customIcon.lastModified = Clock::currentDateTimeUtc();
|
|
|
|
|
db.metadata()->removeCustomIcon(iconUuid);
|
|
|
|
|
db.metadata()->addCustomIcon(iconUuid, customIcon);
|
|
|
|
|
QVERIFY(KeePass2Writer::implicitKDBXUpgradeNeeded(&db));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestKdbx4Format::testUpgradeMasterKeyIntegrity()
|
|
|
|
|
{
|
|
|
|
|
QFETCH(QString, upgradeAction);
|
|
|
|
|
QFETCH(quint32, expectedVersion);
|
|
|
|
|
@@ -331,7 +400,7 @@ void TestKdbx4Argon2::testUpgradeMasterKeyIntegrity()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestKdbx4Argon2::testUpgradeMasterKeyIntegrity_data()
|
|
|
|
|
void TestKdbx4Format::testUpgradeMasterKeyIntegrity_data()
|
|
|
|
|
{
|
|
|
|
|
QTest::addColumn<QString>("upgradeAction");
|
|
|
|
|
QTest::addColumn<quint32>("expectedVersion");
|
|
|
|
|
@@ -350,7 +419,7 @@ void TestKdbx4Argon2::testUpgradeMasterKeyIntegrity_data()
|
|
|
|
|
QTest::newRow("Upgrade (implicit): entry-customdata") << QString("entry-customdata") << KeePass2::FILE_VERSION_4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestKdbx4Argon2::testCustomData()
|
|
|
|
|
void TestKdbx4Format::testCustomData()
|
|
|
|
|
{
|
|
|
|
|
Database db;
|
|
|
|
|
|
|
|
|
|
@@ -443,9 +512,3 @@ void TestKdbx4Argon2::testCustomData()
|
|
|
|
|
QCOMPARE(newEntry->customData()->value(customDataKey1), customData1);
|
|
|
|
|
QCOMPARE(newEntry->customData()->value(customDataKey2), customData2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestKdbx4AesKdf::initTestCaseImpl()
|
|
|
|
|
{
|
|
|
|
|
m_xmlDb->changeKdf(fastKdf(KeePass2::uuidToKdf(KeePass2::KDF_AES_KDBX4)));
|
|
|
|
|
m_kdbxSourceDb->changeKdf(fastKdf(KeePass2::uuidToKdf(KeePass2::KDF_AES_KDBX4)));
|
|
|
|
|
}
|
|
|
|
|
|