diff --git a/tests/TestKeePass1Reader.cpp b/tests/TestKeePass1Reader.cpp index eff5093fc..cb0332fb8 100644 --- a/tests/TestKeePass1Reader.cpp +++ b/tests/TestKeePass1Reader.cpp @@ -17,6 +17,7 @@ #include "TestKeePass1Reader.h" +#include #include #include "config-keepassx-tests.h" @@ -122,6 +123,62 @@ void TestKeePass1Reader::testGroupExpanded() false); } +void TestKeePass1Reader::testFileKey() +{ + QFETCH(QString, type); + + QString name = QString("FileKey").append(type); + + KeePass1Reader reader; + + QString dbFilename = QString("%1/%2.kdb").arg(QString(KEEPASSX_TEST_DATA_DIR), name); + QString keyFilename = QString("%1/%2.key").arg(QString(KEEPASSX_TEST_DATA_DIR), name); + + QFile file(keyFilename); + QVERIFY(file.open(QIODevice::ReadOnly)); + QByteArray keyData = KeePass1Reader::readKeyfile(&file); + QVERIFY(!keyData.isEmpty()); + + Database* db = reader.readDatabase(dbFilename, QString(), keyData); + QVERIFY(db); + QVERIFY(!reader.hasError()); + QCOMPARE(db->rootGroup()->children().size(), 1); + QCOMPARE(db->rootGroup()->children().at(0)->name(), name); + + delete db; +} + +void TestKeePass1Reader::testFileKey_data() +{ + QTest::addColumn("type"); + QTest::newRow("Binary") << QString("Binary"); + QTest::newRow("Hex") << QString("Hex"); + QTest::newRow("Hashed") << QString("Hashed"); +} + +void TestKeePass1Reader::testCompositeKey() +{ + QString name = "CompositeKey"; + + KeePass1Reader reader; + + QString dbFilename = QString("%1/%2.kdb").arg(QString(KEEPASSX_TEST_DATA_DIR), name); + QString keyFilename = QString("%1/FileKeyHex.key").arg(QString(KEEPASSX_TEST_DATA_DIR)); + + QFile file(keyFilename); + QVERIFY(file.open(QIODevice::ReadOnly)); + QByteArray keyData = KeePass1Reader::readKeyfile(&file); + QVERIFY(!keyData.isEmpty()); + + Database* db = reader.readDatabase(dbFilename, "mypassword", keyData); + QVERIFY(db); + QVERIFY(!reader.hasError()); + QCOMPARE(db->rootGroup()->children().size(), 1); + QCOMPARE(db->rootGroup()->children().at(0)->name(), name); + + delete db; +} + void TestKeePass1Reader::cleanupTestCase() { delete m_db; diff --git a/tests/TestKeePass1Reader.h b/tests/TestKeePass1Reader.h index 194167687..8a8da4e0f 100644 --- a/tests/TestKeePass1Reader.h +++ b/tests/TestKeePass1Reader.h @@ -32,6 +32,9 @@ private Q_SLOTS: void testBasic(); void testCustomIcons(); void testGroupExpanded(); + void testFileKey(); + void testFileKey_data(); + void testCompositeKey(); void cleanupTestCase(); private: diff --git a/tests/data/CompositeKey.kdb b/tests/data/CompositeKey.kdb new file mode 100644 index 000000000..70060d8f2 Binary files /dev/null and b/tests/data/CompositeKey.kdb differ diff --git a/tests/data/FileKeyBinary.kdb b/tests/data/FileKeyBinary.kdb new file mode 100644 index 000000000..0ce9f58b7 Binary files /dev/null and b/tests/data/FileKeyBinary.kdb differ diff --git a/tests/data/FileKeyHashed.kdb b/tests/data/FileKeyHashed.kdb new file mode 100644 index 000000000..8ef734720 Binary files /dev/null and b/tests/data/FileKeyHashed.kdb differ diff --git a/tests/data/FileKeyHex.kdb b/tests/data/FileKeyHex.kdb new file mode 100644 index 000000000..ed872c586 Binary files /dev/null and b/tests/data/FileKeyHex.kdb differ