Add tests for opening KeePass 1 databases with different keyfiles.

This commit is contained in:
Felix Geyer 2012-05-10 19:34:55 +02:00
parent c02b5abc6e
commit 225e5dac66
6 changed files with 60 additions and 0 deletions

View File

@ -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;

View File

@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
tests/data/FileKeyHex.kdb Normal file

Binary file not shown.