mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Merge pull request #1164 from keepassxreboot/fix/add_db_creation_test
Add test for DB creation, re-use ChnageMasterKeyWidget instance in CsvImportWizard
This commit is contained in:
commit
2106be6a04
@ -63,6 +63,7 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
|
||||
, m_newGroup(nullptr)
|
||||
, m_newEntry(nullptr)
|
||||
, m_newParent(nullptr)
|
||||
, m_importingCsv(false)
|
||||
{
|
||||
m_mainWidget = new QWidget(this);
|
||||
|
||||
@ -137,13 +138,14 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
|
||||
m_editGroupWidget = new EditGroupWidget();
|
||||
m_editGroupWidget->setObjectName("editGroupWidget");
|
||||
m_changeMasterKeyWidget = new ChangeMasterKeyWidget();
|
||||
m_changeMasterKeyWidget->setObjectName("changeMasterKeyWidget");
|
||||
m_changeMasterKeyWidget->headlineLabel()->setText(tr("Change master key"));
|
||||
m_csvImportWizard = new CsvImportWizard();
|
||||
m_csvImportWizard->setObjectName("csvImportWizard");
|
||||
QFont headlineLabelFont = m_changeMasterKeyWidget->headlineLabel()->font();
|
||||
headlineLabelFont.setBold(true);
|
||||
headlineLabelFont.setPointSize(headlineLabelFont.pointSize() + 2);
|
||||
m_changeMasterKeyWidget->headlineLabel()->setFont(headlineLabelFont);
|
||||
m_csvImportWizard = new CsvImportWizard();
|
||||
m_csvImportWizard->setObjectName("csvImportWizard");
|
||||
m_databaseSettingsWidget = new DatabaseSettingsWidget();
|
||||
m_databaseSettingsWidget->setObjectName("databaseSettingsWidget");
|
||||
m_databaseOpenWidget = new DatabaseOpenWidget();
|
||||
@ -782,6 +784,12 @@ void DatabaseWidget::switchToGroupEdit(Group* group, bool create)
|
||||
|
||||
void DatabaseWidget::updateMasterKey(bool accepted)
|
||||
{
|
||||
if (m_importingCsv) {
|
||||
setCurrentWidget(m_csvImportWizard);
|
||||
m_csvImportWizard->keyFinished(accepted, m_changeMasterKeyWidget->newMasterKey());
|
||||
return;
|
||||
}
|
||||
|
||||
if (accepted) {
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||
bool result = m_db->setKey(m_changeMasterKeyWidget->newMasterKey());
|
||||
@ -915,6 +923,7 @@ void DatabaseWidget::switchToMasterKeyChange(bool disableCancel)
|
||||
m_changeMasterKeyWidget->clearForms();
|
||||
m_changeMasterKeyWidget->setCancelEnabled(!disableCancel);
|
||||
setCurrentWidget(m_changeMasterKeyWidget);
|
||||
m_importingCsv = false;
|
||||
}
|
||||
|
||||
void DatabaseWidget::switchToDatabaseSettings()
|
||||
@ -941,9 +950,11 @@ void DatabaseWidget::switchToOpenDatabase(const QString& fileName, const QString
|
||||
void DatabaseWidget::switchToImportCsv(const QString& fileName)
|
||||
{
|
||||
updateFilename(fileName);
|
||||
switchToMasterKeyChange();
|
||||
m_csvImportWizard->load(fileName, m_db);
|
||||
setCurrentWidget(m_csvImportWizard);
|
||||
m_changeMasterKeyWidget->clearForms();
|
||||
m_changeMasterKeyWidget->setCancelEnabled(false);
|
||||
setCurrentWidget(m_changeMasterKeyWidget);
|
||||
m_importingCsv = true;
|
||||
}
|
||||
|
||||
void DatabaseWidget::switchToOpenMergeDatabase(const QString& fileName)
|
||||
|
@ -236,6 +236,9 @@ private:
|
||||
bool m_searchCaseSensitive;
|
||||
bool m_searchLimitGroup;
|
||||
|
||||
// CSV import state
|
||||
bool m_importingCsv;
|
||||
|
||||
// Autoreload
|
||||
QFileSystemWatcher m_fileWatcher;
|
||||
QTimer m_fileWatchTimer;
|
||||
|
@ -28,19 +28,9 @@ CsvImportWizard::CsvImportWizard(QWidget *parent)
|
||||
: DialogyWidget(parent)
|
||||
{
|
||||
m_layout = new QGridLayout(this);
|
||||
m_pages = new QStackedWidget(parent);
|
||||
m_layout->addWidget(m_pages, 0, 0);
|
||||
m_layout->addWidget(m_parse = new CsvImportWidget(this), 0, 0);
|
||||
|
||||
m_pages->addWidget(key = new ChangeMasterKeyWidget(m_pages));
|
||||
m_pages->addWidget(parse = new CsvImportWidget(m_pages));
|
||||
key->headlineLabel()->setText(tr("Import CSV file"));
|
||||
QFont headLineFont = key->headlineLabel()->font();
|
||||
headLineFont.setBold(true);
|
||||
headLineFont.setPointSize(headLineFont.pointSize() + 2);
|
||||
key->headlineLabel()->setFont(headLineFont);
|
||||
|
||||
connect(key, SIGNAL(editFinished(bool)), this, SLOT(keyFinished(bool)));
|
||||
connect(parse, SIGNAL(editFinished(bool)), this, SLOT(parseFinished(bool)));
|
||||
connect(m_parse, SIGNAL(editFinished(bool)), this, SLOT(parseFinished(bool)));
|
||||
}
|
||||
|
||||
CsvImportWizard::~CsvImportWizard()
|
||||
@ -49,21 +39,18 @@ CsvImportWizard::~CsvImportWizard()
|
||||
void CsvImportWizard::load(const QString& filename, Database* database)
|
||||
{
|
||||
m_db = database;
|
||||
parse->load(filename, database);
|
||||
key->clearForms();
|
||||
m_parse->load(filename, database);
|
||||
}
|
||||
|
||||
void CsvImportWizard::keyFinished(bool accepted)
|
||||
void CsvImportWizard::keyFinished(bool accepted, CompositeKey key)
|
||||
{
|
||||
if (!accepted) {
|
||||
emit importFinished(false);
|
||||
return;
|
||||
}
|
||||
|
||||
m_pages->setCurrentIndex(m_pages->currentIndex()+1);
|
||||
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||
bool result = m_db->setKey(key->newMasterKey());
|
||||
bool result = m_db->setKey(key);
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
if (!result) {
|
||||
|
@ -38,19 +38,17 @@ public:
|
||||
explicit CsvImportWizard(QWidget *parent = nullptr);
|
||||
~CsvImportWizard();
|
||||
void load(const QString& filename, Database *database);
|
||||
void keyFinished(bool accepted, CompositeKey key);
|
||||
|
||||
signals:
|
||||
void importFinished(bool accepted);
|
||||
|
||||
private slots:
|
||||
void keyFinished(bool accepted);
|
||||
void parseFinished(bool accepted);
|
||||
|
||||
private:
|
||||
Database* m_db;
|
||||
CsvImportWidget* parse;
|
||||
ChangeMasterKeyWidget* key;
|
||||
QStackedWidget *m_pages;
|
||||
CsvImportWidget* m_parse;
|
||||
QGridLayout *m_layout;
|
||||
};
|
||||
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "gui/DatabaseTabWidget.h"
|
||||
#include "gui/DatabaseWidget.h"
|
||||
#include "gui/CloneDialog.h"
|
||||
#include "gui/PasswordEdit.h"
|
||||
#include "gui/TotpDialog.h"
|
||||
#include "gui/SetupTotpDialog.h"
|
||||
#include "gui/FileDialog.h"
|
||||
@ -119,6 +120,45 @@ void TestGui::cleanup()
|
||||
m_dbWidget = nullptr;
|
||||
}
|
||||
|
||||
void TestGui::testCreateDatabase()
|
||||
{
|
||||
QTemporaryFile tmpFile;
|
||||
QVERIFY(tmpFile.open());
|
||||
QString tmpFileName = tmpFile.fileName();
|
||||
tmpFile.remove();
|
||||
|
||||
fileDialog()->setNextFileName(tmpFileName);
|
||||
triggerAction("actionDatabaseNew");
|
||||
|
||||
DatabaseWidget* dbWidget = m_tabWidget->currentDatabaseWidget();
|
||||
|
||||
QWidget* databaseNewWidget = dbWidget->findChild<QWidget*>("changeMasterKeyWidget");
|
||||
QList<QWidget*> databaseNewWidgets = dbWidget->findChildren<QWidget*>("changeMasterKeyWidget");
|
||||
PasswordEdit* editPassword = databaseNewWidget->findChild<PasswordEdit*>("enterPasswordEdit");
|
||||
QVERIFY(editPassword->isVisible());
|
||||
|
||||
QLineEdit* editPasswordRepeat = databaseNewWidget->findChild<QLineEdit*>("repeatPasswordEdit");
|
||||
QVERIFY(editPasswordRepeat->isVisible());
|
||||
|
||||
m_tabWidget->currentDatabaseWidget()->setCurrentWidget(databaseNewWidget);
|
||||
|
||||
QTest::keyClicks(editPassword, "test");
|
||||
QTest::keyClicks(editPasswordRepeat, "test");
|
||||
QTest::keyClick(editPasswordRepeat, Qt::Key_Enter);
|
||||
|
||||
QTRY_VERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).contains("*"));
|
||||
|
||||
m_db = m_tabWidget->currentDatabaseWidget()->database();
|
||||
|
||||
// there is a new empty db
|
||||
QCOMPARE(m_db->rootGroup()->children().size(), 0);
|
||||
|
||||
// close the new database
|
||||
MessageBox::setNextAnswer(QMessageBox::No);
|
||||
triggerAction("actionDatabaseClose");
|
||||
Tools::wait(100);
|
||||
}
|
||||
|
||||
void TestGui::testMergeDatabase()
|
||||
{
|
||||
// It is safe to ignore the warning this line produces
|
||||
|
@ -40,6 +40,7 @@ private slots:
|
||||
void cleanup();
|
||||
void cleanupTestCase();
|
||||
|
||||
void testCreateDatabase();
|
||||
void testMergeDatabase();
|
||||
void testAutoreloadDatabase();
|
||||
void testTabs();
|
||||
|
Loading…
Reference in New Issue
Block a user