Test if we can re-open imported KeePass 1 databases.

This commit is contained in:
Felix Geyer 2012-05-10 23:00:29 +02:00
parent 65bdc207b7
commit 3738115b6d
2 changed files with 34 additions and 1 deletions

View File

@ -102,6 +102,8 @@ void TestKeePass1Reader::testBasic()
QCOMPARE(group2->name(), QString("eMail"));
QCOMPARE(group2->entries().size(), 1);
QCOMPARE(group2->iconNumber(), 19);
reopenDatabase(m_db, "masterpw", QString());
}
void TestKeePass1Reader::testMasterKey()
@ -154,6 +156,8 @@ void TestKeePass1Reader::testFileKey()
QCOMPARE(db->rootGroup()->children().size(), 1);
QCOMPARE(db->rootGroup()->children().at(0)->name(), name);
reopenDatabase(db, QString(), keyFilename);
delete db;
}
@ -180,6 +184,8 @@ void TestKeePass1Reader::testCompositeKey()
QCOMPARE(db->rootGroup()->children().size(), 1);
QCOMPARE(db->rootGroup()->children().at(0)->name(), name);
reopenDatabase(db, "mypassword", keyFilename);
delete db;
}
@ -230,4 +236,31 @@ QDateTime TestKeePass1Reader::genDT(int year, int month, int day, int hour, int
return QDateTime(date, time, Qt::UTC);
}
void TestKeePass1Reader::reopenDatabase(Database* db, const QString& password, const QString& keyfileName)
{
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
KeePass2Writer writer;
writer.writeDatabase(&buffer, db);
QVERIFY(!writer.error());
QVERIFY(buffer.seek(0));
CompositeKey key;
if (!password.isNull()) {
key.addKey(PasswordKey(password));
}
if (!keyfileName.isEmpty()) {
FileKey fileKey;
QVERIFY(fileKey.load(keyfileName));
key.addKey(fileKey);
}
KeePass2Reader reader;
Database* newDb = reader.readDatabase(&buffer, key);
QVERIFY(newDb);
QVERIFY(!reader.hasError());
delete newDb;
}
KEEPASSX_QTEST_CORE_MAIN(TestKeePass1Reader)

View File

@ -22,7 +22,6 @@
#include <QtCore/QObject>
class Database;
class QIODevice;
class TestKeePass1Reader : public QObject
{
@ -43,6 +42,7 @@ private Q_SLOTS:
private:
static QDateTime genDT(int year, int month, int day, int hour, int min);
static void reopenDatabase(Database* db, const QString& password, const QString& keyfileName);
Database* m_db;
};