@@ -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);
|
||||
|
||||
@@ -27,6 +27,10 @@ class TestKeys : public QObject
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void testComposite();
|
||||
void testFileKey();
|
||||
void testFileKey_data();
|
||||
void testCreateFileKey();
|
||||
void testFileKeyError();
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_TESTKEYS_H
|
||||
|
||||
BIN
tests/data/FileKeyBinary.kdbx
Normal file
BIN
tests/data/FileKeyBinary.kdbx
Normal file
Binary file not shown.
1
tests/data/FileKeyBinary.key
Normal file
1
tests/data/FileKeyBinary.key
Normal file
@@ -0,0 +1 @@
|
||||
!"#$%&'()012
|
||||
BIN
tests/data/FileKeyHashed.kdbx
Normal file
BIN
tests/data/FileKeyHashed.kdbx
Normal file
Binary file not shown.
BIN
tests/data/FileKeyHashed.key
Normal file
BIN
tests/data/FileKeyHashed.key
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
BIN
tests/data/FileKeyHex.kdbx
Normal file
BIN
tests/data/FileKeyHex.kdbx
Normal file
Binary file not shown.
1
tests/data/FileKeyHex.key
Normal file
1
tests/data/FileKeyHex.key
Normal file
@@ -0,0 +1 @@
|
||||
0123456789abcdeffedcba98765432100123456789abcdeffedcba9876543210
|
||||
BIN
tests/data/FileKeyXml.kdbx
Normal file
BIN
tests/data/FileKeyXml.kdbx
Normal file
Binary file not shown.
9
tests/data/FileKeyXml.key
Normal file
9
tests/data/FileKeyXml.key
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<KeyFile>
|
||||
<Meta>
|
||||
<Version>1.00</Version>
|
||||
</Meta>
|
||||
<Key>
|
||||
<Data>nhNal+U9p6h1rWAAJ5YrNkMazMTZkIWLi3WC4JQv5jk=</Data>
|
||||
</Key>
|
||||
</KeyFile>
|
||||
Reference in New Issue
Block a user