mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-23 13:11:12 -05:00
Make GUI tests more robust for CI
This commit is contained in:
parent
287e822e02
commit
689a85a071
@ -76,6 +76,14 @@
|
||||
#include "keys/FileKey.h"
|
||||
#include "keys/PasswordKey.h"
|
||||
|
||||
#define TEST_MODAL_NO_WAIT(TEST_CODE) \
|
||||
bool dialogFinished = false; \
|
||||
QTimer::singleShot(0, [&]() { TEST_CODE dialogFinished = true; })
|
||||
|
||||
#define TEST_MODAL(TEST_CODE) \
|
||||
TEST_MODAL_NO_WAIT(TEST_CODE); \
|
||||
QTRY_VERIFY(dialogFinished)
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
||||
@ -195,38 +203,8 @@ void TestGui::testSettingsDefaultTabOrder()
|
||||
|
||||
void TestGui::testCreateDatabase()
|
||||
{
|
||||
QTimer::singleShot(50, this, SLOT(createDatabaseCallback()));
|
||||
triggerAction("actionDatabaseNew");
|
||||
|
||||
// there is a new empty db
|
||||
m_db = m_tabWidget->currentDatabaseWidget()->database();
|
||||
QCOMPARE(m_db->rootGroup()->children().size(), 0);
|
||||
|
||||
// check meta data
|
||||
QCOMPARE(m_db->metadata()->name(), QString("Test Name"));
|
||||
QCOMPARE(m_db->metadata()->description(), QString("Test Description"));
|
||||
|
||||
// check key and encryption
|
||||
QCOMPARE(m_db->key()->keys().size(), 2);
|
||||
QCOMPARE(m_db->kdf()->rounds(), 2);
|
||||
QCOMPARE(m_db->kdf()->uuid(), KeePass2::KDF_ARGON2);
|
||||
QCOMPARE(m_db->cipher(), KeePass2::CIPHER_AES256);
|
||||
auto compositeKey = QSharedPointer<CompositeKey>::create();
|
||||
compositeKey->addKey(QSharedPointer<PasswordKey>::create("test"));
|
||||
auto fileKey = QSharedPointer<FileKey>::create();
|
||||
fileKey->load(QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key"));
|
||||
compositeKey->addKey(fileKey);
|
||||
QCOMPARE(m_db->key()->rawKey(), compositeKey->rawKey());
|
||||
|
||||
// close the new database
|
||||
MessageBox::setNextAnswer(MessageBox::No);
|
||||
triggerAction("actionDatabaseClose");
|
||||
}
|
||||
|
||||
void TestGui::createDatabaseCallback()
|
||||
{
|
||||
auto* wizard = m_tabWidget->findChild<NewDatabaseWizard*>();
|
||||
QVERIFY(wizard);
|
||||
TEST_MODAL_NO_WAIT(
|
||||
NewDatabaseWizard * wizard; QTRY_VERIFY(wizard = m_tabWidget->findChild<NewDatabaseWizard*>());
|
||||
|
||||
QTest::keyClicks(wizard->currentPage()->findChild<QLineEdit*>("databaseName"), "Test Name");
|
||||
QTest::keyClicks(wizard->currentPage()->findChild<QLineEdit*>("databaseDescription"), "Test Description");
|
||||
@ -308,7 +286,36 @@ void TestGui::createDatabaseCallback()
|
||||
fileDialog()->setNextFileName(tmpFile.fileName());
|
||||
|
||||
QTest::keyClick(fileCombo, Qt::Key::Key_Enter);
|
||||
tmpFile.remove();
|
||||
tmpFile.remove(););
|
||||
|
||||
triggerAction("actionDatabaseNew");
|
||||
|
||||
// there is a new empty db
|
||||
m_db = m_tabWidget->currentDatabaseWidget()->database();
|
||||
QCOMPARE(m_db->rootGroup()->children().size(), 0);
|
||||
|
||||
// check meta data
|
||||
QCOMPARE(m_db->metadata()->name(), QString("Test Name"));
|
||||
QCOMPARE(m_db->metadata()->description(), QString("Test Description"));
|
||||
|
||||
// check key and encryption
|
||||
QCOMPARE(m_db->key()->keys().size(), 2);
|
||||
QCOMPARE(m_db->kdf()->rounds(), 2);
|
||||
QCOMPARE(m_db->kdf()->uuid(), KeePass2::KDF_ARGON2);
|
||||
QCOMPARE(m_db->cipher(), KeePass2::CIPHER_AES256);
|
||||
auto compositeKey = QSharedPointer<CompositeKey>::create();
|
||||
compositeKey->addKey(QSharedPointer<PasswordKey>::create("test"));
|
||||
auto fileKey = QSharedPointer<FileKey>::create();
|
||||
fileKey->load(QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key"));
|
||||
compositeKey->addKey(fileKey);
|
||||
QCOMPARE(m_db->key()->rawKey(), compositeKey->rawKey());
|
||||
|
||||
// close the new database
|
||||
MessageBox::setNextAnswer(MessageBox::No);
|
||||
triggerAction("actionDatabaseClose");
|
||||
|
||||
// Wait for dialog to terminate
|
||||
QTRY_VERIFY(dialogFinished);
|
||||
}
|
||||
|
||||
void TestGui::testMergeDatabase()
|
||||
@ -666,14 +673,10 @@ void TestGui::testPasswordEntryEntropy()
|
||||
QVERIFY(passwordEdit);
|
||||
QTest::mouseClick(passwordEdit, Qt::LeftButton);
|
||||
|
||||
QTimer::singleShot(50, this, SLOT(passwordGeneratorCallback()));
|
||||
QTest::keyClick(passwordEdit, Qt::Key_G, Qt::ControlModifier);
|
||||
}
|
||||
|
||||
void TestGui::passwordGeneratorCallback()
|
||||
{
|
||||
auto* pwGeneratorWidget = m_dbWidget->findChild<PasswordGeneratorWidget*>();
|
||||
QVERIFY(pwGeneratorWidget);
|
||||
TEST_MODAL(PasswordGeneratorWidget * pwGeneratorWidget;
|
||||
QTRY_VERIFY(pwGeneratorWidget = m_dbWidget->findChild<PasswordGeneratorWidget*>());
|
||||
|
||||
// Type in some password
|
||||
auto* generatedPassword = pwGeneratorWidget->findChild<QLineEdit*>("editNewPassword");
|
||||
@ -721,7 +724,7 @@ void TestGui::passwordGeneratorCallback()
|
||||
QCOMPARE(strengthLabel->text(), QString("Password Quality: Excellent"));
|
||||
|
||||
QTest::mouseClick(generatedPassword, Qt::LeftButton);
|
||||
QTest::keyClick(generatedPassword, Qt::Key_Escape);
|
||||
QTest::keyClick(generatedPassword, Qt::Key_Escape););
|
||||
}
|
||||
|
||||
void TestGui::testDicewareEntryEntropy()
|
||||
@ -751,14 +754,10 @@ void TestGui::testDicewareEntryEntropy()
|
||||
QVERIFY(passwordEdit);
|
||||
QTest::mouseClick(passwordEdit, Qt::LeftButton);
|
||||
|
||||
QTimer::singleShot(50, this, SLOT(passwordGeneratorCallback()));
|
||||
QTest::keyClick(passwordEdit, Qt::Key_G, Qt::ControlModifier);
|
||||
}
|
||||
|
||||
void TestGui::passphraseGeneratorCallback()
|
||||
{
|
||||
auto* pwGeneratorWidget = m_dbWidget->findChild<PasswordGeneratorWidget*>();
|
||||
QVERIFY(pwGeneratorWidget);
|
||||
TEST_MODAL(PasswordGeneratorWidget * pwGeneratorWidget;
|
||||
QTRY_VERIFY(pwGeneratorWidget = m_dbWidget->findChild<PasswordGeneratorWidget*>());
|
||||
|
||||
// Select Diceware
|
||||
auto* generatedPassword = pwGeneratorWidget->findChild<QLineEdit*>("editNewPassword");
|
||||
@ -779,7 +778,7 @@ void TestGui::passphraseGeneratorCallback()
|
||||
QCOMPARE(strengthLabel->text(), QString("Password Quality: Good"));
|
||||
|
||||
QTest::mouseClick(generatedPassword, Qt::LeftButton);
|
||||
QTest::keyClick(generatedPassword, Qt::Key_Escape);
|
||||
QTest::keyClick(generatedPassword, Qt::Key_Escape););
|
||||
}
|
||||
|
||||
void TestGui::testTotp()
|
||||
|
@ -37,11 +37,6 @@ class TestGui : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected slots:
|
||||
void createDatabaseCallback();
|
||||
void passwordGeneratorCallback();
|
||||
void passphraseGeneratorCallback();
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void init();
|
||||
|
Loading…
Reference in New Issue
Block a user