mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-18 04:04:29 -05:00
Test speedup (#1678)
* Tests: Speed up AutoType testing Decrease default autotype delay to 1 to improve test suite speed by seconds. This shaves multiple seconds off the whole test suite. In some cases, the largest part. Also, initialize config just creating the test instance, just in case that it ever depends on the configuration values at that point already. * Tests: Speed up Kdbx4 testing This speeds up the Kdbx4 tests by using parameters optimized for speed for the key derivation functions. On an i7-6700K the tests run close to 50% faster with this change (about 1.5s vs. 3s).
This commit is contained in:
parent
aa6327716f
commit
46e8e3dbbc
@ -35,8 +35,9 @@ void TestAutoType::initTestCase()
|
|||||||
{
|
{
|
||||||
QVERIFY(Crypto::init());
|
QVERIFY(Crypto::init());
|
||||||
Config::createTempFileInstance();
|
Config::createTempFileInstance();
|
||||||
AutoType::createTestInstance();
|
config()->set("AutoTypeDelay", 1);
|
||||||
config()->set("security/autotypeask", false);
|
config()->set("security/autotypeask", false);
|
||||||
|
AutoType::createTestInstance();
|
||||||
|
|
||||||
QPluginLoader loader(filePath()->pluginPath("keepassx-autotype-test"));
|
QPluginLoader loader(filePath()->pluginPath("keepassx-autotype-test"));
|
||||||
loader.setLoadHints(QLibrary::ResolveAllSymbolsHint);
|
loader.setLoadHints(QLibrary::ResolveAllSymbolsHint);
|
||||||
|
@ -34,8 +34,8 @@ QTEST_GUILESS_MAIN(TestKdbx4)
|
|||||||
|
|
||||||
void TestKdbx4::initTestCaseImpl()
|
void TestKdbx4::initTestCaseImpl()
|
||||||
{
|
{
|
||||||
m_xmlDb->changeKdf(KeePass2::uuidToKdf(KeePass2::KDF_ARGON2));
|
m_xmlDb->changeKdf(fastKdf(KeePass2::uuidToKdf(KeePass2::KDF_ARGON2)));
|
||||||
m_kdbxSourceDb->changeKdf(KeePass2::uuidToKdf(KeePass2::KDF_ARGON2));
|
m_kdbxSourceDb->changeKdf(fastKdf(KeePass2::uuidToKdf(KeePass2::KDF_ARGON2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Database* TestKdbx4::readXml(const QString& path, bool strictMode, bool& hasError, QString& errorString)
|
Database* TestKdbx4::readXml(const QString& path, bool strictMode, bool& hasError, QString& errorString)
|
||||||
@ -93,7 +93,7 @@ void TestKdbx4::readKdbx(const QString& path, CompositeKey const& key, QScopedPo
|
|||||||
void TestKdbx4::writeKdbx(QIODevice* device, Database* db, bool& hasError, QString& errorString)
|
void TestKdbx4::writeKdbx(QIODevice* device, Database* db, bool& hasError, QString& errorString)
|
||||||
{
|
{
|
||||||
if (db->kdf()->uuid() == KeePass2::KDF_AES_KDBX3) {
|
if (db->kdf()->uuid() == KeePass2::KDF_AES_KDBX3) {
|
||||||
db->changeKdf(KeePass2::uuidToKdf(KeePass2::KDF_ARGON2));
|
db->changeKdf(fastKdf(KeePass2::uuidToKdf(KeePass2::KDF_ARGON2)));
|
||||||
}
|
}
|
||||||
KeePass2Writer writer;
|
KeePass2Writer writer;
|
||||||
hasError = writer.writeDatabase(device, db);
|
hasError = writer.writeDatabase(device, db);
|
||||||
@ -137,6 +137,7 @@ void TestKdbx4::testFormat400Upgrade()
|
|||||||
QFETCH(quint32, expectedVersion);
|
QFETCH(quint32, expectedVersion);
|
||||||
|
|
||||||
QScopedPointer<Database> sourceDb(new Database());
|
QScopedPointer<Database> sourceDb(new Database());
|
||||||
|
sourceDb->changeKdf(fastKdf(sourceDb->kdf()));
|
||||||
sourceDb->metadata()->setName("Wubba lubba dub dub");
|
sourceDb->metadata()->setName("Wubba lubba dub dub");
|
||||||
QCOMPARE(sourceDb->kdf()->uuid(), KeePass2::KDF_AES_KDBX3); // default is legacy AES-KDF
|
QCOMPARE(sourceDb->kdf()->uuid(), KeePass2::KDF_AES_KDBX3); // default is legacy AES-KDF
|
||||||
|
|
||||||
@ -148,7 +149,7 @@ void TestKdbx4::testFormat400Upgrade()
|
|||||||
buffer.open(QBuffer::ReadWrite);
|
buffer.open(QBuffer::ReadWrite);
|
||||||
|
|
||||||
// upgrade to KDBX 4 by changing KDF and Cipher
|
// upgrade to KDBX 4 by changing KDF and Cipher
|
||||||
sourceDb->changeKdf(KeePass2::uuidToKdf(kdfUuid));
|
sourceDb->changeKdf(fastKdf(KeePass2::uuidToKdf(kdfUuid)));
|
||||||
sourceDb->setCipher(cipherUuid);
|
sourceDb->setCipher(cipherUuid);
|
||||||
|
|
||||||
// CustomData in meta should not cause any version change
|
// CustomData in meta should not cause any version change
|
||||||
@ -235,6 +236,7 @@ void TestKdbx4::testUpgradeMasterKeyIntegrity()
|
|||||||
compositeKey.addChallengeResponseKey(crKey);
|
compositeKey.addChallengeResponseKey(crKey);
|
||||||
|
|
||||||
QScopedPointer<Database> db(new Database());
|
QScopedPointer<Database> db(new Database());
|
||||||
|
db->changeKdf(fastKdf(db->kdf()));
|
||||||
db->setKey(compositeKey);
|
db->setKey(compositeKey);
|
||||||
|
|
||||||
// upgrade the database by a specific method
|
// upgrade the database by a specific method
|
||||||
@ -243,11 +245,11 @@ void TestKdbx4::testUpgradeMasterKeyIntegrity()
|
|||||||
} else if (upgradeAction == "meta-customdata") {
|
} else if (upgradeAction == "meta-customdata") {
|
||||||
db->metadata()->customData()->set("abc", "def");
|
db->metadata()->customData()->set("abc", "def");
|
||||||
} else if (upgradeAction == "kdf-aes-kdbx3") {
|
} else if (upgradeAction == "kdf-aes-kdbx3") {
|
||||||
db->changeKdf(KeePass2::uuidToKdf(KeePass2::KDF_AES_KDBX3));
|
db->changeKdf(fastKdf(KeePass2::uuidToKdf(KeePass2::KDF_AES_KDBX3)));
|
||||||
} else if (upgradeAction == "kdf-argon2") {
|
} else if (upgradeAction == "kdf-argon2") {
|
||||||
db->changeKdf(KeePass2::uuidToKdf(KeePass2::KDF_ARGON2));
|
db->changeKdf(fastKdf(KeePass2::uuidToKdf(KeePass2::KDF_ARGON2)));
|
||||||
} else if (upgradeAction == "kdf-aes-kdbx4") {
|
} else if (upgradeAction == "kdf-aes-kdbx4") {
|
||||||
db->changeKdf(KeePass2::uuidToKdf(KeePass2::KDF_AES_KDBX4));
|
db->changeKdf(fastKdf(KeePass2::uuidToKdf(KeePass2::KDF_AES_KDBX4)));
|
||||||
} else if (upgradeAction == "public-customdata") {
|
} else if (upgradeAction == "public-customdata") {
|
||||||
db->publicCustomData().insert("abc", "def");
|
db->publicCustomData().insert("abc", "def");
|
||||||
} else if (upgradeAction == "rootgroup-customdata") {
|
} else if (upgradeAction == "rootgroup-customdata") {
|
||||||
@ -403,3 +405,17 @@ void TestKdbx4::testCustomData()
|
|||||||
QCOMPARE(newEntry->customData()->value(customDataKey1), customData1);
|
QCOMPARE(newEntry->customData()->value(customDataKey1), customData1);
|
||||||
QCOMPARE(newEntry->customData()->value(customDataKey2), customData2);
|
QCOMPARE(newEntry->customData()->value(customDataKey2), customData2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSharedPointer<Kdf> TestKdbx4::fastKdf(QSharedPointer<Kdf> kdf)
|
||||||
|
{
|
||||||
|
kdf->setRounds(1);
|
||||||
|
|
||||||
|
if (kdf->uuid() == KeePass2::KDF_ARGON2) {
|
||||||
|
kdf->processParameters({
|
||||||
|
{KeePass2::KDFPARAM_ARGON2_MEMORY, 1024},
|
||||||
|
{KeePass2::KDFPARAM_ARGON2_PARALLELISM, 1}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return kdf;
|
||||||
|
}
|
||||||
|
@ -44,6 +44,8 @@ protected:
|
|||||||
void readKdbx(QIODevice* device, CompositeKey const& key, QScopedPointer<Database>& db,
|
void readKdbx(QIODevice* device, CompositeKey const& key, QScopedPointer<Database>& db,
|
||||||
bool& hasError, QString& errorString) override;
|
bool& hasError, QString& errorString) override;
|
||||||
void writeKdbx(QIODevice* device, Database* db, bool& hasError, QString& errorString) override;
|
void writeKdbx(QIODevice* device, Database* db, bool& hasError, QString& errorString) override;
|
||||||
|
|
||||||
|
QSharedPointer<Kdf> fastKdf(QSharedPointer<Kdf> kdf);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSXC_TEST_KDBX4_H
|
#endif // KEEPASSXC_TEST_KDBX4_H
|
||||||
|
Loading…
Reference in New Issue
Block a user