2011-12-26 13:18:21 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
2017-06-09 17:40:36 -04:00
|
|
|
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
2011-12-26 13:18:21 -05:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "TestGui.h"
|
2018-01-24 07:22:20 -05:00
|
|
|
#include "TestGlobal.h"
|
2018-09-29 13:00:47 -04:00
|
|
|
#include "gui/Application.h"
|
2011-12-26 13:18:21 -05:00
|
|
|
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QAction>
|
|
|
|
#include <QApplication>
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QDebug>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QDialogButtonBox>
|
2016-11-23 21:59:24 -05:00
|
|
|
#include <QLabel>
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QLineEdit>
|
2015-07-22 11:03:59 -04:00
|
|
|
#include <QMimeData>
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QPlainTextEdit>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QPushButton>
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QSignalSpy>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QSpinBox>
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QTimer>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QToolBar>
|
|
|
|
#include <QToolButton>
|
2011-12-26 13:18:21 -05:00
|
|
|
|
|
|
|
#include "config-keepassx-tests.h"
|
2018-09-29 13:00:47 -04:00
|
|
|
#include "core/Bootstrap.h"
|
2012-06-14 16:55:25 -04:00
|
|
|
#include "core/Config.h"
|
2012-07-06 13:21:19 -04:00
|
|
|
#include "core/Database.h"
|
2012-05-10 04:29:25 -04:00
|
|
|
#include "core/Entry.h"
|
2012-07-17 17:29:25 -04:00
|
|
|
#include "core/Group.h"
|
2012-07-06 13:21:19 -04:00
|
|
|
#include "core/Metadata.h"
|
2012-11-02 06:08:41 -04:00
|
|
|
#include "core/Tools.h"
|
2012-07-06 13:21:19 -04:00
|
|
|
#include "crypto/Crypto.h"
|
2017-11-12 12:56:01 -05:00
|
|
|
#include "crypto/kdf/AesKdf.h"
|
2012-07-06 13:21:19 -04:00
|
|
|
#include "format/KeePass2Reader.h"
|
2018-05-13 17:21:43 -04:00
|
|
|
#include "gui/ApplicationSettingsWidget.h"
|
|
|
|
#include "gui/CategoryListWidget.h"
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "gui/CloneDialog.h"
|
2012-04-14 14:31:35 -04:00
|
|
|
#include "gui/DatabaseTabWidget.h"
|
|
|
|
#include "gui/DatabaseWidget.h"
|
2011-12-26 13:18:21 -05:00
|
|
|
#include "gui/FileDialog.h"
|
2013-10-08 16:11:40 -04:00
|
|
|
#include "gui/MessageBox.h"
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "gui/PasswordEdit.h"
|
2016-11-28 19:02:21 -05:00
|
|
|
#include "gui/SearchWidget.h"
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "gui/TotpDialog.h"
|
2018-10-31 23:27:38 -04:00
|
|
|
#include "gui/TotpSetupDialog.h"
|
|
|
|
#include "gui/dbsettings/DatabaseSettingsDialog.h"
|
2012-05-16 04:16:32 -04:00
|
|
|
#include "gui/entry/EditEntryWidget.h"
|
|
|
|
#include "gui/entry/EntryView.h"
|
2018-03-31 16:01:30 -04:00
|
|
|
#include "gui/group/EditGroupWidget.h"
|
2012-07-17 17:29:25 -04:00
|
|
|
#include "gui/group/GroupModel.h"
|
|
|
|
#include "gui/group/GroupView.h"
|
2018-05-13 17:21:43 -04:00
|
|
|
#include "gui/masterkey/KeyComponentWidget.h"
|
2018-10-31 23:27:38 -04:00
|
|
|
#include "gui/masterkey/KeyFileEditWidget.h"
|
|
|
|
#include "gui/masterkey/PasswordEditWidget.h"
|
|
|
|
#include "gui/wizard/NewDatabaseWizard.h"
|
|
|
|
#include "keys/FileKey.h"
|
2012-07-06 13:21:19 -04:00
|
|
|
#include "keys/PasswordKey.h"
|
2011-12-26 13:18:21 -05:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
QTEST_MAIN(TestGui)
|
|
|
|
|
2011-12-26 13:18:21 -05:00
|
|
|
void TestGui::initTestCase()
|
|
|
|
{
|
2014-06-15 05:17:40 -04:00
|
|
|
QVERIFY(Crypto::init());
|
2012-06-14 16:55:25 -04:00
|
|
|
Config::createTempFileInstance();
|
2018-01-28 14:06:17 -05:00
|
|
|
// Disable autosave so we can test the modified file indicator
|
2018-05-13 17:21:43 -04:00
|
|
|
config()->set("AutoSaveAfterEveryChange", false);
|
2018-09-29 13:00:47 -04:00
|
|
|
// Enable the tray icon so we can test hiding/restoring the windowQByteArray
|
2018-05-13 17:21:43 -04:00
|
|
|
config()->set("GUI/ShowTrayIcon", true);
|
|
|
|
// Disable advanced settings mode (activate within individual tests to test advanced settings)
|
|
|
|
config()->set("GUI/AdvancedSettings", false);
|
2018-01-28 14:06:17 -05:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
m_mainWindow.reset(new MainWindow());
|
|
|
|
Bootstrap::restoreMainWindowState(*m_mainWindow);
|
2012-07-06 13:21:19 -04:00
|
|
|
m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");
|
2012-04-26 11:52:02 -04:00
|
|
|
m_mainWindow->show();
|
2015-07-19 13:33:47 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Load the NewDatabase.kdbx file into temporary storage
|
2015-07-19 13:33:47 -04:00
|
|
|
QFile sourceDbFile(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.kdbx"));
|
|
|
|
QVERIFY(sourceDbFile.open(QIODevice::ReadOnly));
|
2016-11-11 17:58:47 -05:00
|
|
|
QVERIFY(Tools::readAllFromDevice(&sourceDbFile, m_dbData));
|
2016-11-02 21:01:02 -04:00
|
|
|
sourceDbFile.close();
|
2016-11-11 17:58:47 -05:00
|
|
|
}
|
2015-07-19 13:33:47 -04:00
|
|
|
|
2016-11-11 17:58:47 -05:00
|
|
|
// Every test starts with opening the temp database
|
|
|
|
void TestGui::init()
|
|
|
|
{
|
2018-10-19 14:10:37 -04:00
|
|
|
m_dbFile.reset(new TemporaryFile());
|
2016-11-02 21:01:02 -04:00
|
|
|
// Write the temp storage to a temp database file for use in our tests
|
2018-09-29 13:00:47 -04:00
|
|
|
QVERIFY(m_dbFile->open());
|
|
|
|
QCOMPARE(m_dbFile->write(m_dbData), static_cast<qint64>((m_dbData.size())));
|
|
|
|
m_dbFileName = QFileInfo(m_dbFile->fileName()).fileName();
|
|
|
|
m_dbFilePath = m_dbFile->fileName();
|
|
|
|
m_dbFile->close();
|
2011-12-26 13:18:21 -05:00
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
// make sure window is activated or focus tests may fail
|
|
|
|
m_mainWindow->activateWindow();
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
2017-01-03 22:27:41 -05:00
|
|
|
fileDialog()->setNextFileName(m_dbFilePath);
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionDatabaseOpen");
|
2011-12-26 13:18:21 -05:00
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
auto* databaseOpenWidget = m_tabWidget->currentDatabaseWidget()->findChild<QWidget*>("databaseOpenWidget");
|
|
|
|
QVERIFY(databaseOpenWidget);
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editPassword = databaseOpenWidget->findChild<QLineEdit*>("editPassword");
|
2011-12-26 13:18:21 -05:00
|
|
|
QVERIFY(editPassword);
|
2018-11-22 05:47:31 -05:00
|
|
|
editPassword->setFocus();
|
2012-06-28 03:21:15 -04:00
|
|
|
|
2011-12-26 13:18:21 -05:00
|
|
|
QTest::keyClicks(editPassword, "a");
|
2012-06-28 03:21:15 -04:00
|
|
|
QTest::keyClick(editPassword, Qt::Key_Enter);
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
m_dbWidget = m_tabWidget->currentDatabaseWidget();
|
|
|
|
m_db = m_dbWidget->database();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Every test ends with closing the temp database without saving
|
|
|
|
void TestGui::cleanup()
|
|
|
|
{
|
|
|
|
// DO NOT save the database
|
2018-11-22 05:47:31 -05:00
|
|
|
m_db->markAsClean();
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::No);
|
2016-11-02 21:01:02 -04:00
|
|
|
triggerAction("actionDatabaseClose");
|
2018-09-29 13:00:47 -04:00
|
|
|
QApplication::processEvents();
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::NoButton);
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2018-01-06 18:30:18 -05:00
|
|
|
if (m_dbWidget) {
|
|
|
|
delete m_dbWidget;
|
|
|
|
}
|
2018-09-29 13:00:47 -04:00
|
|
|
|
|
|
|
m_dbFile->remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::cleanupTestCase()
|
|
|
|
{
|
|
|
|
m_dbFile->remove();
|
2011-12-29 14:10:19 -05:00
|
|
|
}
|
2011-12-26 13:18:21 -05:00
|
|
|
|
2018-05-13 17:21:43 -04:00
|
|
|
void TestGui::testSettingsDefaultTabOrder()
|
2017-10-29 10:04:46 -04:00
|
|
|
{
|
2018-05-13 17:21:43 -04:00
|
|
|
// check application settings default tab order
|
|
|
|
triggerAction("actionSettings");
|
|
|
|
auto* settingsWidget = m_mainWindow->findChild<ApplicationSettingsWidget*>();
|
|
|
|
QVERIFY(settingsWidget->isVisible());
|
|
|
|
QCOMPARE(settingsWidget->findChild<CategoryListWidget*>("categoryList")->currentCategory(), 0);
|
2018-10-31 23:27:38 -04:00
|
|
|
for (auto* w : settingsWidget->findChildren<QTabWidget*>()) {
|
2018-05-13 17:21:43 -04:00
|
|
|
if (w->currentIndex() != 0) {
|
|
|
|
QFAIL("Application settings contain QTabWidgets whose default index is not 0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QTest::keyClick(settingsWidget, Qt::Key::Key_Escape);
|
2017-10-29 10:04:46 -04:00
|
|
|
|
2018-05-13 17:21:43 -04:00
|
|
|
// check database settings default tab order
|
|
|
|
triggerAction("actionChangeDatabaseSettings");
|
|
|
|
auto* dbSettingsWidget = m_mainWindow->findChild<DatabaseSettingsDialog*>();
|
|
|
|
QVERIFY(dbSettingsWidget->isVisible());
|
|
|
|
QCOMPARE(dbSettingsWidget->findChild<CategoryListWidget*>("categoryList")->currentCategory(), 0);
|
2018-10-31 23:27:38 -04:00
|
|
|
for (auto* w : dbSettingsWidget->findChildren<QTabWidget*>()) {
|
2018-05-13 17:21:43 -04:00
|
|
|
if (w->currentIndex() != 0) {
|
|
|
|
QFAIL("Database settings contain QTabWidgets whose default index is not 0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QTest::keyClick(dbSettingsWidget, Qt::Key::Key_Escape);
|
|
|
|
}
|
2017-10-29 10:04:46 -04:00
|
|
|
|
2018-05-13 17:21:43 -04:00
|
|
|
void TestGui::testCreateDatabase()
|
|
|
|
{
|
|
|
|
QTimer::singleShot(0, this, SLOT(createDatabaseCallback()));
|
|
|
|
triggerAction("actionDatabaseNew");
|
2017-10-29 10:04:46 -04:00
|
|
|
|
|
|
|
// there is a new empty db
|
2018-05-13 17:21:43 -04:00
|
|
|
m_db = m_tabWidget->currentDatabaseWidget()->database();
|
2017-10-29 10:04:46 -04:00
|
|
|
QCOMPARE(m_db->rootGroup()->children().size(), 0);
|
|
|
|
|
2018-05-13 17:21:43 -04:00
|
|
|
// 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);
|
2018-09-29 13:00:47 -04:00
|
|
|
QCOMPARE(m_db->kdf()->rounds(), 2);
|
2018-05-13 17:21:43 -04:00
|
|
|
QCOMPARE(m_db->kdf()->uuid(), KeePass2::KDF_ARGON2);
|
2018-09-29 13:00:47 -04:00
|
|
|
QCOMPARE(m_db->cipher(), KeePass2::CIPHER_AES256);
|
2018-05-13 17:21:43 -04:00
|
|
|
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());
|
|
|
|
|
2017-11-02 14:58:45 -04:00
|
|
|
// close the new database
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::No);
|
2017-10-29 10:04:46 -04:00
|
|
|
triggerAction("actionDatabaseClose");
|
2018-05-13 17:21:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::createDatabaseCallback()
|
|
|
|
{
|
|
|
|
auto* wizard = m_tabWidget->findChild<NewDatabaseWizard*>();
|
|
|
|
QVERIFY(wizard);
|
|
|
|
|
|
|
|
QTest::keyClicks(wizard->currentPage()->findChild<QLineEdit*>("databaseName"), "Test Name");
|
|
|
|
QTest::keyClicks(wizard->currentPage()->findChild<QLineEdit*>("databaseDescription"), "Test Description");
|
|
|
|
QCOMPARE(wizard->currentId(), 0);
|
|
|
|
|
|
|
|
QTest::keyClick(wizard, Qt::Key_Enter);
|
|
|
|
QCOMPARE(wizard->currentId(), 1);
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto decryptionTimeSlider = wizard->currentPage()->findChild<QSlider*>("decryptionTimeSlider");
|
|
|
|
auto algorithmComboBox = wizard->currentPage()->findChild<QComboBox*>("algorithmComboBox");
|
|
|
|
QTRY_VERIFY(decryptionTimeSlider->isVisible());
|
|
|
|
QVERIFY(!algorithmComboBox->isVisible());
|
|
|
|
auto advancedToggle = wizard->currentPage()->findChild<QPushButton*>("advancedSettingsButton");
|
|
|
|
QTest::mouseClick(advancedToggle, Qt::MouseButton::LeftButton);
|
|
|
|
QTRY_VERIFY(!decryptionTimeSlider->isVisible());
|
|
|
|
QVERIFY(algorithmComboBox->isVisible());
|
|
|
|
|
|
|
|
auto rounds = wizard->currentPage()->findChild<QSpinBox*>("transformRoundsSpinBox");
|
|
|
|
QVERIFY(rounds);
|
|
|
|
QVERIFY(rounds->isVisible());
|
|
|
|
QTest::mouseClick(rounds, Qt::MouseButton::LeftButton);
|
|
|
|
QTest::keyClick(rounds, Qt::Key_A, Qt::ControlModifier);
|
|
|
|
QTest::keyClicks(rounds, "2");
|
|
|
|
QTest::keyClick(rounds, Qt::Key_Tab);
|
|
|
|
QTest::keyClick(rounds, Qt::Key_Tab);
|
|
|
|
|
|
|
|
auto memory = wizard->currentPage()->findChild<QSpinBox*>("memorySpinBox");
|
|
|
|
QVERIFY(memory);
|
|
|
|
QVERIFY(memory->isVisible());
|
|
|
|
QTest::mouseClick(memory, Qt::MouseButton::LeftButton);
|
|
|
|
QTest::keyClick(memory, Qt::Key_A, Qt::ControlModifier);
|
|
|
|
QTest::keyClicks(memory, "50");
|
|
|
|
QTest::keyClick(memory, Qt::Key_Tab);
|
|
|
|
|
|
|
|
auto parallelism = wizard->currentPage()->findChild<QSpinBox*>("parallelismSpinBox");
|
|
|
|
QVERIFY(parallelism);
|
|
|
|
QVERIFY(parallelism->isVisible());
|
|
|
|
QTest::mouseClick(parallelism, Qt::MouseButton::LeftButton);
|
|
|
|
QTest::keyClick(parallelism, Qt::Key_A, Qt::ControlModifier);
|
|
|
|
QTest::keyClicks(parallelism, "1");
|
|
|
|
QTest::keyClick(parallelism, Qt::Key_Enter);
|
|
|
|
|
2018-05-13 17:21:43 -04:00
|
|
|
QCOMPARE(wizard->currentId(), 2);
|
|
|
|
|
|
|
|
// enter password
|
|
|
|
auto* passwordWidget = wizard->currentPage()->findChild<PasswordEditWidget*>();
|
|
|
|
QCOMPARE(passwordWidget->visiblePage(), KeyFileEditWidget::Page::Edit);
|
|
|
|
auto* passwordEdit = passwordWidget->findChild<QLineEdit*>("enterPasswordEdit");
|
|
|
|
auto* passwordRepeatEdit = passwordWidget->findChild<QLineEdit*>("repeatPasswordEdit");
|
|
|
|
QTRY_VERIFY(passwordEdit->isVisible());
|
2018-09-29 13:00:47 -04:00
|
|
|
QTRY_VERIFY(passwordEdit->hasFocus());
|
2018-05-13 17:21:43 -04:00
|
|
|
QTest::keyClicks(passwordEdit, "test");
|
|
|
|
QTest::keyClick(passwordEdit, Qt::Key::Key_Tab);
|
|
|
|
QTest::keyClicks(passwordRepeatEdit, "test");
|
|
|
|
|
|
|
|
// add key file
|
|
|
|
auto* additionalOptionsButton = wizard->currentPage()->findChild<QPushButton*>("additionalKeyOptionsToggle");
|
|
|
|
auto* keyFileWidget = wizard->currentPage()->findChild<KeyFileEditWidget*>();
|
|
|
|
QVERIFY(additionalOptionsButton->isVisible());
|
|
|
|
QTest::mouseClick(additionalOptionsButton, Qt::MouseButton::LeftButton);
|
|
|
|
QTRY_VERIFY(keyFileWidget->isVisible());
|
|
|
|
QTRY_VERIFY(!additionalOptionsButton->isVisible());
|
|
|
|
QCOMPARE(passwordWidget->visiblePage(), KeyFileEditWidget::Page::Edit);
|
|
|
|
QTest::mouseClick(keyFileWidget->findChild<QPushButton*>("addButton"), Qt::MouseButton::LeftButton);
|
|
|
|
auto* fileCombo = keyFileWidget->findChild<QComboBox*>("keyFileCombo");
|
|
|
|
QTRY_VERIFY(fileCombo);
|
|
|
|
QTRY_VERIFY(fileCombo->isVisible());
|
|
|
|
fileDialog()->setNextFileName(QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key"));
|
|
|
|
QTest::keyClick(keyFileWidget->findChild<QPushButton*>("addButton"), Qt::Key::Key_Enter);
|
|
|
|
QVERIFY(fileCombo->hasFocus());
|
|
|
|
auto* browseButton = keyFileWidget->findChild<QPushButton*>("browseKeyFileButton");
|
|
|
|
QTest::keyClick(browseButton, Qt::Key::Key_Enter);
|
|
|
|
QCOMPARE(fileCombo->currentText(), QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key"));
|
|
|
|
|
|
|
|
// save database to temporary file
|
2018-10-19 14:10:37 -04:00
|
|
|
TemporaryFile tmpFile;
|
2018-05-13 17:21:43 -04:00
|
|
|
QVERIFY(tmpFile.open());
|
|
|
|
tmpFile.close();
|
2018-09-29 13:00:47 -04:00
|
|
|
fileDialog()->setNextFileName(tmpFile.fileName());
|
2018-05-13 17:21:43 -04:00
|
|
|
|
|
|
|
QTest::keyClick(fileCombo, Qt::Key::Key_Enter);
|
2018-09-29 13:00:47 -04:00
|
|
|
tmpFile.remove();
|
2017-10-29 10:04:46 -04:00
|
|
|
}
|
|
|
|
|
2016-11-07 22:37:42 -05:00
|
|
|
void TestGui::testMergeDatabase()
|
|
|
|
{
|
2016-11-11 17:58:47 -05:00
|
|
|
// It is safe to ignore the warning this line produces
|
2018-11-22 05:47:31 -05:00
|
|
|
QSignalSpy dbMergeSpy(m_dbWidget.data(), SIGNAL(databaseMerged(QSharedPointer<Database>)));
|
|
|
|
QApplication::processEvents();
|
2016-11-07 22:37:42 -05:00
|
|
|
|
|
|
|
// set file to merge from
|
|
|
|
fileDialog()->setNextFileName(QString(KEEPASSX_TEST_DATA_DIR).append("/MergeDatabase.kdbx"));
|
|
|
|
triggerAction("actionDatabaseMerge");
|
|
|
|
|
2018-11-23 18:57:41 -05:00
|
|
|
QTRY_COMPARE(QApplication::focusWidget()->objectName(), QString("editPassword"));
|
|
|
|
auto* editPasswordMerge = QApplication::focusWidget();
|
2016-11-07 22:37:42 -05:00
|
|
|
QVERIFY(editPasswordMerge->isVisible());
|
|
|
|
|
|
|
|
QTest::keyClicks(editPasswordMerge, "a");
|
|
|
|
QTest::keyClick(editPasswordMerge, Qt::Key_Enter);
|
|
|
|
|
|
|
|
QTRY_COMPARE(dbMergeSpy.count(), 1);
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_VERIFY(m_tabWidget->tabName(m_tabWidget->currentIndex()).contains("*"));
|
2016-11-07 22:37:42 -05:00
|
|
|
|
|
|
|
m_db = m_tabWidget->currentDatabaseWidget()->database();
|
|
|
|
|
|
|
|
// there are seven child groups of the root group
|
|
|
|
QCOMPARE(m_db->rootGroup()->children().size(), 7);
|
|
|
|
// the merged group should contain an entry
|
|
|
|
QCOMPARE(m_db->rootGroup()->children().at(6)->entries().size(), 1);
|
|
|
|
// the General group contains one entry merged from the other db
|
|
|
|
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 1);
|
|
|
|
}
|
|
|
|
|
2016-11-11 17:58:47 -05:00
|
|
|
void TestGui::testAutoreloadDatabase()
|
|
|
|
{
|
|
|
|
config()->set("AutoReloadOnChange", false);
|
|
|
|
|
|
|
|
// Load the MergeDatabase.kdbx file into temporary storage
|
2018-09-30 08:45:06 -04:00
|
|
|
QByteArray unmodifiedMergeDatabase;
|
2016-11-11 17:58:47 -05:00
|
|
|
QFile mergeDbFile(QString(KEEPASSX_TEST_DATA_DIR).append("/MergeDatabase.kdbx"));
|
|
|
|
QVERIFY(mergeDbFile.open(QIODevice::ReadOnly));
|
2018-09-30 08:45:06 -04:00
|
|
|
QVERIFY(Tools::readAllFromDevice(&mergeDbFile, unmodifiedMergeDatabase));
|
2016-11-11 17:58:47 -05:00
|
|
|
mergeDbFile.close();
|
|
|
|
|
|
|
|
// Test accepting new file in autoreload
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Yes);
|
2016-11-11 17:58:47 -05:00
|
|
|
// Overwrite the current database with the temp data
|
2018-09-29 13:00:47 -04:00
|
|
|
QVERIFY(m_dbFile->open());
|
|
|
|
QVERIFY(m_dbFile->write(unmodifiedMergeDatabase, static_cast<qint64>(unmodifiedMergeDatabase.size())));
|
|
|
|
m_dbFile->close();
|
2016-11-11 17:58:47 -05:00
|
|
|
|
2018-12-28 18:32:25 -05:00
|
|
|
QTRY_VERIFY(m_db != m_dbWidget->database());
|
2016-11-11 17:58:47 -05:00
|
|
|
m_db = m_dbWidget->database();
|
|
|
|
|
|
|
|
// the General group contains one entry from the new db data
|
|
|
|
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 1);
|
2018-11-22 05:47:31 -05:00
|
|
|
QVERIFY(!m_tabWidget->tabName(m_tabWidget->currentIndex()).endsWith("*"));
|
2016-11-11 17:58:47 -05:00
|
|
|
|
|
|
|
// Reset the state
|
|
|
|
cleanup();
|
|
|
|
init();
|
|
|
|
|
|
|
|
// Test rejecting new file in autoreload
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::No);
|
2016-11-11 17:58:47 -05:00
|
|
|
// Overwrite the current temp database with a new file
|
2018-12-28 18:32:25 -05:00
|
|
|
QVERIFY(m_dbFile->open());
|
2018-09-29 13:00:47 -04:00
|
|
|
QVERIFY(m_dbFile->write(unmodifiedMergeDatabase, static_cast<qint64>(unmodifiedMergeDatabase.size())));
|
|
|
|
m_dbFile->close();
|
2016-11-11 17:58:47 -05:00
|
|
|
|
|
|
|
// Ensure the merge did not take place
|
|
|
|
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 0);
|
2018-12-28 18:32:25 -05:00
|
|
|
QTRY_VERIFY(m_tabWidget->tabName(m_tabWidget->currentIndex()).endsWith("*"));
|
2016-11-11 17:58:47 -05:00
|
|
|
|
|
|
|
// Reset the state
|
|
|
|
cleanup();
|
|
|
|
init();
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
// Test accepting a merge of edits into autoreload
|
2016-11-11 17:58:47 -05:00
|
|
|
// Turn on autoload so we only get one messagebox (for the merge)
|
|
|
|
config()->set("AutoReloadOnChange", true);
|
|
|
|
// Modify some entries
|
|
|
|
testEditEntry();
|
|
|
|
|
|
|
|
// This is saying yes to merging the entries
|
2018-12-28 18:32:25 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Merge);
|
2016-11-11 17:58:47 -05:00
|
|
|
// Overwrite the current database with the temp data
|
2018-09-29 13:00:47 -04:00
|
|
|
QVERIFY(m_dbFile->open());
|
|
|
|
QVERIFY(m_dbFile->write(unmodifiedMergeDatabase, static_cast<qint64>(unmodifiedMergeDatabase.size())));
|
|
|
|
m_dbFile->close();
|
2016-11-11 17:58:47 -05:00
|
|
|
|
2018-12-28 18:32:25 -05:00
|
|
|
QTRY_VERIFY(m_db != m_dbWidget->database());
|
2016-11-11 17:58:47 -05:00
|
|
|
m_db = m_dbWidget->database();
|
|
|
|
|
|
|
|
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 1);
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_VERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*"));
|
2016-11-11 17:58:47 -05:00
|
|
|
}
|
|
|
|
|
2011-12-29 14:10:19 -05:00
|
|
|
void TestGui::testTabs()
|
|
|
|
{
|
2012-07-06 13:21:19 -04:00
|
|
|
QCOMPARE(m_tabWidget->count(), 1);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_tabWidget->tabName(m_tabWidget->currentIndex()), m_dbFileName);
|
2011-12-26 13:18:21 -05:00
|
|
|
}
|
|
|
|
|
2012-04-14 14:31:35 -04:00
|
|
|
void TestGui::testEditEntry()
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2018-11-09 21:58:42 -05:00
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2018-12-28 18:32:25 -05:00
|
|
|
entryView->setFocus();
|
|
|
|
QVERIFY(entryView->hasFocus());
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Select the first entry in the database
|
|
|
|
QModelIndex entryItem = entryView->model()->index(0, 1);
|
2017-06-13 20:55:53 -04:00
|
|
|
Entry* entry = entryView->entryFromIndex(entryItem);
|
2016-11-02 21:01:02 -04:00
|
|
|
clickIndex(entryItem, entryView, Qt::LeftButton);
|
2012-04-26 11:52:02 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Confirm the edit action button is enabled
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
|
2012-04-26 11:52:02 -04:00
|
|
|
QVERIFY(entryEditAction->isEnabled());
|
|
|
|
QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
|
|
|
|
QVERIFY(entryEditWidget->isVisible());
|
|
|
|
QVERIFY(entryEditWidget->isEnabled());
|
|
|
|
|
2018-11-09 21:58:42 -05:00
|
|
|
// Record current history count
|
|
|
|
int editCount = entry->historyItems().size();
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Edit the first entry ("Sample Entry")
|
|
|
|
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
2016-11-02 21:01:02 -04:00
|
|
|
QTest::keyClicks(titleEdit, "_test");
|
|
|
|
|
2017-06-13 20:55:53 -04:00
|
|
|
// Apply the edit
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2018-11-22 05:47:31 -05:00
|
|
|
QVERIFY(editEntryWidgetButtonBox);
|
2017-06-13 20:55:53 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Apply), Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2017-06-13 20:55:53 -04:00
|
|
|
QCOMPARE(entry->title(), QString("Sample Entry_test"));
|
2018-02-19 18:22:49 -05:00
|
|
|
QCOMPARE(entry->historyItems().size(), ++editCount);
|
|
|
|
|
|
|
|
// Test entry colors (simulate choosing a color)
|
|
|
|
editEntryWidget->setCurrentPage(1);
|
|
|
|
auto fgColor = QColor(Qt::red);
|
|
|
|
auto bgColor = QColor(Qt::blue);
|
|
|
|
// Set foreground color
|
|
|
|
auto colorButton = editEntryWidget->findChild<QPushButton*>("fgColorButton");
|
|
|
|
auto colorCheckBox = editEntryWidget->findChild<QCheckBox*>("fgColorCheckBox");
|
|
|
|
colorButton->setProperty("color", fgColor);
|
|
|
|
colorCheckBox->setChecked(true);
|
|
|
|
// Set background color
|
|
|
|
colorButton = editEntryWidget->findChild<QPushButton*>("bgColorButton");
|
|
|
|
colorCheckBox = editEntryWidget->findChild<QCheckBox*>("bgColorCheckBox");
|
|
|
|
colorButton->setProperty("color", bgColor);
|
|
|
|
colorCheckBox->setChecked(true);
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Apply), Qt::LeftButton);
|
|
|
|
QCOMPARE(entry->historyItems().size(), ++editCount);
|
2017-06-13 20:55:53 -04:00
|
|
|
|
2017-03-07 22:38:18 -05:00
|
|
|
// Test protected attributes
|
|
|
|
editEntryWidget->setCurrentPage(1);
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* attrTextEdit = editEntryWidget->findChild<QPlainTextEdit*>("attributesEdit");
|
2017-03-07 22:38:18 -05:00
|
|
|
QTest::mouseClick(editEntryWidget->findChild<QAbstractButton*>("addAttributeButton"), Qt::LeftButton);
|
|
|
|
QString attrText = "TEST TEXT";
|
|
|
|
QTest::keyClicks(attrTextEdit, attrText);
|
|
|
|
QCOMPARE(attrTextEdit->toPlainText(), attrText);
|
|
|
|
QTest::mouseClick(editEntryWidget->findChild<QAbstractButton*>("protectAttributeButton"), Qt::LeftButton);
|
|
|
|
QVERIFY(attrTextEdit->toPlainText().contains("PROTECTED"));
|
|
|
|
QTest::mouseClick(editEntryWidget->findChild<QAbstractButton*>("revealAttributeButton"), Qt::LeftButton);
|
|
|
|
QCOMPARE(attrTextEdit->toPlainText(), attrText);
|
|
|
|
editEntryWidget->setCurrentPage(0);
|
|
|
|
|
2017-09-29 17:05:30 -04:00
|
|
|
// Test mismatch passwords
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* passwordEdit = editEntryWidget->findChild<QLineEdit*>("passwordEdit");
|
2017-09-29 17:05:30 -04:00
|
|
|
QString originalPassword = passwordEdit->text();
|
|
|
|
passwordEdit->setText("newpass");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* messageWiget = editEntryWidget->findChild<MessageWidget*>("messageWidget");
|
2017-09-29 17:05:30 -04:00
|
|
|
QTRY_VERIFY(messageWiget->isVisible());
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2017-09-29 17:05:30 -04:00
|
|
|
QCOMPARE(passwordEdit->text(), QString("newpass"));
|
|
|
|
passwordEdit->setText(originalPassword);
|
|
|
|
|
2017-06-13 20:55:53 -04:00
|
|
|
// Save the edit (press OK)
|
2012-04-14 14:31:35 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QApplication::processEvents();
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Confirm edit was made
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2016-11-02 21:01:02 -04:00
|
|
|
QCOMPARE(entry->title(), QString("Sample Entry_test"));
|
2018-02-19 18:22:49 -05:00
|
|
|
QCOMPARE(entry->foregroundColor(), fgColor);
|
|
|
|
QCOMPARE(entryItem.data(Qt::ForegroundRole), QVariant(fgColor));
|
|
|
|
QCOMPARE(entry->backgroundColor(), bgColor);
|
|
|
|
QCOMPARE(entryItem.data(Qt::BackgroundRole), QVariant(bgColor));
|
|
|
|
QCOMPARE(entry->historyItems().size(), ++editCount);
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Confirm modified indicator is showing
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_COMPARE(m_tabWidget->tabName(m_tabWidget->currentIndex()), QString("%1*").arg(m_dbFileName));
|
2018-02-25 14:59:59 -05:00
|
|
|
|
|
|
|
// Test copy & paste newline sanitization
|
|
|
|
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2018-02-25 14:59:59 -05:00
|
|
|
titleEdit->setText("multiline\ntitle");
|
|
|
|
editEntryWidget->findChild<QLineEdit*>("usernameEdit")->setText("multiline\nusername");
|
|
|
|
editEntryWidget->findChild<QLineEdit*>("passwordEdit")->setText("multiline\npassword");
|
|
|
|
editEntryWidget->findChild<QLineEdit*>("passwordRepeatEdit")->setText("multiline\npassword");
|
|
|
|
editEntryWidget->findChild<QLineEdit*>("urlEdit")->setText("multiline\nurl");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
|
|
|
QCOMPARE(entry->title(), QString("multiline title"));
|
|
|
|
QCOMPARE(entry->username(), QString("multiline username"));
|
|
|
|
// here we keep newlines, so users can't lock themselves out accidentally
|
|
|
|
QCOMPARE(entry->password(), QString("multiline\npassword"));
|
|
|
|
QCOMPARE(entry->url(), QString("multiline url"));
|
2012-04-14 14:31:35 -04:00
|
|
|
}
|
|
|
|
|
2018-02-16 23:30:24 -05:00
|
|
|
void TestGui::testSearchEditEntry()
|
|
|
|
{
|
|
|
|
// Regression test for Issue #1447 -- Uses example from issue description
|
|
|
|
|
|
|
|
// Find buttons for group creation
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editGroupWidget = m_dbWidget->findChild<EditGroupWidget*>("editGroupWidget");
|
|
|
|
auto* nameEdit = editGroupWidget->findChild<QLineEdit*>("editName");
|
|
|
|
auto* editGroupWidgetButtonBox = editGroupWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2018-02-16 23:30:24 -05:00
|
|
|
|
|
|
|
// Add groups "Good" and "Bad"
|
|
|
|
m_dbWidget->createGroup();
|
|
|
|
QTest::keyClicks(nameEdit, "Good");
|
|
|
|
QTest::mouseClick(editGroupWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(m_db->rootGroup()); // Makes "Good" and "Bad" on the same level
|
|
|
|
m_dbWidget->createGroup();
|
|
|
|
QTest::keyClicks(nameEdit, "Bad");
|
|
|
|
QTest::mouseClick(editGroupWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(m_db->rootGroup());
|
|
|
|
|
|
|
|
// Find buttons for entry creation
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2018-02-16 23:30:24 -05:00
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(m_mainWindow->findChild<QAction*>("actionEntryNew"));
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
|
|
|
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2018-02-16 23:30:24 -05:00
|
|
|
|
|
|
|
// Create "Doggy" in "Good"
|
|
|
|
Group* goodGroup = m_dbWidget->currentGroup()->findChildByName(QString("Good"));
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(goodGroup);
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "Doggy");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
// Select "Bad" group in groupView
|
|
|
|
Group* badGroup = m_db->rootGroup()->findChildByName(QString("Bad"));
|
|
|
|
m_dbWidget->groupView()->setCurrentGroup(badGroup);
|
|
|
|
|
|
|
|
// Search for "Doggy" entry
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* searchWidget = toolBar->findChild<SearchWidget*>("SearchWidget");
|
|
|
|
auto* searchTextEdit = searchWidget->findChild<QLineEdit*>("searchEdit");
|
2018-02-16 23:30:24 -05:00
|
|
|
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(searchTextEdit, "Doggy");
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_VERIFY(m_dbWidget->isSearchActive());
|
2018-02-16 23:30:24 -05:00
|
|
|
|
|
|
|
// Goto "Doggy"'s edit view
|
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Return);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2018-02-16 23:30:24 -05:00
|
|
|
|
|
|
|
// Check the path in header is "parent-group > entry"
|
|
|
|
QCOMPARE(m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget")->findChild<QLabel*>("headerLabel")->text(),
|
|
|
|
QString("Good > Doggy > Edit entry"));
|
|
|
|
}
|
|
|
|
|
2012-05-10 04:29:25 -04:00
|
|
|
void TestGui::testAddEntry()
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Find the new entry action
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
2012-05-10 04:29:25 -04:00
|
|
|
QVERIFY(entryNewAction->isEnabled());
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Find the button associated with the new entry action
|
2012-05-10 04:29:25 -04:00
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
|
|
|
|
QVERIFY(entryNewWidget->isVisible());
|
|
|
|
QVERIFY(entryNewWidget->isEnabled());
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Click the new entry button and check that we enter edit mode
|
2012-05-10 04:29:25 -04:00
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2012-05-10 04:29:25 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Add entry "test" and confirm added
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
2012-05-10 04:29:25 -04:00
|
|
|
QTest::keyClicks(titleEdit, "test");
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2012-05-10 04:29:25 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2012-05-12 07:22:41 -04:00
|
|
|
QModelIndex item = entryView->model()->index(1, 1);
|
2012-05-11 06:01:01 -04:00
|
|
|
Entry* entry = entryView->entryFromIndex(item);
|
2012-05-10 04:29:25 -04:00
|
|
|
|
|
|
|
QCOMPARE(entry->title(), QString("test"));
|
|
|
|
QCOMPARE(entry->historyItems().size(), 0);
|
2013-10-08 16:11:40 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Add entry "something 2"
|
2013-10-08 16:11:40 -04:00
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "something 2");
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* passwordEdit = editEntryWidget->findChild<QLineEdit*>("passwordEdit");
|
|
|
|
auto* passwordRepeatEdit = editEntryWidget->findChild<QLineEdit*>("passwordRepeatEdit");
|
2016-12-23 12:13:08 -05:00
|
|
|
QTest::keyClicks(passwordEdit, "something 2");
|
|
|
|
QTest::keyClicks(passwordRepeatEdit, "something 2");
|
2013-10-08 16:11:40 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
2017-10-28 09:23:45 -04:00
|
|
|
// Add entry "something 5" but click cancel button (does NOT add entry)
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "something 5");
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Discard);
|
2017-10-28 09:23:45 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Cancel), Qt::LeftButton);
|
|
|
|
|
2017-03-16 21:08:09 -04:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
2018-08-13 09:04:18 -04:00
|
|
|
// Confirm entry count
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 3);
|
2012-05-10 04:29:25 -04:00
|
|
|
}
|
|
|
|
|
2017-03-04 13:24:08 -05:00
|
|
|
void TestGui::testPasswordEntryEntropy()
|
2016-11-23 21:59:24 -05:00
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2016-11-23 21:59:24 -05:00
|
|
|
|
|
|
|
// Find the new entry action
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
2016-11-23 21:59:24 -05:00
|
|
|
QVERIFY(entryNewAction->isEnabled());
|
|
|
|
|
|
|
|
// Find the button associated with the new entry action
|
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
|
|
|
|
QVERIFY(entryNewWidget->isVisible());
|
|
|
|
QVERIFY(entryNewWidget->isEnabled());
|
|
|
|
|
|
|
|
// Click the new entry button and check that we enter edit mode
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2016-11-23 21:59:24 -05:00
|
|
|
|
|
|
|
// Add entry "test" and confirm added
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
2016-11-23 21:59:24 -05:00
|
|
|
QTest::keyClicks(titleEdit, "test");
|
|
|
|
|
|
|
|
// Open the password generator
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* generatorButton = editEntryWidget->findChild<QToolButton*>("togglePasswordGeneratorButton");
|
2016-11-23 21:59:24 -05:00
|
|
|
QTest::mouseClick(generatorButton, Qt::LeftButton);
|
|
|
|
|
|
|
|
// Type in some password
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editNewPassword = editEntryWidget->findChild<QLineEdit*>("editNewPassword");
|
|
|
|
auto* entropyLabel = editEntryWidget->findChild<QLabel*>("entropyLabel");
|
|
|
|
auto* strengthLabel = editEntryWidget->findChild<QLabel*>("strengthLabel");
|
2016-11-23 21:59:24 -05:00
|
|
|
|
|
|
|
editNewPassword->setText("");
|
|
|
|
QTest::keyClicks(editNewPassword, "hello");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 6.38 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Poor"));
|
|
|
|
|
|
|
|
editNewPassword->setText("");
|
|
|
|
QTest::keyClicks(editNewPassword, "helloworld");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 13.10 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Poor"));
|
|
|
|
|
|
|
|
editNewPassword->setText("");
|
|
|
|
QTest::keyClicks(editNewPassword, "password1");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 4.00 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Poor"));
|
|
|
|
|
|
|
|
editNewPassword->setText("");
|
|
|
|
QTest::keyClicks(editNewPassword, "D0g..................");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 19.02 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Poor"));
|
|
|
|
|
|
|
|
editNewPassword->setText("");
|
|
|
|
QTest::keyClicks(editNewPassword, "Tr0ub4dour&3");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 30.87 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Poor"));
|
|
|
|
|
|
|
|
editNewPassword->setText("");
|
|
|
|
QTest::keyClicks(editNewPassword, "correcthorsebatterystaple");
|
2018-03-31 16:01:30 -04:00
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 47.98 bit"));
|
2016-11-23 21:59:24 -05:00
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Weak"));
|
2016-12-23 12:13:08 -05:00
|
|
|
|
2016-11-23 21:59:24 -05:00
|
|
|
editNewPassword->setText("");
|
|
|
|
QTest::keyClicks(editNewPassword, "YQC3kbXbjC652dTDH");
|
2018-03-31 16:01:30 -04:00
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 95.83 bit"));
|
2016-11-23 21:59:24 -05:00
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Good"));
|
2016-12-23 12:13:08 -05:00
|
|
|
|
2016-11-23 21:59:24 -05:00
|
|
|
editNewPassword->setText("");
|
|
|
|
QTest::keyClicks(editNewPassword, "Bs5ZFfthWzR8DGFEjaCM6bGqhmCT4km");
|
2018-03-31 16:01:30 -04:00
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 174.59 bit"));
|
2016-11-23 21:59:24 -05:00
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Excellent"));
|
|
|
|
}
|
|
|
|
|
2017-03-04 13:24:08 -05:00
|
|
|
void TestGui::testDicewareEntryEntropy()
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2017-03-04 13:24:08 -05:00
|
|
|
|
|
|
|
// Find the new entry action
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
2017-03-04 13:24:08 -05:00
|
|
|
QVERIFY(entryNewAction->isEnabled());
|
|
|
|
|
|
|
|
// Find the button associated with the new entry action
|
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
|
|
|
|
QVERIFY(entryNewWidget->isVisible());
|
|
|
|
QVERIFY(entryNewWidget->isEnabled());
|
|
|
|
|
|
|
|
// Click the new entry button and check that we enter edit mode
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2017-03-04 13:24:08 -05:00
|
|
|
|
|
|
|
// Add entry "test" and confirm added
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
2017-03-04 13:24:08 -05:00
|
|
|
QTest::keyClicks(titleEdit, "test");
|
|
|
|
|
|
|
|
// Open the password generator
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* generatorButton = editEntryWidget->findChild<QToolButton*>("togglePasswordGeneratorButton");
|
2017-03-04 13:24:08 -05:00
|
|
|
QTest::mouseClick(generatorButton, Qt::LeftButton);
|
|
|
|
|
|
|
|
// Select Diceware
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* tabWidget = editEntryWidget->findChild<QTabWidget*>("tabWidget");
|
|
|
|
auto* dicewareWidget = editEntryWidget->findChild<QWidget*>("dicewareWidget");
|
2017-03-04 13:24:08 -05:00
|
|
|
tabWidget->setCurrentWidget(dicewareWidget);
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* comboBoxWordList = dicewareWidget->findChild<QComboBox*>("comboBoxWordList");
|
2017-03-04 13:24:08 -05:00
|
|
|
comboBoxWordList->setCurrentText("eff_large.wordlist");
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* spinBoxWordCount = dicewareWidget->findChild<QSpinBox*>("spinBoxWordCount");
|
2017-03-04 13:24:08 -05:00
|
|
|
spinBoxWordCount->setValue(6);
|
|
|
|
|
|
|
|
// Type in some password
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entropyLabel = editEntryWidget->findChild<QLabel*>("entropyLabel");
|
|
|
|
auto* strengthLabel = editEntryWidget->findChild<QLabel*>("strengthLabel");
|
2017-03-04 13:24:08 -05:00
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 77.55 bit"));
|
2017-03-04 13:24:08 -05:00
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Good"));
|
|
|
|
}
|
|
|
|
|
2017-04-13 06:05:36 -04:00
|
|
|
void TestGui::testTotp()
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2017-04-13 06:05:36 -04:00
|
|
|
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 1);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2017-04-13 06:05:36 -04:00
|
|
|
QModelIndex item = entryView->model()->index(0, 1);
|
|
|
|
Entry* entry = entryView->entryFromIndex(item);
|
|
|
|
clickIndex(item, entryView, Qt::LeftButton);
|
|
|
|
|
|
|
|
triggerAction("actionEntrySetupTotp");
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* setupTotpDialog = m_dbWidget->findChild<TotpSetupDialog*>("TotpSetupDialog");
|
2017-04-13 06:05:36 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
QApplication::processEvents();
|
2017-04-13 06:05:36 -04:00
|
|
|
|
2018-11-16 10:00:59 -05:00
|
|
|
QString exampleSeed = "gezdgnbvgy3tqojqgezdgnbvgy3tqojq";
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* seedEdit = setupTotpDialog->findChild<QLineEdit*>("seedEdit");
|
2018-11-09 21:58:42 -05:00
|
|
|
seedEdit->setText("");
|
2017-04-13 06:05:36 -04:00
|
|
|
QTest::keyClicks(seedEdit, exampleSeed);
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* setupTotpButtonBox = setupTotpDialog->findChild<QDialogButtonBox*>("buttonBox");
|
2017-04-13 06:05:36 -04:00
|
|
|
QTest::mouseClick(setupTotpButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
2018-11-16 10:00:59 -05:00
|
|
|
QTRY_VERIFY(!setupTotpDialog->isVisible());
|
|
|
|
|
|
|
|
// Make sure the entryView is selected and active
|
|
|
|
entryView->activateWindow();
|
|
|
|
QApplication::processEvents();
|
|
|
|
QTRY_VERIFY(entryView->hasFocus());
|
2017-04-13 06:05:36 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
|
2017-04-13 06:05:36 -04:00
|
|
|
QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
|
2018-11-16 10:00:59 -05:00
|
|
|
QVERIFY(entryEditWidget->isVisible());
|
|
|
|
QVERIFY(entryEditWidget->isEnabled());
|
2017-04-13 06:05:36 -04:00
|
|
|
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2017-04-13 06:05:36 -04:00
|
|
|
|
2018-11-16 10:00:59 -05:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
2017-04-13 06:05:36 -04:00
|
|
|
editEntryWidget->setCurrentPage(1);
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* attrTextEdit = editEntryWidget->findChild<QPlainTextEdit*>("attributesEdit");
|
2017-04-13 06:05:36 -04:00
|
|
|
QTest::mouseClick(editEntryWidget->findChild<QAbstractButton*>("revealAttributeButton"), Qt::LeftButton);
|
|
|
|
QCOMPARE(attrTextEdit->toPlainText(), exampleSeed);
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2017-04-13 06:05:36 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
|
|
|
triggerAction("actionEntryTotp");
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* totpDialog = m_dbWidget->findChild<TotpDialog*>("TotpDialog");
|
|
|
|
auto* totpLabel = totpDialog->findChild<QLabel*>("totpLabel");
|
2017-04-13 06:05:36 -04:00
|
|
|
|
2017-05-03 20:26:08 -04:00
|
|
|
QCOMPARE(totpLabel->text().replace(" ", ""), entry->totp());
|
2017-04-13 06:05:36 -04:00
|
|
|
}
|
|
|
|
|
2012-05-16 03:56:40 -04:00
|
|
|
void TestGui::testSearch()
|
|
|
|
{
|
2016-11-02 21:01:02 -04:00
|
|
|
// Add canned entries for consistent testing
|
2017-10-28 09:23:45 -04:00
|
|
|
Q_UNUSED(addCannedEntries());
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* searchWidget = toolBar->findChild<SearchWidget*>("SearchWidget");
|
2016-11-28 19:02:21 -05:00
|
|
|
QVERIFY(searchWidget->isEnabled());
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* searchTextEdit = searchWidget->findChild<QLineEdit*>("searchEdit");
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2016-11-02 21:01:02 -04:00
|
|
|
QVERIFY(entryView->isVisible());
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* clearButton = searchWidget->findChild<QAction*>("clearIcon");
|
2017-04-05 04:42:15 -04:00
|
|
|
QVERIFY(!clearButton->isVisible());
|
|
|
|
|
2018-11-01 21:33:27 -04:00
|
|
|
auto* helpButton = searchWidget->findChild<QAction*>("helpIcon");
|
|
|
|
auto* helpPanel = searchWidget->findChild<QWidget*>("SearchHelpWidget");
|
|
|
|
QVERIFY(helpButton->isVisible());
|
|
|
|
QVERIFY(!helpPanel->isVisible());
|
|
|
|
|
2014-11-18 21:46:38 -05:00
|
|
|
// Enter search
|
2016-11-28 19:02:21 -05:00
|
|
|
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
2017-04-05 04:42:15 -04:00
|
|
|
QTRY_VERIFY(!clearButton->isVisible());
|
2018-11-01 21:33:27 -04:00
|
|
|
// Show/Hide search help
|
|
|
|
helpButton->trigger();
|
|
|
|
QTRY_VERIFY(helpPanel->isVisible());
|
|
|
|
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
|
|
|
QTRY_VERIFY(helpPanel->isVisible());
|
|
|
|
helpButton->trigger();
|
|
|
|
QTRY_VERIFY(!helpPanel->isVisible());
|
2014-11-18 02:26:04 -05:00
|
|
|
// Search for "ZZZ"
|
2016-11-28 19:02:21 -05:00
|
|
|
QTest::keyClicks(searchTextEdit, "ZZZ");
|
|
|
|
QTRY_COMPARE(searchTextEdit->text(), QString("ZZZ"));
|
2017-04-05 04:42:15 -04:00
|
|
|
QTRY_VERIFY(clearButton->isVisible());
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_VERIFY(m_dbWidget->isSearchActive());
|
2016-11-02 21:01:02 -04:00
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 0);
|
2017-01-14 22:29:16 -05:00
|
|
|
// Press the search clear button
|
2017-04-05 04:42:15 -04:00
|
|
|
clearButton->trigger();
|
2017-01-14 22:29:16 -05:00
|
|
|
QTRY_VERIFY(searchTextEdit->text().isEmpty());
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
2017-04-05 04:42:15 -04:00
|
|
|
QTRY_VERIFY(!clearButton->isVisible());
|
2016-11-02 21:01:02 -04:00
|
|
|
// Escape clears searchedit and retains focus
|
2017-01-14 22:29:16 -05:00
|
|
|
QTest::keyClicks(searchTextEdit, "ZZZ");
|
2016-11-28 19:02:21 -05:00
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Escape);
|
|
|
|
QTRY_VERIFY(searchTextEdit->text().isEmpty());
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2014-11-18 02:26:04 -05:00
|
|
|
// Search for "some"
|
2016-11-28 19:02:21 -05:00
|
|
|
QTest::keyClicks(searchTextEdit, "some");
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_VERIFY(m_dbWidget->isSearchActive());
|
2016-11-02 21:01:02 -04:00
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 3);
|
2016-11-28 19:02:21 -05:00
|
|
|
// Search for "someTHING"
|
|
|
|
QTest::keyClicks(searchTextEdit, "THING");
|
2016-11-02 21:01:02 -04:00
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 2);
|
2017-01-04 20:46:52 -05:00
|
|
|
// Press Down to focus on the entry view
|
2016-12-23 12:13:08 -05:00
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Right, Qt::ControlModifier);
|
2016-12-22 02:21:52 -05:00
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Down);
|
|
|
|
QTRY_VERIFY(entryView->hasFocus());
|
2017-01-04 20:46:52 -05:00
|
|
|
// Restore focus and search text selection
|
2018-09-29 13:00:47 -04:00
|
|
|
QTest::keyClick(m_mainWindow.data(), Qt::Key_F, Qt::ControlModifier);
|
2017-01-04 20:46:52 -05:00
|
|
|
QTRY_COMPARE(searchTextEdit->selectedText(), QString("someTHING"));
|
|
|
|
// Ensure Down focuses on entry view when search text is selected
|
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Down);
|
|
|
|
QTRY_VERIFY(entryView->hasFocus());
|
2018-03-25 16:24:30 -04:00
|
|
|
QCOMPARE(entryView->selectionModel()->currentIndex().row(), 0);
|
2018-11-16 10:00:59 -05:00
|
|
|
// Test that password copies (entry has focus)
|
2018-03-31 16:01:30 -04:00
|
|
|
QClipboard* clipboard = QApplication::clipboard();
|
2018-03-25 16:24:30 -04:00
|
|
|
QTest::keyClick(entryView, Qt::Key_C, Qt::ControlModifier);
|
2016-12-23 12:13:08 -05:00
|
|
|
QModelIndex searchedItem = entryView->model()->index(0, 1);
|
|
|
|
Entry* searchedEntry = entryView->entryFromIndex(searchedItem);
|
|
|
|
QTRY_COMPARE(searchedEntry->password(), clipboard->text());
|
2018-11-16 10:00:59 -05:00
|
|
|
// Refocus back to search edit
|
|
|
|
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
|
|
|
// Test that password does not copy
|
|
|
|
searchTextEdit->selectAll();
|
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_C, Qt::ControlModifier);
|
|
|
|
QTRY_COMPARE(clipboard->text(), QString("someTHING"));
|
2016-11-28 19:02:21 -05:00
|
|
|
|
|
|
|
// Test case sensitive search
|
|
|
|
searchWidget->setCaseSensitive(true);
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 0);
|
|
|
|
searchWidget->setCaseSensitive(false);
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 2);
|
|
|
|
|
|
|
|
// Test group search
|
2018-11-28 16:13:56 -05:00
|
|
|
searchWidget->setLimitGroup(false);
|
2016-11-28 19:02:21 -05:00
|
|
|
GroupView* groupView = m_dbWidget->findChild<GroupView*>("groupView");
|
|
|
|
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
|
|
|
QModelIndex rootGroupIndex = groupView->model()->index(0, 0);
|
|
|
|
clickIndex(groupView->model()->index(0, 0, rootGroupIndex), groupView, Qt::LeftButton);
|
|
|
|
QCOMPARE(groupView->currentGroup()->name(), QString("General"));
|
2018-11-28 16:13:56 -05:00
|
|
|
// Selecting a group should cancel search
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 0);
|
|
|
|
// Restore search
|
|
|
|
QTest::keyClick(m_mainWindow.data(), Qt::Key_F, Qt::ControlModifier);
|
|
|
|
QTest::keyClicks(searchTextEdit, "someTHING");
|
2017-06-20 15:54:13 -04:00
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 2);
|
2018-11-28 16:13:56 -05:00
|
|
|
// Enable group limiting
|
2017-06-20 15:54:13 -04:00
|
|
|
searchWidget->setLimitGroup(true);
|
2016-11-28 19:02:21 -05:00
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 0);
|
2018-11-28 16:13:56 -05:00
|
|
|
// Selecting another group should NOT cancel search
|
|
|
|
clickIndex(rootGroupIndex, groupView, Qt::LeftButton);
|
|
|
|
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 2);
|
2017-06-20 15:54:13 -04:00
|
|
|
|
2016-11-28 19:02:21 -05:00
|
|
|
// reset
|
2018-11-28 16:13:56 -05:00
|
|
|
searchWidget->setLimitGroup(false);
|
2016-11-28 19:02:21 -05:00
|
|
|
clickIndex(rootGroupIndex, groupView, Qt::LeftButton);
|
|
|
|
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Try to edit the first entry from the search view
|
2017-01-04 20:46:52 -05:00
|
|
|
// Refocus back to search edit
|
|
|
|
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
2018-11-22 05:47:31 -05:00
|
|
|
QVERIFY(m_dbWidget->isSearchActive());
|
2017-01-04 20:46:52 -05:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
QModelIndex item = entryView->model()->index(0, 1);
|
|
|
|
Entry* entry = entryView->entryFromIndex(item);
|
2017-01-04 20:46:52 -05:00
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Return);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Perform the edit and save it
|
2012-07-17 04:16:59 -04:00
|
|
|
EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
2016-11-02 21:01:02 -04:00
|
|
|
QLineEdit* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
|
|
|
QString origTitle = titleEdit->text();
|
|
|
|
QTest::keyClicks(titleEdit, "_edited");
|
2012-05-16 03:56:40 -04:00
|
|
|
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
2017-01-04 20:46:52 -05:00
|
|
|
// Confirm the edit was made and we are back in search mode
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_VERIFY(m_dbWidget->isSearchActive());
|
2016-11-02 21:01:02 -04:00
|
|
|
QCOMPARE(entry->title(), origTitle.append("_edited"));
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Cancel search, should return to normal view
|
2018-09-29 13:00:47 -04:00
|
|
|
QTest::keyClick(m_mainWindow.data(), Qt::Key_Escape);
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_COMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2016-11-02 21:01:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::testDeleteEntry()
|
|
|
|
{
|
|
|
|
// Add canned entries for consistent testing
|
2017-10-28 09:23:45 -04:00
|
|
|
Q_UNUSED(addCannedEntries());
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* groupView = m_dbWidget->findChild<GroupView*>("groupView");
|
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
auto* entryDeleteAction = m_mainWindow->findChild<QAction*>("actionEntryDelete");
|
2012-05-16 03:56:40 -04:00
|
|
|
QWidget* entryDeleteWidget = toolBar->widgetForAction(entryDeleteAction);
|
2018-12-28 18:32:25 -05:00
|
|
|
entryView->setFocus();
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2017-12-21 04:32:07 -05:00
|
|
|
clickIndex(entryView->model()->index(1, 1), entryView, Qt::LeftButton);
|
2012-05-16 03:56:40 -04:00
|
|
|
QVERIFY(entryDeleteWidget->isVisible());
|
|
|
|
QVERIFY(entryDeleteWidget->isEnabled());
|
2013-10-08 16:14:02 -04:00
|
|
|
QVERIFY(!m_db->metadata()->recycleBin());
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Move);
|
2012-05-16 03:56:40 -04:00
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
2013-10-08 16:11:40 -04:00
|
|
|
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 3);
|
2013-10-08 16:14:02 -04:00
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1);
|
2013-10-08 16:11:40 -04:00
|
|
|
|
2017-12-21 04:32:07 -05:00
|
|
|
clickIndex(entryView->model()->index(1, 1), entryView, Qt::LeftButton);
|
|
|
|
clickIndex(entryView->model()->index(2, 1), entryView, Qt::LeftButton, Qt::ControlModifier);
|
2013-10-08 16:11:40 -04:00
|
|
|
QCOMPARE(entryView->selectionModel()->selectedRows().size(), 2);
|
|
|
|
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Cancel);
|
2013-10-08 16:11:40 -04:00
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 3);
|
2013-10-08 16:14:02 -04:00
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1);
|
2013-10-08 16:11:40 -04:00
|
|
|
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Move);
|
2013-10-08 16:11:40 -04:00
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 1);
|
2013-10-08 16:14:02 -04:00
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3);
|
2013-10-08 16:11:40 -04:00
|
|
|
|
2013-10-08 16:36:27 -04:00
|
|
|
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
|
|
|
QModelIndex rootGroupIndex = groupView->model()->index(0, 0);
|
|
|
|
clickIndex(groupView->model()->index(groupView->model()->rowCount(rootGroupIndex) - 1, 0, rootGroupIndex),
|
2018-03-31 16:01:30 -04:00
|
|
|
groupView,
|
|
|
|
Qt::LeftButton);
|
2013-10-08 16:36:27 -04:00
|
|
|
QCOMPARE(groupView->currentGroup()->name(), m_db->metadata()->recycleBin()->name());
|
|
|
|
|
2017-12-21 04:32:07 -05:00
|
|
|
clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton);
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Cancel);
|
2013-10-08 16:36:27 -04:00
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 3);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3);
|
|
|
|
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Delete);
|
2013-10-08 16:36:27 -04:00
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 2);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 2);
|
|
|
|
|
2017-12-21 04:32:07 -05:00
|
|
|
clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton);
|
|
|
|
clickIndex(entryView->model()->index(1, 1), entryView, Qt::LeftButton, Qt::ControlModifier);
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Delete);
|
2013-10-08 16:36:27 -04:00
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 0);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 0);
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
clickIndex(groupView->model()->index(0, 0), groupView, Qt::LeftButton);
|
2013-10-08 16:36:27 -04:00
|
|
|
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
|
|
|
}
|
|
|
|
|
2012-07-21 18:00:44 -04:00
|
|
|
void TestGui::testCloneEntry()
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2018-12-28 18:32:25 -05:00
|
|
|
entryView->setFocus();
|
2012-07-21 18:00:44 -04:00
|
|
|
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 1);
|
|
|
|
|
|
|
|
QModelIndex item = entryView->model()->index(0, 1);
|
|
|
|
Entry* entryOrg = entryView->entryFromIndex(item);
|
2013-10-08 16:40:47 -04:00
|
|
|
clickIndex(item, entryView, Qt::LeftButton);
|
2012-07-21 18:00:44 -04:00
|
|
|
|
|
|
|
triggerAction("actionEntryClone");
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* cloneDialog = m_dbWidget->findChild<CloneDialog*>("CloneDialog");
|
|
|
|
auto* cloneButtonBox = cloneDialog->findChild<QDialogButtonBox*>("buttonBox");
|
2018-03-31 16:01:30 -04:00
|
|
|
QTest::mouseClick(cloneButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
2017-03-04 19:42:21 -05:00
|
|
|
|
2012-07-21 18:00:44 -04:00
|
|
|
QCOMPARE(entryView->model()->rowCount(), 2);
|
|
|
|
Entry* entryClone = entryView->entryFromIndex(entryView->model()->index(1, 1));
|
|
|
|
QVERIFY(entryOrg->uuid() != entryClone->uuid());
|
2017-01-25 20:02:32 -05:00
|
|
|
QCOMPARE(entryClone->title(), entryOrg->title() + QString(" - Clone"));
|
2012-07-21 18:00:44 -04:00
|
|
|
}
|
|
|
|
|
2017-03-16 15:31:14 -04:00
|
|
|
void TestGui::testEntryPlaceholders()
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2017-03-16 15:31:14 -04:00
|
|
|
|
|
|
|
// Find the new entry action
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
2017-03-16 15:31:14 -04:00
|
|
|
QVERIFY(entryNewAction->isEnabled());
|
|
|
|
|
|
|
|
// Find the button associated with the new entry action
|
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
|
|
|
|
QVERIFY(entryNewWidget->isVisible());
|
|
|
|
QVERIFY(entryNewWidget->isEnabled());
|
|
|
|
|
|
|
|
// Click the new entry button and check that we enter edit mode
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditMode);
|
2017-03-16 15:31:14 -04:00
|
|
|
|
|
|
|
// Add entry "test" and confirm added
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
2017-03-16 15:31:14 -04:00
|
|
|
QTest::keyClicks(titleEdit, "test");
|
|
|
|
QLineEdit* usernameEdit = editEntryWidget->findChild<QLineEdit*>("usernameEdit");
|
|
|
|
QTest::keyClicks(usernameEdit, "john");
|
|
|
|
QLineEdit* urlEdit = editEntryWidget->findChild<QLineEdit*>("urlEdit");
|
|
|
|
QTest::keyClicks(urlEdit, "{TITLE}.{USERNAME}");
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2017-03-16 15:31:14 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 2);
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
2017-03-16 15:31:14 -04:00
|
|
|
QModelIndex item = entryView->model()->index(1, 1);
|
|
|
|
Entry* entry = entryView->entryFromIndex(item);
|
|
|
|
|
|
|
|
QCOMPARE(entry->title(), QString("test"));
|
|
|
|
QCOMPARE(entry->url(), QString("{TITLE}.{USERNAME}"));
|
|
|
|
|
|
|
|
// Test password copy
|
2018-03-31 16:01:30 -04:00
|
|
|
QClipboard* clipboard = QApplication::clipboard();
|
2017-03-16 15:31:14 -04:00
|
|
|
m_dbWidget->copyURL();
|
|
|
|
QTRY_COMPARE(clipboard->text(), QString("test.john"));
|
|
|
|
}
|
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
void TestGui::testDragAndDropEntry()
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
|
|
|
auto* groupView = m_dbWidget->findChild<GroupView*>("groupView");
|
2012-07-17 17:29:25 -04:00
|
|
|
QAbstractItemModel* groupModel = groupView->model();
|
|
|
|
|
|
|
|
QModelIndex sourceIndex = entryView->model()->index(0, 1);
|
|
|
|
QModelIndex targetIndex = groupModel->index(0, 0, groupModel->index(0, 0));
|
|
|
|
QVERIFY(sourceIndex.isValid());
|
|
|
|
QVERIFY(targetIndex.isValid());
|
|
|
|
|
|
|
|
QMimeData mimeData;
|
|
|
|
QByteArray encoded;
|
|
|
|
QDataStream stream(&encoded, QIODevice::WriteOnly);
|
|
|
|
Entry* entry = entryView->entryFromIndex(sourceIndex);
|
|
|
|
stream << entry->group()->database()->uuid() << entry->uuid();
|
|
|
|
mimeData.setData("application/x-keepassx-entry", encoded);
|
|
|
|
|
|
|
|
QVERIFY(groupModel->dropMimeData(&mimeData, Qt::MoveAction, -1, 0, targetIndex));
|
|
|
|
QCOMPARE(entry->group()->name(), QString("General"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::testDragAndDropGroup()
|
|
|
|
{
|
2014-05-17 05:21:17 -04:00
|
|
|
QAbstractItemModel* groupModel = m_dbWidget->findChild<GroupView*>("groupView")->model();
|
2012-07-17 17:29:25 -04:00
|
|
|
QModelIndex rootIndex = groupModel->index(0, 0);
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
dragAndDropGroup(groupModel->index(0, 0, rootIndex), groupModel->index(1, 0, rootIndex), -1, true, "Windows", 0);
|
2012-07-17 17:29:25 -04:00
|
|
|
|
|
|
|
// dropping parent on child is supposed to fail
|
|
|
|
dragAndDropGroup(groupModel->index(0, 0, rootIndex),
|
2018-10-31 23:27:38 -04:00
|
|
|
groupModel->index(0, 0, groupModel->index(0, 0, rootIndex)),
|
|
|
|
-1,
|
|
|
|
false,
|
|
|
|
"NewDatabase",
|
|
|
|
0);
|
2012-07-17 17:29:25 -04:00
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
dragAndDropGroup(groupModel->index(1, 0, rootIndex), rootIndex, 0, true, "NewDatabase", 0);
|
2012-07-17 17:29:25 -04:00
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
dragAndDropGroup(groupModel->index(0, 0, rootIndex), rootIndex, -1, true, "NewDatabase", 4);
|
2012-07-17 17:29:25 -04:00
|
|
|
}
|
|
|
|
|
2012-07-06 13:21:19 -04:00
|
|
|
void TestGui::testSaveAs()
|
|
|
|
{
|
2017-01-03 22:27:41 -05:00
|
|
|
QFileInfo fileInfo(m_dbFilePath);
|
2012-07-06 13:21:19 -04:00
|
|
|
QDateTime lastModified = fileInfo.lastModified();
|
|
|
|
|
2018-05-13 17:21:43 -04:00
|
|
|
m_db->metadata()->setName("testSaveAs");
|
2012-07-06 13:21:19 -04:00
|
|
|
|
|
|
|
// open temporary file so it creates a filename
|
2018-10-19 14:10:37 -04:00
|
|
|
TemporaryFile tmpFile;
|
2016-11-02 21:01:02 -04:00
|
|
|
QVERIFY(tmpFile.open());
|
|
|
|
QString tmpFileName = tmpFile.fileName();
|
|
|
|
tmpFile.remove();
|
|
|
|
|
|
|
|
fileDialog()->setNextFileName(tmpFileName);
|
2012-07-06 13:21:19 -04:00
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionDatabaseSaveAs");
|
2012-07-06 13:21:19 -04:00
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_tabWidget->tabName(m_tabWidget->currentIndex()), QString("testSaveAs"));
|
2012-07-06 13:21:19 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
checkDatabase(tmpFileName);
|
2012-07-06 13:21:19 -04:00
|
|
|
|
|
|
|
fileInfo.refresh();
|
|
|
|
QCOMPARE(fileInfo.lastModified(), lastModified);
|
2018-09-29 13:00:47 -04:00
|
|
|
tmpFile.remove();
|
2012-07-06 13:21:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::testSave()
|
|
|
|
{
|
2018-05-13 17:21:43 -04:00
|
|
|
m_db->metadata()->setName("testSave");
|
|
|
|
|
2012-07-23 18:00:53 -04:00
|
|
|
// wait for modified timer
|
2018-05-13 17:21:43 -04:00
|
|
|
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("testSave*"));
|
2012-07-06 13:21:19 -04:00
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionDatabaseSave");
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_tabWidget->tabName(m_tabWidget->currentIndex()), QString("testSave"));
|
2012-07-06 13:21:19 -04:00
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
checkDatabase();
|
2012-07-06 13:21:19 -04:00
|
|
|
}
|
|
|
|
|
2012-07-17 04:35:17 -04:00
|
|
|
void TestGui::testDatabaseSettings()
|
|
|
|
{
|
2018-05-13 17:21:43 -04:00
|
|
|
m_db->metadata()->setName("testDatabaseSettings");
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionChangeDatabaseSettings");
|
2018-05-13 17:21:43 -04:00
|
|
|
auto* dbSettingsDialog = m_dbWidget->findChild<QWidget*>("databaseSettingsDialog");
|
|
|
|
auto* transformRoundsSpinBox = dbSettingsDialog->findChild<QSpinBox*>("transformRoundsSpinBox");
|
|
|
|
auto advancedToggle = dbSettingsDialog->findChild<QCheckBox*>("advancedSettingsToggle");
|
|
|
|
|
|
|
|
advancedToggle->setChecked(true);
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
2018-01-01 14:24:37 -05:00
|
|
|
QVERIFY(transformRoundsSpinBox != nullptr);
|
2018-01-06 11:06:51 -05:00
|
|
|
transformRoundsSpinBox->setValue(123456);
|
2012-07-17 04:35:17 -04:00
|
|
|
QTest::keyClick(transformRoundsSpinBox, Qt::Key_Enter);
|
2012-07-23 18:00:53 -04:00
|
|
|
// wait for modified timer
|
2018-05-13 17:21:43 -04:00
|
|
|
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("testDatabaseSettings*"));
|
2018-01-12 20:47:02 -05:00
|
|
|
QCOMPARE(m_db->kdf()->rounds(), 123456);
|
2012-07-17 04:35:17 -04:00
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionDatabaseSave");
|
2018-05-13 17:21:43 -04:00
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("testDatabaseSettings"));
|
|
|
|
|
|
|
|
advancedToggle->setChecked(false);
|
|
|
|
QApplication::processEvents();
|
2012-07-17 04:35:17 -04:00
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
checkDatabase();
|
2012-07-17 04:35:17 -04:00
|
|
|
}
|
|
|
|
|
2012-06-29 09:54:34 -04:00
|
|
|
void TestGui::testKeePass1Import()
|
|
|
|
{
|
|
|
|
fileDialog()->setNextFileName(QString(KEEPASSX_TEST_DATA_DIR).append("/basic.kdb"));
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionImportKeePass1");
|
2012-06-29 09:54:34 -04:00
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
auto* keepass1OpenWidget = m_tabWidget->currentDatabaseWidget()->findChild<QWidget*>("keepass1OpenWidget");
|
2018-05-13 17:21:43 -04:00
|
|
|
auto* editPassword = keepass1OpenWidget->findChild<QLineEdit*>("editPassword");
|
2012-06-29 09:54:34 -04:00
|
|
|
QVERIFY(editPassword);
|
|
|
|
|
|
|
|
QTest::keyClicks(editPassword, "masterpw");
|
|
|
|
QTest::keyClick(editPassword, Qt::Key_Enter);
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
QTRY_COMPARE(m_tabWidget->count(), 2);
|
|
|
|
QTRY_COMPARE(m_tabWidget->tabName(m_tabWidget->currentIndex()), QString("basic [New Database]*"));
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Close the KeePass1 Database
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::No);
|
2016-11-02 21:01:02 -04:00
|
|
|
triggerAction("actionDatabaseClose");
|
2018-09-29 13:00:47 -04:00
|
|
|
QApplication::processEvents();
|
2012-06-29 09:54:34 -04:00
|
|
|
}
|
|
|
|
|
2012-10-12 06:12:00 -04:00
|
|
|
void TestGui::testDatabaseLocking()
|
|
|
|
{
|
2016-11-02 21:01:02 -04:00
|
|
|
QString origDbName = m_tabWidget->tabText(0);
|
2015-01-11 10:20:59 -05:00
|
|
|
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::Cancel);
|
2012-10-12 06:12:00 -04:00
|
|
|
triggerAction("actionLockDatabases");
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_tabWidget->tabName(0), origDbName + " [Locked]");
|
2012-10-12 06:12:00 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* actionDatabaseMerge = m_mainWindow->findChild<QAction*>("actionDatabaseMerge", Qt::FindChildrenRecursively);
|
2018-04-30 17:07:07 -04:00
|
|
|
QCOMPARE(actionDatabaseMerge->isEnabled(), false);
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* actionDatabaseSave = m_mainWindow->findChild<QAction*>("actionDatabaseSave", Qt::FindChildrenRecursively);
|
2018-04-30 17:07:07 -04:00
|
|
|
QCOMPARE(actionDatabaseSave->isEnabled(), false);
|
|
|
|
|
2018-11-23 18:57:41 -05:00
|
|
|
DatabaseWidget* dbWidget = m_tabWidget->currentDatabaseWidget();
|
|
|
|
QVERIFY(dbWidget->isLocked());
|
|
|
|
auto* unlockDatabaseWidget = dbWidget->findChild<QWidget*>("databaseOpenWidget");
|
2012-10-12 06:12:00 -04:00
|
|
|
QWidget* editPassword = unlockDatabaseWidget->findChild<QLineEdit*>("editPassword");
|
|
|
|
QVERIFY(editPassword);
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
QTest::keyClicks(editPassword, "a");
|
2012-10-12 06:12:00 -04:00
|
|
|
QTest::keyClick(editPassword, Qt::Key_Enter);
|
|
|
|
|
2018-11-23 18:57:41 -05:00
|
|
|
QVERIFY(!dbWidget->isLocked());
|
2018-11-22 05:47:31 -05:00
|
|
|
QCOMPARE(m_tabWidget->tabName(0), origDbName);
|
2018-04-30 17:07:07 -04:00
|
|
|
|
|
|
|
actionDatabaseMerge = m_mainWindow->findChild<QAction*>("actionDatabaseMerge", Qt::FindChildrenRecursively);
|
|
|
|
QCOMPARE(actionDatabaseMerge->isEnabled(), true);
|
2012-10-12 06:12:00 -04:00
|
|
|
}
|
|
|
|
|
2017-12-22 13:05:33 -05:00
|
|
|
void TestGui::testDragAndDropKdbxFiles()
|
|
|
|
{
|
2018-03-31 16:01:30 -04:00
|
|
|
const int openedDatabasesCount = m_tabWidget->count();
|
2017-12-22 13:05:33 -05:00
|
|
|
|
|
|
|
const QString badDatabaseFilePath(QString(KEEPASSX_TEST_DATA_DIR).append("/NotDatabase.notkdbx"));
|
|
|
|
QMimeData badMimeData;
|
|
|
|
badMimeData.setUrls({QUrl::fromLocalFile(badDatabaseFilePath)});
|
|
|
|
QDragEnterEvent badDragEvent(QPoint(1, 1), Qt::LinkAction, &badMimeData, Qt::LeftButton, Qt::NoModifier);
|
2018-09-29 13:00:47 -04:00
|
|
|
qApp->notify(m_mainWindow.data(), &badDragEvent);
|
2017-12-22 13:05:33 -05:00
|
|
|
QCOMPARE(badDragEvent.isAccepted(), false);
|
|
|
|
|
|
|
|
QDropEvent badDropEvent(QPoint(1, 1), Qt::LinkAction, &badMimeData, Qt::LeftButton, Qt::NoModifier);
|
2018-09-29 13:00:47 -04:00
|
|
|
qApp->notify(m_mainWindow.data(), &badDropEvent);
|
2017-12-22 13:05:33 -05:00
|
|
|
QCOMPARE(badDropEvent.isAccepted(), false);
|
|
|
|
|
|
|
|
QCOMPARE(m_tabWidget->count(), openedDatabasesCount);
|
|
|
|
|
|
|
|
const QString goodDatabaseFilePath(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.kdbx"));
|
|
|
|
QMimeData goodMimeData;
|
|
|
|
goodMimeData.setUrls({QUrl::fromLocalFile(goodDatabaseFilePath)});
|
|
|
|
QDragEnterEvent goodDragEvent(QPoint(1, 1), Qt::LinkAction, &goodMimeData, Qt::LeftButton, Qt::NoModifier);
|
2018-09-29 13:00:47 -04:00
|
|
|
qApp->notify(m_mainWindow.data(), &goodDragEvent);
|
2017-12-22 13:05:33 -05:00
|
|
|
QCOMPARE(goodDragEvent.isAccepted(), true);
|
|
|
|
|
|
|
|
QDropEvent goodDropEvent(QPoint(1, 1), Qt::LinkAction, &goodMimeData, Qt::LeftButton, Qt::NoModifier);
|
2018-09-29 13:00:47 -04:00
|
|
|
qApp->notify(m_mainWindow.data(), &goodDropEvent);
|
2017-12-22 13:05:33 -05:00
|
|
|
QCOMPARE(goodDropEvent.isAccepted(), true);
|
|
|
|
|
|
|
|
QCOMPARE(m_tabWidget->count(), openedDatabasesCount + 1);
|
|
|
|
|
2018-12-19 23:14:11 -05:00
|
|
|
MessageBox::setNextAnswer(MessageBox::No);
|
2017-12-22 13:05:33 -05:00
|
|
|
triggerAction("actionDatabaseClose");
|
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
QTRY_COMPARE(m_tabWidget->count(), openedDatabasesCount);
|
2017-12-22 13:05:33 -05:00
|
|
|
}
|
|
|
|
|
2018-03-11 10:29:48 -04:00
|
|
|
void TestGui::testTrayRestoreHide()
|
|
|
|
{
|
2018-03-11 11:27:26 -04:00
|
|
|
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
|
|
|
|
QSKIP("QSystemTrayIcon::isSystemTrayAvailable() = false, skipping tray restore/hide test...");
|
|
|
|
}
|
2018-03-11 10:29:48 -04:00
|
|
|
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* trayIcon = m_mainWindow->findChild<QSystemTrayIcon*>();
|
2018-03-11 10:29:48 -04:00
|
|
|
QVERIFY(m_mainWindow->isVisible());
|
|
|
|
|
|
|
|
trayIcon->activated(QSystemTrayIcon::Trigger);
|
2018-09-29 13:00:47 -04:00
|
|
|
QTRY_VERIFY(!m_mainWindow->isVisible());
|
2018-03-11 10:29:48 -04:00
|
|
|
|
|
|
|
trayIcon->activated(QSystemTrayIcon::Trigger);
|
2018-09-29 13:00:47 -04:00
|
|
|
QTRY_VERIFY(m_mainWindow->isVisible());
|
2018-03-11 10:29:48 -04:00
|
|
|
|
|
|
|
trayIcon->activated(QSystemTrayIcon::Trigger);
|
2018-09-29 13:00:47 -04:00
|
|
|
QTRY_VERIFY(!m_mainWindow->isVisible());
|
2018-03-11 10:29:48 -04:00
|
|
|
|
|
|
|
trayIcon->activated(QSystemTrayIcon::Trigger);
|
2018-09-29 13:00:47 -04:00
|
|
|
QTRY_VERIFY(m_mainWindow->isVisible());
|
2011-12-29 14:10:19 -05:00
|
|
|
}
|
|
|
|
|
2017-10-28 09:23:45 -04:00
|
|
|
int TestGui::addCannedEntries()
|
|
|
|
{
|
|
|
|
int entries_added = 0;
|
|
|
|
|
|
|
|
// Find buttons
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2017-10-28 09:23:45 -04:00
|
|
|
QWidget* entryNewWidget = toolBar->widgetForAction(m_mainWindow->findChild<QAction*>("actionEntryNew"));
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
|
|
|
auto* passwordEdit = editEntryWidget->findChild<QLineEdit*>("passwordEdit");
|
|
|
|
auto* passwordRepeatEdit = editEntryWidget->findChild<QLineEdit*>("passwordRepeatEdit");
|
2017-10-28 09:23:45 -04:00
|
|
|
|
|
|
|
// Add entry "test" and confirm added
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "test");
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
2017-10-28 09:23:45 -04:00
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
++entries_added;
|
|
|
|
|
|
|
|
// Add entry "something 2"
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "something 2");
|
|
|
|
QTest::keyClicks(passwordEdit, "something 2");
|
|
|
|
QTest::keyClicks(passwordRepeatEdit, "something 2");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
++entries_added;
|
|
|
|
|
|
|
|
// Add entry "something 3"
|
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "something 3");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
++entries_added;
|
|
|
|
|
|
|
|
return entries_added;
|
|
|
|
}
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
void TestGui::checkDatabase(QString dbFileName)
|
2012-07-17 04:16:59 -04:00
|
|
|
{
|
2016-11-02 21:01:02 -04:00
|
|
|
if (dbFileName.isEmpty())
|
2017-01-03 22:27:41 -05:00
|
|
|
dbFileName = m_dbFilePath;
|
2016-11-02 21:01:02 -04:00
|
|
|
|
2018-05-13 17:21:43 -04:00
|
|
|
auto key = QSharedPointer<CompositeKey>::create();
|
|
|
|
key->addKey(QSharedPointer<PasswordKey>::create("a"));
|
2018-11-22 05:47:31 -05:00
|
|
|
auto dbSaved = QSharedPointer<Database>::create();
|
|
|
|
QVERIFY(dbSaved->open(dbFileName, key, nullptr, false));
|
2012-07-17 17:29:25 -04:00
|
|
|
QCOMPARE(dbSaved->metadata()->name(), m_db->metadata()->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::triggerAction(const QString& name)
|
|
|
|
{
|
2018-09-29 13:00:47 -04:00
|
|
|
auto* action = m_mainWindow->findChild<QAction*>(name);
|
2012-07-17 17:29:25 -04:00
|
|
|
QVERIFY(action);
|
|
|
|
QVERIFY(action->isEnabled());
|
|
|
|
action->trigger();
|
2018-05-13 17:21:43 -04:00
|
|
|
QApplication::processEvents();
|
2012-07-17 17:29:25 -04:00
|
|
|
}
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
void TestGui::dragAndDropGroup(const QModelIndex& sourceIndex,
|
|
|
|
const QModelIndex& targetIndex,
|
|
|
|
int row,
|
|
|
|
bool expectedResult,
|
|
|
|
const QString& expectedParentName,
|
|
|
|
int expectedPos)
|
2012-07-17 17:29:25 -04:00
|
|
|
{
|
|
|
|
QVERIFY(sourceIndex.isValid());
|
|
|
|
QVERIFY(targetIndex.isValid());
|
|
|
|
|
2018-01-06 18:30:18 -05:00
|
|
|
auto groupModel = qobject_cast<GroupModel*>(m_dbWidget->findChild<GroupView*>("groupView")->model());
|
2012-07-17 17:29:25 -04:00
|
|
|
|
|
|
|
QMimeData mimeData;
|
|
|
|
QByteArray encoded;
|
|
|
|
QDataStream stream(&encoded, QIODevice::WriteOnly);
|
|
|
|
Group* group = groupModel->groupFromIndex(sourceIndex);
|
|
|
|
stream << group->database()->uuid() << group->uuid();
|
|
|
|
mimeData.setData("application/x-keepassx-group", encoded);
|
|
|
|
|
|
|
|
QCOMPARE(groupModel->dropMimeData(&mimeData, Qt::MoveAction, row, 0, targetIndex), expectedResult);
|
|
|
|
QCOMPARE(group->parentGroup()->name(), expectedParentName);
|
|
|
|
QCOMPARE(group->parentGroup()->children().indexOf(group), expectedPos);
|
2012-07-17 04:16:59 -04:00
|
|
|
}
|
|
|
|
|
2018-03-31 16:01:30 -04:00
|
|
|
void TestGui::clickIndex(const QModelIndex& index,
|
|
|
|
QAbstractItemView* view,
|
|
|
|
Qt::MouseButton button,
|
2013-10-08 16:36:27 -04:00
|
|
|
Qt::KeyboardModifiers stateKey)
|
|
|
|
{
|
|
|
|
QTest::mouseClick(view->viewport(), button, stateKey, view->visualRect(index).center());
|
|
|
|
}
|