mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-24 14:59:44 -05:00
Add tests for opening KeePass 1 databases with different keyfiles.
This commit is contained in:
parent
c02b5abc6e
commit
225e5dac66
@ -17,6 +17,7 @@
|
||||
|
||||
#include "TestKeePass1Reader.h"
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtTest/QTest>
|
||||
|
||||
#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<QString>("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;
|
||||
|
@ -32,6 +32,9 @@ private Q_SLOTS:
|
||||
void testBasic();
|
||||
void testCustomIcons();
|
||||
void testGroupExpanded();
|
||||
void testFileKey();
|
||||
void testFileKey_data();
|
||||
void testCompositeKey();
|
||||
void cleanupTestCase();
|
||||
|
||||
private:
|
||||
|
BIN
tests/data/CompositeKey.kdb
Normal file
BIN
tests/data/CompositeKey.kdb
Normal file
Binary file not shown.
BIN
tests/data/FileKeyBinary.kdb
Normal file
BIN
tests/data/FileKeyBinary.kdb
Normal file
Binary file not shown.
BIN
tests/data/FileKeyHashed.kdb
Normal file
BIN
tests/data/FileKeyHashed.kdb
Normal file
Binary file not shown.
BIN
tests/data/FileKeyHex.kdb
Normal file
BIN
tests/data/FileKeyHex.kdb
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user