2011-12-26 13:18:21 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QAction>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QLineEdit>
|
2016-11-23 21:59:24 -05:00
|
|
|
#include <QLabel>
|
2015-07-22 11:03:59 -04:00
|
|
|
#include <QMimeData>
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QTest>
|
|
|
|
#include <QToolBar>
|
|
|
|
#include <QToolButton>
|
2016-11-02 21:01:02 -04:00
|
|
|
#include <QTimer>
|
2016-11-07 22:37:42 -05:00
|
|
|
#include <QSignalSpy>
|
2016-12-23 12:13:08 -05:00
|
|
|
#include <QClipboard>
|
|
|
|
#include <QDebug>
|
2011-12-26 13:18:21 -05:00
|
|
|
|
|
|
|
#include "config-keepassx-tests.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"
|
|
|
|
#include "format/KeePass2Reader.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"
|
|
|
|
#include "gui/MainWindow.h"
|
2013-10-08 16:11:40 -04:00
|
|
|
#include "gui/MessageBox.h"
|
2016-11-28 19:02:21 -05:00
|
|
|
#include "gui/SearchWidget.h"
|
2012-05-16 04:16:32 -04:00
|
|
|
#include "gui/entry/EditEntryWidget.h"
|
|
|
|
#include "gui/entry/EntryView.h"
|
2012-07-17 17:29:25 -04:00
|
|
|
#include "gui/group/GroupModel.h"
|
|
|
|
#include "gui/group/GroupView.h"
|
2012-07-06 13:21:19 -04:00
|
|
|
#include "keys/PasswordKey.h"
|
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();
|
2011-12-29 14:10:19 -05:00
|
|
|
m_mainWindow = new 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-09-12 17:12:17 -04:00
|
|
|
m_mainWindow->activateWindow();
|
2012-11-02 06:08:41 -04:00
|
|
|
Tools::wait(50);
|
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
|
|
|
QByteArray tmpData;
|
|
|
|
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()
|
|
|
|
{
|
2016-11-02 21:01:02 -04:00
|
|
|
// Write the temp storage to a temp database file for use in our tests
|
|
|
|
QVERIFY(m_dbFile.open());
|
2016-11-11 17:58:47 -05:00
|
|
|
QCOMPARE(m_dbFile.write(m_dbData), static_cast<qint64>((m_dbData.size())));
|
2016-11-02 21:01:02 -04:00
|
|
|
m_dbFile.close();
|
|
|
|
|
2017-01-03 22:27:41 -05:00
|
|
|
m_dbFileName = m_dbFile.fileName();
|
|
|
|
m_dbFilePath = m_dbFile.filePath();
|
2011-12-26 13:18:21 -05:00
|
|
|
|
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
|
|
|
|
2012-06-28 03:21:15 -04:00
|
|
|
QWidget* databaseOpenWidget = m_mainWindow->findChild<QWidget*>("databaseOpenWidget");
|
|
|
|
QLineEdit* editPassword = databaseOpenWidget->findChild<QLineEdit*>("editPassword");
|
2011-12-26 13:18:21 -05:00
|
|
|
QVERIFY(editPassword);
|
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
|
|
|
Tools::wait(100);
|
|
|
|
|
|
|
|
QVERIFY(m_tabWidget->currentDatabaseWidget());
|
|
|
|
|
|
|
|
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
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::No);
|
|
|
|
triggerAction("actionDatabaseClose");
|
|
|
|
Tools::wait(100);
|
|
|
|
|
|
|
|
m_db = nullptr;
|
|
|
|
m_dbWidget = nullptr;
|
2011-12-29 14:10:19 -05:00
|
|
|
}
|
2011-12-26 13:18:21 -05: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
|
|
|
|
QSignalSpy dbMergeSpy(m_dbWidget, SIGNAL(databaseMerged(Database*)));
|
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");
|
|
|
|
|
|
|
|
QWidget* databaseOpenMergeWidget = m_mainWindow->findChild<QWidget*>("databaseOpenMergeWidget");
|
|
|
|
QLineEdit* editPasswordMerge = databaseOpenMergeWidget->findChild<QLineEdit*>("editPassword");
|
|
|
|
QVERIFY(editPasswordMerge->isVisible());
|
|
|
|
|
|
|
|
m_tabWidget->currentDatabaseWidget()->setCurrentWidget(databaseOpenMergeWidget);
|
|
|
|
|
|
|
|
QTest::keyClicks(editPasswordMerge, "a");
|
|
|
|
QTest::keyClick(editPasswordMerge, Qt::Key_Enter);
|
|
|
|
|
|
|
|
QTRY_COMPARE(dbMergeSpy.count(), 1);
|
|
|
|
QTRY_VERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).contains("*"));
|
|
|
|
|
|
|
|
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
|
|
|
|
QByteArray tmpData;
|
|
|
|
QFile mergeDbFile(QString(KEEPASSX_TEST_DATA_DIR).append("/MergeDatabase.kdbx"));
|
|
|
|
QVERIFY(mergeDbFile.open(QIODevice::ReadOnly));
|
|
|
|
QVERIFY(Tools::readAllFromDevice(&mergeDbFile, tmpData));
|
|
|
|
mergeDbFile.close();
|
|
|
|
|
|
|
|
// Test accepting new file in autoreload
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::Yes);
|
|
|
|
// Overwrite the current database with the temp data
|
|
|
|
QVERIFY(m_dbFile.open());
|
|
|
|
QVERIFY(m_dbFile.write(tmpData, static_cast<qint64>(tmpData.size())));
|
|
|
|
m_dbFile.close();
|
|
|
|
Tools::wait(1500);
|
|
|
|
|
|
|
|
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);
|
|
|
|
QVERIFY(! m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*"));
|
|
|
|
|
|
|
|
// Reset the state
|
|
|
|
cleanup();
|
|
|
|
init();
|
|
|
|
|
|
|
|
// Test rejecting new file in autoreload
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::No);
|
|
|
|
// Overwrite the current temp database with a new file
|
|
|
|
m_dbFile.open();
|
|
|
|
QVERIFY(m_dbFile.write(tmpData, static_cast<qint64>(tmpData.size())));
|
|
|
|
m_dbFile.close();
|
|
|
|
Tools::wait(1500);
|
|
|
|
|
|
|
|
m_db = m_dbWidget->database();
|
|
|
|
|
|
|
|
// Ensure the merge did not take place
|
|
|
|
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 0);
|
|
|
|
QVERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*"));
|
|
|
|
|
|
|
|
// Reset the state
|
|
|
|
cleanup();
|
|
|
|
init();
|
|
|
|
|
|
|
|
// Test accepting a merge of edits into autoreload
|
|
|
|
// 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
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::Yes);
|
|
|
|
// Overwrite the current database with the temp data
|
|
|
|
QVERIFY(m_dbFile.open());
|
|
|
|
QVERIFY(m_dbFile.write(tmpData, static_cast<qint64>(tmpData.size())));
|
|
|
|
m_dbFile.close();
|
|
|
|
Tools::wait(1500);
|
|
|
|
|
|
|
|
m_db = m_dbWidget->database();
|
|
|
|
|
|
|
|
QCOMPARE(m_db->rootGroup()->findChildByName("General")->entries().size(), 1);
|
|
|
|
QVERIFY(m_tabWidget->tabText(m_tabWidget->currentIndex()).endsWith("*"));
|
|
|
|
}
|
|
|
|
|
2011-12-29 14:10:19 -05:00
|
|
|
void TestGui::testTabs()
|
|
|
|
{
|
2012-07-06 13:21:19 -04:00
|
|
|
QCOMPARE(m_tabWidget->count(), 1);
|
2016-11-02 21:01:02 -04:00
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), m_dbFileName);
|
2011-12-26 13:18:21 -05:00
|
|
|
}
|
|
|
|
|
2012-04-14 14:31:35 -04:00
|
|
|
void TestGui::testEditEntry()
|
|
|
|
{
|
2016-11-02 21:01:02 -04:00
|
|
|
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
|
|
|
|
// Select the first entry in the database
|
2014-05-17 05:21:17 -04:00
|
|
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2016-11-02 21:01:02 -04:00
|
|
|
QModelIndex entryItem = entryView->model()->index(0, 1);
|
|
|
|
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
|
2012-04-26 11:52:02 -04:00
|
|
|
QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
|
|
|
|
QVERIFY(entryEditAction->isEnabled());
|
|
|
|
QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
|
|
|
|
QVERIFY(entryEditWidget->isVisible());
|
|
|
|
QVERIFY(entryEditWidget->isEnabled());
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Edit the first entry ("Sample Entry")
|
|
|
|
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);
|
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");
|
|
|
|
QTest::keyClicks(titleEdit, "_test");
|
|
|
|
|
|
|
|
// Save the edit
|
2012-04-14 14:31:35 -04:00
|
|
|
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Confirm edit was made
|
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode);
|
|
|
|
Entry* entry = entryView->entryFromIndex(entryItem);
|
|
|
|
QCOMPARE(entry->title(), QString("Sample Entry_test"));
|
|
|
|
QCOMPARE(entry->historyItems().size(), 1);
|
|
|
|
|
|
|
|
// Confirm modified indicator is showing
|
|
|
|
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("%1*").arg(m_dbFileName));
|
2012-04-14 14:31:35 -04:00
|
|
|
}
|
|
|
|
|
2012-05-10 04:29:25 -04:00
|
|
|
void TestGui::testAddEntry()
|
|
|
|
{
|
2016-11-02 21:01:02 -04:00
|
|
|
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2012-07-17 04:16:59 -04:00
|
|
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Find the new entry action
|
2012-05-10 04:29:25 -04:00
|
|
|
QAction* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
|
|
|
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);
|
2012-07-17 04:16:59 -04:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);
|
2012-05-10 04:29:25 -04:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Add entry "test" and confirm added
|
2012-07-17 04:16:59 -04:00
|
|
|
EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
2012-05-10 04:29:25 -04:00
|
|
|
QLineEdit* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
|
|
|
QTest::keyClicks(titleEdit, "test");
|
|
|
|
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
2012-07-17 04:16:59 -04:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::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");
|
2016-12-23 12:13:08 -05:00
|
|
|
QLineEdit* passwordEdit = editEntryWidget->findChild<QLineEdit*>("passwordEdit");
|
|
|
|
QLineEdit* passwordRepeatEdit = editEntryWidget->findChild<QLineEdit*>("passwordRepeatEdit");
|
|
|
|
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);
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Add entry "something 3"
|
2013-10-08 16:11:40 -04:00
|
|
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
|
|
|
QTest::keyClicks(titleEdit, "something 3");
|
|
|
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
// Confirm that 4 entries now exist
|
2013-10-08 16:11:40 -04:00
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 4);
|
2012-05-10 04:29:25 -04:00
|
|
|
}
|
|
|
|
|
2016-11-23 21:59:24 -05:00
|
|
|
void TestGui::testEntryEntropy()
|
|
|
|
{
|
|
|
|
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
|
|
|
|
// Find the new entry action
|
|
|
|
QAction* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
|
|
|
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);
|
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);
|
|
|
|
|
|
|
|
// Add entry "test" and confirm added
|
|
|
|
EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
|
|
|
QLineEdit* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
|
|
|
QTest::keyClicks(titleEdit, "test");
|
|
|
|
|
|
|
|
// Open the password generator
|
2017-01-14 14:33:27 -05:00
|
|
|
QToolButton* generatorButton = editEntryWidget->findChild<QToolButton*>("togglePasswordGeneratorButton");
|
2016-11-23 21:59:24 -05:00
|
|
|
QTest::mouseClick(generatorButton, Qt::LeftButton);
|
|
|
|
|
|
|
|
// Type in some password
|
|
|
|
QLineEdit* editNewPassword = editEntryWidget->findChild<QLineEdit*>("editNewPassword");
|
|
|
|
QLabel* entropyLabel = editEntryWidget->findChild<QLabel*>("entropyLabel");
|
|
|
|
QLabel* strengthLabel = editEntryWidget->findChild<QLabel*>("strengthLabel");
|
|
|
|
|
|
|
|
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");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 47.98 bit"));
|
|
|
|
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");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 96.07 bit"));
|
|
|
|
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");
|
|
|
|
QCOMPARE(entropyLabel->text(), QString("Entropy: 174.59 bit"));
|
|
|
|
QCOMPARE(strengthLabel->text(), QString("Password Quality: Excellent"));
|
2016-12-23 12:13:08 -05:00
|
|
|
|
2016-11-23 21:59:24 -05:00
|
|
|
// We are done
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
testAddEntry();
|
|
|
|
|
2012-05-19 05:53:32 -04:00
|
|
|
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
2012-05-16 03:56:40 -04:00
|
|
|
|
2016-11-28 19:02:21 -05:00
|
|
|
SearchWidget* searchWidget = toolBar->findChild<SearchWidget*>("SearchWidget");
|
|
|
|
QVERIFY(searchWidget->isEnabled());
|
|
|
|
QLineEdit* searchTextEdit = searchWidget->findChild<QLineEdit*>("searchEdit");
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
|
|
|
QVERIFY(entryView->isVisible());
|
2012-05-16 03:56:40 -04:00
|
|
|
|
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());
|
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"));
|
2016-11-02 21:01:02 -04:00
|
|
|
QTRY_VERIFY(m_dbWidget->isInSearchMode());
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 0);
|
|
|
|
// Escape clears searchedit and retains focus
|
2016-11-28 19:02:21 -05:00
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Escape);
|
|
|
|
QTRY_VERIFY(searchTextEdit->text().isEmpty());
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
2016-11-02 21:01:02 -04:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode);
|
2014-11-18 02:26:04 -05:00
|
|
|
// Search for "some"
|
2016-11-28 19:02:21 -05:00
|
|
|
QTest::keyClicks(searchTextEdit, "some");
|
2016-11-02 21:01:02 -04:00
|
|
|
QTRY_VERIFY(m_dbWidget->isInSearchMode());
|
|
|
|
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
|
|
|
|
QTest::keyClick(m_mainWindow, Qt::Key_F, Qt::ControlModifier);
|
|
|
|
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());
|
|
|
|
// Refocus back to search edit
|
|
|
|
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
|
|
|
QTRY_VERIFY(searchTextEdit->hasFocus());
|
|
|
|
// Test password copy
|
2016-12-23 12:13:08 -05:00
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
2017-01-04 20:46:52 -05:00
|
|
|
QTest::keyClick(searchTextEdit, 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());
|
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
|
|
|
|
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"));
|
|
|
|
QTRY_COMPARE(entryView->model()->rowCount(), 0);
|
|
|
|
// reset
|
|
|
|
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());
|
|
|
|
QVERIFY(m_dbWidget->isInSearchMode());
|
|
|
|
|
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);
|
2012-07-17 04:16:59 -04:00
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::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
|
2016-11-02 21:01:02 -04:00
|
|
|
QTRY_VERIFY(m_dbWidget->isInSearchMode());
|
|
|
|
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
|
2016-11-28 19:02:21 -05:00
|
|
|
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
|
|
|
QTest::keyClick(searchTextEdit, Qt::Key_Escape);
|
2016-11-02 21:01:02 -04:00
|
|
|
QTRY_COMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::testDeleteEntry()
|
|
|
|
{
|
|
|
|
// Add canned entries for consistent testing
|
|
|
|
testAddEntry();
|
|
|
|
|
|
|
|
GroupView* groupView = m_dbWidget->findChild<GroupView*>("groupView");
|
|
|
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
|
|
|
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
|
|
|
QAction* entryDeleteAction = m_mainWindow->findChild<QAction*>("actionEntryDelete");
|
2012-05-16 03:56:40 -04:00
|
|
|
QWidget* entryDeleteWidget = toolBar->widgetForAction(entryDeleteAction);
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode);
|
|
|
|
clickIndex(entryView->model()->index(1, 0), 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
|
|
|
|
2016-09-02 06:00:12 -04:00
|
|
|
MessageBox::setNextAnswer(QMessageBox::Yes);
|
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
|
|
|
|
2013-10-08 16:40:47 -04:00
|
|
|
clickIndex(entryView->model()->index(1, 0), entryView, Qt::LeftButton);
|
|
|
|
clickIndex(entryView->model()->index(2, 0), entryView, Qt::LeftButton, Qt::ControlModifier);
|
2013-10-08 16:11:40 -04:00
|
|
|
QCOMPARE(entryView->selectionModel()->selectedRows().size(), 2);
|
|
|
|
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::No);
|
|
|
|
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
|
|
|
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::Yes);
|
|
|
|
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),
|
|
|
|
groupView, Qt::LeftButton);
|
|
|
|
QCOMPARE(groupView->currentGroup()->name(), m_db->metadata()->recycleBin()->name());
|
|
|
|
|
|
|
|
clickIndex(entryView->model()->index(0, 0), entryView, Qt::LeftButton);
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::No);
|
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 3);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3);
|
|
|
|
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::Yes);
|
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 2);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 2);
|
|
|
|
|
|
|
|
clickIndex(entryView->model()->index(0, 0), entryView, Qt::LeftButton);
|
|
|
|
clickIndex(entryView->model()->index(1, 0), entryView, Qt::LeftButton, Qt::ControlModifier);
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::Yes);
|
|
|
|
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 0);
|
|
|
|
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 0);
|
|
|
|
|
|
|
|
clickIndex(groupView->model()->index(0, 0),
|
|
|
|
groupView, Qt::LeftButton);
|
|
|
|
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
|
|
|
}
|
|
|
|
|
2012-07-21 18:00:44 -04:00
|
|
|
void TestGui::testCloneEntry()
|
|
|
|
{
|
2014-05-17 05:21:17 -04:00
|
|
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
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");
|
|
|
|
|
|
|
|
QCOMPARE(entryView->model()->rowCount(), 2);
|
|
|
|
Entry* entryClone = entryView->entryFromIndex(entryView->model()->index(1, 1));
|
|
|
|
QVERIFY(entryOrg->uuid() != entryClone->uuid());
|
|
|
|
QCOMPARE(entryClone->title(), entryOrg->title());
|
|
|
|
}
|
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
void TestGui::testDragAndDropEntry()
|
|
|
|
{
|
2014-05-17 05:21:17 -04:00
|
|
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
|
|
|
GroupView* 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);
|
|
|
|
|
|
|
|
dragAndDropGroup(groupModel->index(0, 0, rootIndex),
|
|
|
|
groupModel->index(1, 0, rootIndex),
|
|
|
|
-1, true, "Windows", 0);
|
|
|
|
|
|
|
|
// dropping parent on child is supposed to fail
|
|
|
|
dragAndDropGroup(groupModel->index(0, 0, rootIndex),
|
|
|
|
groupModel->index(0, 0, groupModel->index(0, 0, rootIndex)),
|
|
|
|
-1, false, "NewDatabase", 0);
|
|
|
|
|
|
|
|
dragAndDropGroup(groupModel->index(1, 0, rootIndex),
|
|
|
|
rootIndex,
|
|
|
|
0, true, "NewDatabase", 0);
|
|
|
|
|
|
|
|
dragAndDropGroup(groupModel->index(0, 0, rootIndex),
|
|
|
|
rootIndex,
|
2016-11-02 21:01:02 -04:00
|
|
|
-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();
|
|
|
|
|
2012-07-17 04:16:59 -04:00
|
|
|
m_db->metadata()->setName("SaveAs");
|
2012-07-06 13:21:19 -04:00
|
|
|
|
|
|
|
// open temporary file so it creates a filename
|
2016-11-02 21:01:02 -04:00
|
|
|
QTemporaryFile tmpFile;
|
|
|
|
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
|
|
|
|
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("SaveAs"));
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
checkDatabase(tmpFileName);
|
2012-07-06 13:21:19 -04:00
|
|
|
|
|
|
|
fileInfo.refresh();
|
|
|
|
QCOMPARE(fileInfo.lastModified(), lastModified);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::testSave()
|
|
|
|
{
|
2012-07-17 04:16:59 -04:00
|
|
|
m_db->metadata()->setName("Save");
|
2012-07-23 18:00:53 -04:00
|
|
|
// wait for modified timer
|
|
|
|
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save*"));
|
2012-07-06 13:21:19 -04:00
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionDatabaseSave");
|
2012-07-06 13:21:19 -04:00
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save"));
|
|
|
|
|
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()
|
|
|
|
{
|
2017-01-03 22:27:41 -05:00
|
|
|
m_db->metadata()->setName("Save");
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionChangeDatabaseSettings");
|
2012-07-17 04:35:17 -04:00
|
|
|
QWidget* dbSettingsWidget = m_dbWidget->findChild<QWidget*>("databaseSettingsWidget");
|
|
|
|
QSpinBox* transformRoundsSpinBox = dbSettingsWidget->findChild<QSpinBox*>("transformRoundsSpinBox");
|
|
|
|
transformRoundsSpinBox->setValue(100);
|
|
|
|
QTest::keyClick(transformRoundsSpinBox, Qt::Key_Enter);
|
2012-07-23 18:00:53 -04:00
|
|
|
// wait for modified timer
|
|
|
|
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save*"));
|
2012-07-17 04:35:17 -04:00
|
|
|
QCOMPARE(m_db->transformRounds(), Q_UINT64_C(100));
|
|
|
|
|
2012-07-17 17:29:25 -04:00
|
|
|
triggerAction("actionDatabaseSave");
|
2012-07-17 04:35:17 -04:00
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("Save"));
|
|
|
|
|
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
|
|
|
|
|
|
|
QWidget* keepass1OpenWidget = m_mainWindow->findChild<QWidget*>("keepass1OpenWidget");
|
|
|
|
QLineEdit* editPassword = keepass1OpenWidget->findChild<QLineEdit*>("editPassword");
|
|
|
|
QVERIFY(editPassword);
|
|
|
|
|
|
|
|
QTest::keyClicks(editPassword, "masterpw");
|
|
|
|
QTest::keyClick(editPassword, Qt::Key_Enter);
|
|
|
|
|
2012-07-06 13:21:19 -04:00
|
|
|
QCOMPARE(m_tabWidget->count(), 2);
|
|
|
|
QCOMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("basic [New database]*"));
|
2016-11-02 21:01:02 -04:00
|
|
|
|
|
|
|
// Close the KeePass1 Database
|
|
|
|
MessageBox::setNextAnswer(QMessageBox::No);
|
|
|
|
triggerAction("actionDatabaseClose");
|
|
|
|
Tools::wait(100);
|
|
|
|
|
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
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
MessageBox::setNextAnswer(QMessageBox::Cancel);
|
2012-10-12 06:12:00 -04:00
|
|
|
triggerAction("actionLockDatabases");
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
QCOMPARE(m_tabWidget->tabText(0).remove('&'), origDbName + " [locked]");
|
2012-10-12 06:12:00 -04:00
|
|
|
|
|
|
|
QWidget* dbWidget = m_tabWidget->currentDatabaseWidget();
|
|
|
|
QWidget* unlockDatabaseWidget = dbWidget->findChild<QWidget*>("unlockDatabaseWidget");
|
|
|
|
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);
|
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
QCOMPARE(m_tabWidget->tabText(0).remove('&'), origDbName);
|
2012-10-12 06:12:00 -04:00
|
|
|
}
|
|
|
|
|
2011-12-29 14:10:19 -05:00
|
|
|
void TestGui::cleanupTestCase()
|
|
|
|
{
|
2012-04-18 16:08:22 -04:00
|
|
|
delete m_mainWindow;
|
2011-12-29 14:10:19 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-07-17 04:16:59 -04:00
|
|
|
CompositeKey key;
|
|
|
|
key.addKey(PasswordKey("a"));
|
|
|
|
KeePass2Reader reader;
|
2016-11-02 21:01:02 -04:00
|
|
|
QScopedPointer<Database> dbSaved(reader.readDatabase(dbFileName, key));
|
2012-07-17 17:29:25 -04:00
|
|
|
QVERIFY(dbSaved);
|
|
|
|
QVERIFY(!reader.hasError());
|
|
|
|
QCOMPARE(dbSaved->metadata()->name(), m_db->metadata()->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::triggerAction(const QString& name)
|
|
|
|
{
|
|
|
|
QAction* action = m_mainWindow->findChild<QAction*>(name);
|
|
|
|
QVERIFY(action);
|
|
|
|
QVERIFY(action->isEnabled());
|
|
|
|
action->trigger();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGui::dragAndDropGroup(const QModelIndex& sourceIndex, const QModelIndex& targetIndex, int row,
|
|
|
|
bool expectedResult, const QString& expectedParentName, int expectedPos)
|
|
|
|
{
|
|
|
|
QVERIFY(sourceIndex.isValid());
|
|
|
|
QVERIFY(targetIndex.isValid());
|
|
|
|
|
2014-05-17 05:21:17 -04:00
|
|
|
GroupModel* 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
|
|
|
}
|
|
|
|
|
2013-10-08 16:36:27 -04:00
|
|
|
void TestGui::clickIndex(const QModelIndex& index, QAbstractItemView* view, Qt::MouseButton button,
|
|
|
|
Qt::KeyboardModifiers stateKey)
|
|
|
|
{
|
|
|
|
QTest::mouseClick(view->viewport(), button, stateKey, view->visualRect(index).center());
|
|
|
|
}
|
|
|
|
|
2012-07-23 18:07:28 -04:00
|
|
|
QTEST_MAIN(TestGui)
|