Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonathan White <support@dmapps.us>2020-05-11 04:20:00 +0300
committerJonathan White <support@dmapps.us>2020-05-15 00:14:17 +0300
commita145bf91191f0a4630a7e31654aff8a8dfd09bf0 (patch)
tree70cb911c31cb1cf3362129a85fce64f80b898324 /tests
parent3b4057a78ca07d4a3424137b0f17e9a14301da3c (diff)
Complete refactor of Browser Integration classes
* Removed option to attach KeePassXC to the browser extension. Users must use the proxy application to communicate with KeePassXC. * Significantly streamlined proxy code. Used same implementation of stdin/stdout interface across all platforms. * Moved browser service entry point to BrowserService class instead of NativeMessagingHost. BrowserService now coordinates the communication to/from clients. * Moved settings page definition out of MainWindow * Decoupled BrowserService from DatabaseTabWidget * Reduced complexity of various functions and cleaned the ABI (public vs private). * Eliminated BrowserClients class, moved functionality into the BrowserService * Renamed HostInstaller to NativeMessageInstaller and renamed NativeMessageHost to BrowserHost. * Recognize XDG_CONFIG_HOME when installing native message file on Linux. Fix #4121 and fix #4123.
Diffstat (limited to 'tests')
-rw-r--r--tests/TestBrowser.cpp66
-rw-r--r--tests/TestBrowser.h5
-rw-r--r--tests/data/NewDatabaseBrowser.kdbxbin16743 -> 17463 bytes
-rw-r--r--tests/gui/TestGuiBrowser.cpp38
-rw-r--r--tests/gui/TestGuiBrowser.h4
5 files changed, 34 insertions, 79 deletions
diff --git a/tests/TestBrowser.cpp b/tests/TestBrowser.cpp
index 5ddb5e898..5b2f61178 100644
--- a/tests/TestBrowser.cpp
+++ b/tests/TestBrowser.cpp
@@ -16,11 +16,13 @@
*/
#include "TestBrowser.h"
+
#include "TestGlobal.h"
#include "browser/BrowserSettings.h"
#include "core/Tools.h"
#include "crypto/Crypto.h"
#include "sodium/crypto_box.h"
+
#include <QString>
QTEST_GUILESS_MAIN(TestBrowser)
@@ -35,12 +37,12 @@ const QString CLIENTID = "testClient";
void TestBrowser::initTestCase()
{
QVERIFY(Crypto::init());
- m_browserService.reset(new BrowserService(nullptr));
- m_browserAction.reset(new BrowserAction(*m_browserService.data()));
+ m_browserService = browserService();
}
-void TestBrowser::cleanupTestCase()
+void TestBrowser::init()
{
+ m_browserAction.reset(new BrowserAction());
}
/**
@@ -54,7 +56,7 @@ void TestBrowser::testChangePublicKeys()
json["publicKey"] = PUBLICKEY;
json["nonce"] = NONCE;
- auto response = m_browserAction->handleAction(json);
+ auto response = m_browserAction->processClientMessage(json);
QCOMPARE(response["action"].toString(), QString("change-public-keys"));
QCOMPARE(response["publicKey"].toString() == PUBLICKEY, false);
QCOMPARE(response["success"].toString(), TRUE_STR);
@@ -393,62 +395,6 @@ void TestBrowser::testSortEntries()
QCOMPARE(result[3]->url(), QString("github.com/login"));
}
-void TestBrowser::testGetDatabaseGroups()
-{
- auto db = QSharedPointer<Database>::create();
- auto* root = db->rootGroup();
-
- QScopedPointer<Group> group1(new Group());
- group1->setParent(root);
- group1->setName("group1");
-
- QScopedPointer<Group> group2(new Group());
- group2->setParent(root);
- group2->setName("group2");
-
- QScopedPointer<Group> group3(new Group());
- group3->setParent(root);
- group3->setName("group3");
-
- QScopedPointer<Group> group2_1(new Group());
- group2_1->setParent(group2.data());
- group2_1->setName("group2_1");
-
- QScopedPointer<Group> group2_2(new Group());
- group2_2->setParent(group2.data());
- group2_2->setName("group2_2");
-
- QScopedPointer<Group> group2_1_1(new Group());
- group2_1_1->setParent(group2_1.data());
- group2_1_1->setName("group2_1_1");
-
- auto result = m_browserService->getDatabaseGroups(db);
- QCOMPARE(result.length(), 1);
-
- auto groups = result["groups"].toArray();
- auto first = groups.at(0);
- auto children = first.toObject()["children"].toArray();
- QCOMPARE(first.toObject()["name"].toString(), QString("Root"));
- QCOMPARE(children.size(), 3);
-
- auto firstChild = children.at(0);
- auto secondChild = children.at(1);
- auto thirdChild = children.at(2);
- QCOMPARE(firstChild.toObject()["name"].toString(), QString("group1"));
- QCOMPARE(secondChild.toObject()["name"].toString(), QString("group2"));
- QCOMPARE(thirdChild.toObject()["name"].toString(), QString("group3"));
-
- auto childrenOfSecond = secondChild.toObject()["children"].toArray();
- auto firstOfCOS = childrenOfSecond.at(0);
- auto secondOfCOS = childrenOfSecond.at(1);
- QCOMPARE(firstOfCOS.toObject()["name"].toString(), QString("group2_1"));
- QCOMPARE(secondOfCOS.toObject()["name"].toString(), QString("group2_2"));
-
- auto lastChildren = firstOfCOS.toObject()["children"].toArray();
- auto lastChild = lastChildren.at(0);
- QCOMPARE(lastChild.toObject()["name"].toString(), QString("group2_1_1"));
-}
-
QList<Entry*> TestBrowser::createEntries(QStringList& urls, Group* root) const
{
QList<Entry*> entries;
diff --git a/tests/TestBrowser.h b/tests/TestBrowser.h
index 69ba69309..00f9d7528 100644
--- a/tests/TestBrowser.h
+++ b/tests/TestBrowser.h
@@ -30,7 +30,7 @@ class TestBrowser : public QObject
private slots:
void initTestCase();
- void cleanupTestCase();
+ void init();
void testChangePublicKeys();
void testEncryptMessage();
@@ -46,14 +46,13 @@ private slots:
void testInvalidEntries();
void testSubdomainsAndPaths();
void testSortEntries();
- void testGetDatabaseGroups();
void testValidURLs();
private:
QList<Entry*> createEntries(QStringList& urls, Group* root) const;
QScopedPointer<BrowserAction> m_browserAction;
- QScopedPointer<BrowserService> m_browserService;
+ QPointer<BrowserService> m_browserService;
};
#endif // KEEPASSXC_TESTBROWSER_H
diff --git a/tests/data/NewDatabaseBrowser.kdbx b/tests/data/NewDatabaseBrowser.kdbx
index 97599fccf..fb327943c 100644
--- a/tests/data/NewDatabaseBrowser.kdbx
+++ b/tests/data/NewDatabaseBrowser.kdbx
Binary files differ
diff --git a/tests/gui/TestGuiBrowser.cpp b/tests/gui/TestGuiBrowser.cpp
index 7e5d89df4..6eac62798 100644
--- a/tests/gui/TestGuiBrowser.cpp
+++ b/tests/gui/TestGuiBrowser.cpp
@@ -31,6 +31,7 @@
#include <QTableView>
#include <QToolBar>
+#include "browser/BrowserService.h"
#include "config-keepassx-tests.h"
#include "core/Bootstrap.h"
#include "core/Config.h"
@@ -82,30 +83,19 @@ void TestGuiBrowser::initTestCase()
Bootstrap::restoreMainWindowState(*m_mainWindow);
m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");
m_mainWindow->show();
-
- // Load the NewDatabase.kdbx file into temporary storage
- QFile sourceDbFile(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabaseBrowser.kdbx"));
- QVERIFY(sourceDbFile.open(QIODevice::ReadOnly));
- QVERIFY(Tools::readAllFromDevice(&sourceDbFile, m_dbData));
- sourceDbFile.close();
}
// Every test starts with opening the temp database
void TestGuiBrowser::init()
{
m_dbFile.reset(new TemporaryFile());
- // Write the temp storage to a temp database file for use in our tests
- 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();
+ m_dbFile->copyFromFile(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabaseBrowser.kdbx"));
// make sure window is activated or focus tests may fail
m_mainWindow->activateWindow();
QApplication::processEvents();
- fileDialog()->setNextFileName(m_dbFilePath);
+ fileDialog()->setNextFileName(m_dbFile->fileName());
triggerAction("actionDatabaseOpen");
auto* databaseOpenWidget = m_tabWidget->currentDatabaseWidget()->findChild<QWidget*>("databaseOpenWidget");
@@ -241,6 +231,28 @@ void TestGuiBrowser::testAdditionalURLs()
}
}
+void TestGuiBrowser::testGetDatabaseGroups()
+{
+ auto result = browserService()->getDatabaseGroups();
+ QCOMPARE(result.length(), 1);
+
+ auto groups = result["groups"].toArray();
+ auto first = groups.at(0);
+ auto children = first.toObject()["children"].toArray();
+ QCOMPARE(first.toObject()["name"].toString(), QString("NewDatabase"));
+ QCOMPARE(children.size(), 6);
+
+ auto firstChild = children.at(0).toObject();
+ auto secondChild = children.at(1).toObject();
+ QCOMPARE(firstChild["name"].toString(), QString("General"));
+ QCOMPARE(secondChild["name"].toString(), QString("Windows"));
+
+ auto subGroups = firstChild["children"].toArray();
+ QCOMPARE(subGroups.count(), 1);
+ auto subGroupObj = subGroups.at(0).toObject();
+ QCOMPARE(subGroupObj["name"].toString(), QString("SubGroup"));
+}
+
void TestGuiBrowser::triggerAction(const QString& name)
{
auto* action = m_mainWindow->findChild<QAction*>(name);
diff --git a/tests/gui/TestGuiBrowser.h b/tests/gui/TestGuiBrowser.h
index 53a9c73c4..818a36952 100644
--- a/tests/gui/TestGuiBrowser.h
+++ b/tests/gui/TestGuiBrowser.h
@@ -45,6 +45,7 @@ private slots:
void testEntrySettings();
void testAdditionalURLs();
+ void testGetDatabaseGroups();
private:
void triggerAction(const QString& name);
@@ -57,10 +58,7 @@ private:
QPointer<DatabaseTabWidget> m_tabWidget;
QPointer<DatabaseWidget> m_dbWidget;
QSharedPointer<Database> m_db;
- QByteArray m_dbData;
QScopedPointer<TemporaryFile> m_dbFile;
- QString m_dbFileName;
- QString m_dbFilePath;
};
#endif // KEEPASSXC_TESTGUIBROWSER_H