mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-10-11 04:58:31 -04:00
parent
cd919949fd
commit
f215ffa3fa
13 changed files with 435 additions and 0 deletions
|
@ -17,10 +17,17 @@
|
|||
|
||||
#include "TestKeys.h"
|
||||
|
||||
#include <QtCore/QBuffer>
|
||||
#include <QtTest/QTest>
|
||||
|
||||
#include "config-keepassx-tests.h"
|
||||
#include "core/Database.h"
|
||||
#include "core/Metadata.h"
|
||||
#include "crypto/Crypto.h"
|
||||
#include "format/KeePass2Reader.h"
|
||||
#include "format/KeePass2Writer.h"
|
||||
#include "keys/CompositeKey.h"
|
||||
#include "keys/FileKey.h"
|
||||
#include "keys/PasswordKey.h"
|
||||
|
||||
void TestKeys::initTestCase()
|
||||
|
@ -50,4 +57,91 @@ void TestKeys::testComposite()
|
|||
delete compositeKey2;
|
||||
}
|
||||
|
||||
void TestKeys::testFileKey()
|
||||
{
|
||||
QFETCH(QString, type);
|
||||
|
||||
QString name = QString("FileKey").append(type);
|
||||
|
||||
KeePass2Reader reader;
|
||||
|
||||
QString dbFilename = QString("%1/%2.kdbx").arg(QString(KEEPASSX_TEST_DATA_DIR), name);
|
||||
QString keyFilename = QString("%1/%2.key").arg(QString(KEEPASSX_TEST_DATA_DIR), name);
|
||||
|
||||
CompositeKey compositeKey;
|
||||
FileKey fileKey;
|
||||
QVERIFY(fileKey.load(keyFilename));
|
||||
QCOMPARE(fileKey.rawKey().size(), 32);
|
||||
compositeKey.addKey(fileKey);
|
||||
|
||||
Database* db = reader.readDatabase(dbFilename, compositeKey);
|
||||
QVERIFY(db);
|
||||
QVERIFY(!reader.error());
|
||||
QCOMPARE(db->metadata()->name(), QString("%1 Database").arg(name));
|
||||
|
||||
delete db;
|
||||
}
|
||||
|
||||
void TestKeys::testFileKey_data()
|
||||
{
|
||||
QTest::addColumn<QString>("type");
|
||||
QTest::newRow("Xml") << QString("Xml");
|
||||
QTest::newRow("Binary") << QString("Binary");
|
||||
QTest::newRow("Hex") << QString("Hex");
|
||||
QTest::newRow("Hashed") << QString("Hashed");
|
||||
}
|
||||
|
||||
void TestKeys::testCreateFileKey()
|
||||
{
|
||||
const QString dbName("testCreateFileKey database");
|
||||
|
||||
QBuffer keyBuffer;
|
||||
keyBuffer.open(QBuffer::ReadWrite);
|
||||
|
||||
FileKey::create(&keyBuffer);
|
||||
keyBuffer.reset();
|
||||
|
||||
FileKey fileKey;
|
||||
QVERIFY(fileKey.load(&keyBuffer));
|
||||
CompositeKey compositeKey;
|
||||
compositeKey.addKey(fileKey);
|
||||
|
||||
Database* dbOrg = new Database();
|
||||
dbOrg->setKey(compositeKey);
|
||||
dbOrg->metadata()->setName(dbName);
|
||||
|
||||
QBuffer dbBuffer;
|
||||
dbBuffer.open(QBuffer::ReadWrite);
|
||||
|
||||
KeePass2Writer writer;
|
||||
writer.writeDatabase(&dbBuffer, dbOrg);
|
||||
dbBuffer.reset();
|
||||
delete dbOrg;
|
||||
|
||||
KeePass2Reader reader;
|
||||
Database* dbRead = reader.readDatabase(&dbBuffer, compositeKey);
|
||||
QVERIFY(dbRead);
|
||||
QVERIFY(!reader.error());
|
||||
QCOMPARE(dbRead->metadata()->name(), dbName);
|
||||
delete dbRead;
|
||||
}
|
||||
|
||||
void TestKeys::testFileKeyError()
|
||||
{
|
||||
bool result;
|
||||
QString errorMsg;
|
||||
const QString fileName(QString(KEEPASSX_TEST_DATA_DIR).append("/does/not/exist"));
|
||||
|
||||
FileKey fileKey;
|
||||
result = fileKey.load(fileName, &errorMsg);
|
||||
QVERIFY(!result);
|
||||
QVERIFY(!errorMsg.isEmpty());
|
||||
errorMsg = "";
|
||||
|
||||
result = FileKey::create(fileName, &errorMsg);
|
||||
QVERIFY(!result);
|
||||
QVERIFY(!errorMsg.isEmpty());
|
||||
errorMsg = "";
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestKeys);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue