2019-12-16 16:49:58 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Aetf <aetf@unlimitedcodeworks.xyz>
|
|
|
|
*
|
|
|
|
* 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 "TestGuiFdoSecrets.h"
|
|
|
|
|
|
|
|
#include "fdosecrets/FdoSecretsPlugin.h"
|
|
|
|
#include "fdosecrets/FdoSecretsSettings.h"
|
|
|
|
#include "fdosecrets/objects/Collection.h"
|
|
|
|
#include "fdosecrets/objects/Item.h"
|
|
|
|
#include "fdosecrets/objects/SessionCipher.h"
|
2021-02-05 15:07:59 -05:00
|
|
|
#include "fdosecrets/widgets/AccessControlDialog.h"
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
#include "config-keepassx-tests.h"
|
|
|
|
|
|
|
|
#include "core/Tools.h"
|
|
|
|
#include "crypto/Crypto.h"
|
2020-10-08 22:48:45 -04:00
|
|
|
#include "gui/Application.h"
|
2019-12-16 16:49:58 -05:00
|
|
|
#include "gui/DatabaseTabWidget.h"
|
|
|
|
#include "gui/FileDialog.h"
|
2020-10-08 22:48:45 -04:00
|
|
|
#include "gui/MainWindow.h"
|
2019-12-16 16:49:58 -05:00
|
|
|
#include "gui/MessageBox.h"
|
2022-04-13 05:46:47 -04:00
|
|
|
#include "gui/PasswordWidget.h"
|
2019-12-16 16:49:58 -05:00
|
|
|
#include "gui/wizard/NewDatabaseWizard.h"
|
2021-02-05 15:07:59 -05:00
|
|
|
#include "util/FdoSecretsProxy.h"
|
2019-12-16 16:49:58 -05:00
|
|
|
#include "util/TemporaryFile.h"
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
#include <QCheckBox>
|
2019-12-16 16:49:58 -05:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QSignalSpy>
|
2021-07-11 22:10:29 -04:00
|
|
|
#include <QTest>
|
2021-10-24 10:22:50 -04:00
|
|
|
#include <utility>
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
|
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
|
|
|
#endif
|
|
|
|
Application app(argc, argv);
|
|
|
|
app.setApplicationName("KeePassXC");
|
|
|
|
app.setApplicationVersion(KEEPASSXC_VERSION);
|
|
|
|
app.setQuitOnLastWindowClosed(false);
|
|
|
|
app.setAttribute(Qt::AA_Use96Dpi, true);
|
2020-06-04 08:10:43 -04:00
|
|
|
app.applyTheme();
|
2019-12-16 16:49:58 -05:00
|
|
|
QTEST_DISABLE_KEYPAD_NAVIGATION
|
|
|
|
TestGuiFdoSecrets tc;
|
|
|
|
QTEST_SET_MAIN_SOURCE_PATH
|
|
|
|
return QTest::qExec(&tc, argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DBUS_PATH_DEFAULT_ALIAS "/org/freedesktop/secrets/aliases/default"
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
// assert macros compatible with function having return values
|
|
|
|
#define VERIFY2_RET(statement, msg) \
|
2019-12-16 16:49:58 -05:00
|
|
|
do { \
|
2021-02-05 15:07:59 -05:00
|
|
|
if (!QTest::qVerify(static_cast<bool>(statement), #statement, (msg), __FILE__, __LINE__)) \
|
2019-12-16 16:49:58 -05:00
|
|
|
return {}; \
|
|
|
|
} while (false)
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
#define COMPARE_RET(actual, expected) \
|
2019-12-16 16:49:58 -05:00
|
|
|
do { \
|
|
|
|
if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__)) \
|
|
|
|
return {}; \
|
|
|
|
} while (false)
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
// by default use these with Qt macros
|
|
|
|
#define VERIFY QVERIFY
|
|
|
|
#define COMPARE QCOMPARE
|
|
|
|
#define VERIFY2 QVERIFY2
|
|
|
|
|
|
|
|
#define DBUS_COMPARE(actual, expected) \
|
2019-12-16 16:49:58 -05:00
|
|
|
do { \
|
2021-02-05 15:07:59 -05:00
|
|
|
auto reply = (actual); \
|
|
|
|
VERIFY2(reply.isValid(), reply.error().name().toLocal8Bit()); \
|
|
|
|
COMPARE(reply.value(), (expected)); \
|
2019-12-16 16:49:58 -05:00
|
|
|
} while (false)
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
#define DBUS_VERIFY(stmt) \
|
2019-12-16 16:49:58 -05:00
|
|
|
do { \
|
2021-02-05 15:07:59 -05:00
|
|
|
auto reply = (stmt); \
|
|
|
|
VERIFY2(reply.isValid(), reply.error().name().toLocal8Bit()); \
|
2019-12-16 16:49:58 -05:00
|
|
|
} while (false)
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
#define DBUS_GET(var, stmt) \
|
|
|
|
std::remove_cv<decltype((stmt).argumentAt<0>())>::type var; \
|
2019-12-16 16:49:58 -05:00
|
|
|
do { \
|
2021-02-05 15:07:59 -05:00
|
|
|
const auto rep = (stmt); \
|
|
|
|
VERIFY2(rep.isValid(), rep.error().name().toLocal8Bit()); \
|
|
|
|
var = rep.argumentAt<0>(); \
|
2019-12-16 16:49:58 -05:00
|
|
|
} while (false)
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
#define DBUS_GET2(name1, name2, stmt) \
|
|
|
|
std::remove_cv<decltype((stmt).argumentAt<0>())>::type name1; \
|
|
|
|
std::remove_cv<decltype((stmt).argumentAt<1>())>::type name2; \
|
|
|
|
do { \
|
|
|
|
const auto rep = (stmt); \
|
|
|
|
VERIFY2(rep.isValid(), rep.error().name().toLocal8Bit()); \
|
|
|
|
name1 = rep.argumentAt<0>(); \
|
|
|
|
name2 = rep.argumentAt<1>(); \
|
|
|
|
} while (false)
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
using namespace FdoSecrets;
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
class FakeClient : public DBusClient
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit FakeClient(DBusMgr* dbus)
|
2021-10-01 18:22:15 -04:00
|
|
|
: DBusClient(
|
|
|
|
dbus,
|
|
|
|
{QStringLiteral("local"), 0, true, {ProcInfo{0, 0, QStringLiteral("fake-client"), QString{}, QString{}}}})
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
|
|
|
}
|
2021-02-05 15:07:59 -05:00
|
|
|
};
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
// pretty print QDBusObjectPath in QCOMPARE
|
|
|
|
char* toString(const QDBusObjectPath& path)
|
|
|
|
{
|
|
|
|
return QTest::toString("ObjectPath(" + path.path() + ")");
|
|
|
|
}
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
TestGuiFdoSecrets::~TestGuiFdoSecrets() = default;
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::initTestCase()
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(Crypto::init());
|
2019-12-16 16:49:58 -05:00
|
|
|
Config::createTempFileInstance();
|
|
|
|
config()->set(Config::AutoSaveAfterEveryChange, false);
|
|
|
|
config()->set(Config::AutoSaveOnExit, false);
|
|
|
|
config()->set(Config::GUI_ShowTrayIcon, true);
|
|
|
|
config()->set(Config::UpdateCheckMessageShown, true);
|
|
|
|
// Disable secret service integration (activate within individual tests to test the plugin)
|
|
|
|
FdoSecrets::settings()->setEnabled(false);
|
|
|
|
// activate within individual tests
|
|
|
|
FdoSecrets::settings()->setShowNotification(false);
|
|
|
|
|
2020-10-08 22:48:45 -04:00
|
|
|
Application::bootstrap();
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
m_mainWindow.reset(new MainWindow());
|
|
|
|
m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(m_tabWidget);
|
2020-06-19 18:25:59 -04:00
|
|
|
m_plugin = FdoSecretsPlugin::getPlugin();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(m_plugin);
|
2019-12-16 16:49:58 -05:00
|
|
|
m_mainWindow->show();
|
|
|
|
|
2021-04-04 08:56:00 -04:00
|
|
|
auto key = QByteArray::fromHex("e407997e8b918419cf851cf3345358fdf"
|
|
|
|
"ffb9564a220ac9c3934efd277cea20d17"
|
|
|
|
"467ecdc56e817f75ac39501f38a4a04ff"
|
|
|
|
"64d627e16c09981c7ad876da255b61c8e"
|
|
|
|
"6a8408236c2a4523cfe6961c26dbdfc77"
|
|
|
|
"c1a27a5b425ca71a019e829fae32c0b42"
|
|
|
|
"0e1b3096b48bc2ce9ccab1d1ff13a5eb4"
|
|
|
|
"b263cee30bdb1a57af9bfa93f");
|
|
|
|
m_clientCipher.reset(new DhIetf1024Sha256Aes128CbcPkcs7(key));
|
|
|
|
|
2019-12-16 16:49:58 -05:00
|
|
|
// Load the NewDatabase.kdbx file into temporary storage
|
|
|
|
QFile sourceDbFile(QStringLiteral(KEEPASSX_TEST_DATA_DIR "/NewDatabase.kdbx"));
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(sourceDbFile.open(QIODevice::ReadOnly));
|
|
|
|
VERIFY(Tools::readAllFromDevice(&sourceDbFile, m_dbData));
|
2019-12-16 16:49:58 -05:00
|
|
|
sourceDbFile.close();
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
// set a fake dbus client all the time so we can freely access DBusMgr anywhere
|
|
|
|
m_client.reset(new FakeClient(m_plugin->dbus().data()));
|
|
|
|
m_plugin->dbus()->overrideClient(m_client);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Every test starts with opening the temp database
|
|
|
|
void TestGuiFdoSecrets::init()
|
|
|
|
{
|
|
|
|
m_dbFile.reset(new TemporaryFile());
|
|
|
|
// Write the temp storage to a temp database file for use in our tests
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(m_dbFile->open());
|
2022-05-07 03:38:10 -04:00
|
|
|
COMPARE(m_dbFile->write(m_dbData), static_cast<qint64>(m_dbData.size()));
|
2019-12-16 16:49:58 -05:00
|
|
|
m_dbFile->close();
|
|
|
|
|
|
|
|
// make sure window is activated or focus tests may fail
|
|
|
|
m_mainWindow->activateWindow();
|
2021-09-18 19:55:37 -04:00
|
|
|
processEvents();
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// open and unlock the database
|
|
|
|
m_tabWidget->addDatabaseTab(m_dbFile->fileName(), false, "a");
|
|
|
|
m_dbWidget = m_tabWidget->currentDatabaseWidget();
|
|
|
|
m_db = m_dbWidget->database();
|
|
|
|
|
2020-11-02 23:01:04 -05:00
|
|
|
// by default expose the root group
|
2019-12-16 16:49:58 -05:00
|
|
|
FdoSecrets::settings()->setExposedGroup(m_db, m_db->rootGroup()->uuid());
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(m_dbWidget->save());
|
2022-05-07 03:38:10 -04:00
|
|
|
|
|
|
|
// enforce consistent default settings at the beginning
|
|
|
|
FdoSecrets::settings()->setUnlockBeforeSearch(false);
|
|
|
|
FdoSecrets::settings()->setShowNotification(false);
|
|
|
|
FdoSecrets::settings()->setConfirmAccessItem(false);
|
|
|
|
FdoSecrets::settings()->setEnabled(false);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Every test ends with closing the temp database without saving
|
|
|
|
void TestGuiFdoSecrets::cleanup()
|
|
|
|
{
|
|
|
|
// restore to default settings
|
2021-09-18 19:55:37 -04:00
|
|
|
FdoSecrets::settings()->setUnlockBeforeSearch(false);
|
2019-12-16 16:49:58 -05:00
|
|
|
FdoSecrets::settings()->setShowNotification(false);
|
2021-02-05 15:07:59 -05:00
|
|
|
FdoSecrets::settings()->setConfirmAccessItem(false);
|
2019-12-16 16:49:58 -05:00
|
|
|
FdoSecrets::settings()->setEnabled(false);
|
|
|
|
if (m_plugin) {
|
|
|
|
m_plugin->updateServiceState();
|
|
|
|
}
|
|
|
|
|
|
|
|
// DO NOT save the database
|
|
|
|
for (int i = 0; i != m_tabWidget->count(); ++i) {
|
|
|
|
m_tabWidget->databaseWidgetFromIndex(i)->database()->markAsClean();
|
|
|
|
}
|
2021-09-18 19:55:37 -04:00
|
|
|
|
|
|
|
// Close any dialogs
|
|
|
|
while (auto w = QApplication::activeModalWidget()) {
|
|
|
|
w->close();
|
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(m_tabWidget->closeAllDatabaseTabs());
|
2021-09-18 19:55:37 -04:00
|
|
|
processEvents();
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
if (m_dbFile) {
|
|
|
|
m_dbFile->remove();
|
|
|
|
}
|
2021-02-05 15:07:59 -05:00
|
|
|
|
|
|
|
m_client->clearAuthorization();
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::cleanupTestCase()
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
m_plugin->dbus()->overrideClient({});
|
2019-12-16 16:49:58 -05:00
|
|
|
if (m_dbFile) {
|
|
|
|
m_dbFile->remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::testServiceEnable()
|
|
|
|
{
|
|
|
|
QSignalSpy sigError(m_plugin, SIGNAL(error(QString)));
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(sigError.isValid());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
QSignalSpy sigStarted(m_plugin, SIGNAL(secretServiceStarted()));
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(sigStarted.isValid());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// make sure no one else is holding the service
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(!QDBusConnection::sessionBus().interface()->isServiceRegistered(DBUS_SERVICE_SECRET));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// enable the service
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// service started without error
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(sigError.isEmpty());
|
|
|
|
COMPARE(sigStarted.size(), 1);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
processEvents();
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(DBUS_SERVICE_SECRET));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// there will be one default collection
|
|
|
|
auto coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(coll);
|
|
|
|
|
|
|
|
DBUS_COMPARE(coll->locked(), false);
|
|
|
|
DBUS_COMPARE(coll->label(), m_db->metadata()->name());
|
|
|
|
|
|
|
|
DBUS_COMPARE(coll->created(),
|
|
|
|
static_cast<qulonglong>(m_db->rootGroup()->timeInfo().creationTime().toMSecsSinceEpoch() / 1000));
|
|
|
|
DBUS_COMPARE(
|
2019-12-16 16:49:58 -05:00
|
|
|
coll->modified(),
|
|
|
|
static_cast<qulonglong>(m_db->rootGroup()->timeInfo().lastModificationTime().toMSecsSinceEpoch() / 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::testServiceEnableNoExposedDatabase()
|
|
|
|
{
|
|
|
|
// reset the exposed group and then enable the service
|
|
|
|
FdoSecrets::settings()->setExposedGroup(m_db, {});
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// no collections
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_COMPARE(service->collections(), QList<QDBusObjectPath>{});
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::testServiceSearch()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(coll);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto item = getFirstItem(coll);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(item);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
auto itemObj = m_plugin->dbus()->pathToObject<Item>(QDBusObjectPath(item->path()));
|
|
|
|
VERIFY(itemObj);
|
|
|
|
auto entry = itemObj->backend();
|
|
|
|
VERIFY(entry);
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
entry->attributes()->set("fdosecrets-test", "1");
|
|
|
|
entry->attributes()->set("fdosecrets-test-protected", "2", true);
|
2019-12-16 16:49:58 -05:00
|
|
|
const QString crazyKey = "_a:bc&-+'-e%12df_d";
|
|
|
|
const QString crazyValue = "[v]al@-ue";
|
2021-02-05 15:07:59 -05:00
|
|
|
entry->attributes()->set(crazyKey, crazyValue);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// search by title
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{"Title", entry->title()}}));
|
|
|
|
COMPARE(locked, {});
|
|
|
|
COMPARE(unlocked, {QDBusObjectPath(item->path())});
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// search by attribute
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{"fdosecrets-test", "1"}}));
|
|
|
|
COMPARE(locked, {});
|
|
|
|
COMPARE(unlocked, {QDBusObjectPath(item->path())});
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{crazyKey, crazyValue}}));
|
|
|
|
COMPARE(locked, {});
|
|
|
|
COMPARE(unlocked, {QDBusObjectPath(item->path())});
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// searching using empty terms returns nothing
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({}));
|
|
|
|
COMPARE(locked, {});
|
|
|
|
COMPARE(unlocked, {});
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// searching using protected attributes or password returns nothing
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{"Password", entry->password()}}));
|
|
|
|
COMPARE(locked, {});
|
|
|
|
COMPARE(unlocked, {});
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{"fdosecrets-test-protected", "2"}}));
|
|
|
|
COMPARE(locked, {});
|
|
|
|
COMPARE(unlocked, {});
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
void TestGuiFdoSecrets::testServiceSearchBlockingUnlock()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
|
|
|
|
auto entries = m_db->rootGroup()->entriesRecursive();
|
|
|
|
VERIFY(!entries.isEmpty());
|
|
|
|
// assumes the db is not empty
|
|
|
|
auto title = entries.first()->title();
|
|
|
|
|
|
|
|
// NOTE: entries are no longer valid after locking
|
|
|
|
lockDatabaseInBackend();
|
|
|
|
|
|
|
|
// when database is locked, nothing is returned
|
|
|
|
FdoSecrets::settings()->setUnlockBeforeSearch(false);
|
|
|
|
{
|
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{"Title", title}}));
|
|
|
|
COMPARE(locked, {});
|
|
|
|
COMPARE(unlocked, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
// when database is locked, nothing is returned
|
|
|
|
FdoSecrets::settings()->setUnlockBeforeSearch(true);
|
|
|
|
{
|
|
|
|
// SearchItems will block because the blocking wait is implemented
|
|
|
|
// using a local QEventLoop.
|
|
|
|
// so we do a little trick here to get the return value back
|
|
|
|
bool unlockDialogWorks = false;
|
|
|
|
QTimer::singleShot(50, [&]() { unlockDialogWorks = driveUnlockDialog(); });
|
|
|
|
|
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{"Title", title}}));
|
|
|
|
VERIFY(unlockDialogWorks);
|
|
|
|
COMPARE(locked, {});
|
|
|
|
COMPARE(unlocked.size(), 1);
|
|
|
|
auto item = getProxy<ItemProxy>(unlocked.first());
|
|
|
|
DBUS_COMPARE(item->label(), title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-07 03:38:10 -04:00
|
|
|
void TestGuiFdoSecrets::testServiceSearchBlockingUnlockMultiple()
|
|
|
|
{
|
|
|
|
// setup: two databases, both locked, one with exposed db, the other not.
|
|
|
|
|
|
|
|
// add another database tab with a database with no exposed group
|
|
|
|
// to avoid modify the original, copy to a temp file first
|
|
|
|
QFile sourceDbFile(QStringLiteral(KEEPASSX_TEST_DATA_DIR "/NewDatabase2.kdbx"));
|
|
|
|
QByteArray dbData;
|
|
|
|
VERIFY(sourceDbFile.open(QIODevice::ReadOnly));
|
|
|
|
VERIFY(Tools::readAllFromDevice(&sourceDbFile, dbData));
|
|
|
|
sourceDbFile.close();
|
|
|
|
|
|
|
|
QTemporaryFile anotherFile;
|
|
|
|
VERIFY(anotherFile.open());
|
|
|
|
COMPARE(anotherFile.write(dbData), static_cast<qint64>(dbData.size()));
|
|
|
|
anotherFile.close();
|
|
|
|
|
|
|
|
m_tabWidget->addDatabaseTab(anotherFile.fileName(), false);
|
|
|
|
auto anotherWidget = m_tabWidget->currentDatabaseWidget();
|
|
|
|
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
|
|
|
|
// when there are multiple locked databases,
|
2023-01-29 09:38:44 -05:00
|
|
|
// repeatedly show the dialog until there is at least one unlocked collection
|
2022-05-07 03:38:10 -04:00
|
|
|
FdoSecrets::settings()->setUnlockBeforeSearch(true);
|
|
|
|
|
|
|
|
// when only unlocking the one with no exposed group, a second dialog is shown
|
|
|
|
lockDatabaseInBackend();
|
|
|
|
{
|
|
|
|
bool unlockDialogWorks = false;
|
|
|
|
QTimer::singleShot(50, [&]() {
|
|
|
|
unlockDialogWorks = driveUnlockDialog(anotherWidget);
|
|
|
|
QTimer::singleShot(50, [&]() { unlockDialogWorks &= driveUnlockDialog(); });
|
|
|
|
});
|
|
|
|
|
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{"Title", "Sample Entry"}}));
|
|
|
|
VERIFY(unlockDialogWorks);
|
|
|
|
COMPARE(locked, {});
|
|
|
|
COMPARE(unlocked.size(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// when unlocking the one with exposed group, the other one remains locked
|
|
|
|
lockDatabaseInBackend();
|
|
|
|
{
|
|
|
|
bool unlockDialogWorks = false;
|
|
|
|
QTimer::singleShot(50, [&]() { unlockDialogWorks = driveUnlockDialog(m_dbWidget); });
|
|
|
|
|
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{"Title", "Sample Entry"}}));
|
|
|
|
VERIFY(unlockDialogWorks);
|
|
|
|
COMPARE(locked, {});
|
|
|
|
COMPARE(unlocked.size(), 1);
|
|
|
|
VERIFY(anotherWidget->isLocked());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
void TestGuiFdoSecrets::testServiceSearchForce()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
auto item = getFirstItem(coll);
|
|
|
|
VERIFY(item);
|
|
|
|
|
|
|
|
auto itemObj = m_plugin->dbus()->pathToObject<Item>(QDBusObjectPath(item->path()));
|
|
|
|
VERIFY(itemObj);
|
|
|
|
auto entry = itemObj->backend();
|
|
|
|
VERIFY(entry);
|
|
|
|
|
|
|
|
// fdosecrets should still find the item even if searching is disabled
|
|
|
|
entry->group()->setSearchingEnabled(Group::Disable);
|
|
|
|
|
|
|
|
// search by title
|
|
|
|
{
|
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{"Title", entry->title()}}));
|
|
|
|
COMPARE(locked, {});
|
|
|
|
COMPARE(unlocked, {QDBusObjectPath(item->path())});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 16:49:58 -05:00
|
|
|
void TestGuiFdoSecrets::testServiceUnlock()
|
|
|
|
{
|
|
|
|
lockDatabaseInBackend();
|
|
|
|
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(coll);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QSignalSpy spyCollectionCreated(service.data(), SIGNAL(CollectionCreated(QDBusObjectPath)));
|
|
|
|
VERIFY(spyCollectionCreated.isValid());
|
|
|
|
QSignalSpy spyCollectionDeleted(service.data(), SIGNAL(CollectionDeleted(QDBusObjectPath)));
|
|
|
|
VERIFY(spyCollectionDeleted.isValid());
|
|
|
|
QSignalSpy spyCollectionChanged(service.data(), SIGNAL(CollectionChanged(QDBusObjectPath)));
|
|
|
|
VERIFY(spyCollectionChanged.isValid());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(unlocked, promptPath, service->Unlock({QDBusObjectPath(coll->path())}));
|
|
|
|
// nothing is unlocked immediately without user's action
|
|
|
|
COMPARE(unlocked, {});
|
|
|
|
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
|
|
|
QSignalSpy spyPromptCompleted(prompt.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted.isValid());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// nothing is unlocked yet
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 0));
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_COMPARE(coll->locked(), true);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
// show the prompt
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// still not unlocked before user action
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 0));
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_COMPARE(coll->locked(), true);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(driveUnlockDialog());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 1));
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
|
|
|
auto args = spyPromptCompleted.takeFirst();
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(args.size(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
COMPARE(getSignalVariantArgument<QList<QDBusObjectPath>>(args.at(1)), {QDBusObjectPath(coll->path())});
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
2021-09-18 19:55:37 -04:00
|
|
|
|
|
|
|
// check unlocked *AFTER* the prompt signal
|
|
|
|
DBUS_COMPARE(coll->locked(), false);
|
|
|
|
|
|
|
|
VERIFY(waitForSignal(spyCollectionCreated, 0));
|
2021-02-05 15:07:59 -05:00
|
|
|
QTRY_VERIFY(!spyCollectionChanged.isEmpty());
|
|
|
|
for (const auto& args : spyCollectionChanged) {
|
|
|
|
COMPARE(args.size(), 1);
|
|
|
|
COMPARE(args.at(0).value<QDBusObjectPath>().path(), coll->path());
|
|
|
|
}
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyCollectionDeleted, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::testServiceUnlockDatabaseConcurrent()
|
|
|
|
{
|
|
|
|
lockDatabaseInBackend();
|
|
|
|
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
|
|
|
|
DBUS_GET2(unlocked, promptPath, service->Unlock({QDBusObjectPath(coll->path())}));
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
|
|
|
QSignalSpy spyPromptCompleted(prompt.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted.isValid());
|
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
|
|
|
|
|
|
|
// while the first prompt is running, another request come in
|
|
|
|
DBUS_GET2(unlocked2, promptPath2, service->Unlock({QDBusObjectPath(coll->path())}));
|
|
|
|
auto prompt2 = getProxy<PromptProxy>(promptPath2);
|
|
|
|
VERIFY(prompt2);
|
|
|
|
QSignalSpy spyPromptCompleted2(prompt2.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted2.isValid());
|
|
|
|
DBUS_VERIFY(prompt2->Prompt(""));
|
|
|
|
|
|
|
|
// there should be only one unlock dialog
|
|
|
|
VERIFY(driveUnlockDialog());
|
|
|
|
|
|
|
|
// both prompts should complete
|
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 1));
|
|
|
|
{
|
|
|
|
auto args = spyPromptCompleted.takeFirst();
|
|
|
|
COMPARE(args.size(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
COMPARE(getSignalVariantArgument<QList<QDBusObjectPath>>(args.at(1)), {QDBusObjectPath(coll->path())});
|
|
|
|
}
|
|
|
|
VERIFY(waitForSignal(spyPromptCompleted2, 1));
|
|
|
|
{
|
|
|
|
auto args = spyPromptCompleted2.takeFirst();
|
|
|
|
COMPARE(args.size(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
COMPARE(getSignalVariantArgument<QList<QDBusObjectPath>>(args.at(1)), {QDBusObjectPath(coll->path())});
|
|
|
|
}
|
|
|
|
|
|
|
|
// check unlocked *AFTER* prompt signal
|
|
|
|
DBUS_COMPARE(coll->locked(), false);
|
2021-02-05 15:07:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::testServiceUnlockItems()
|
|
|
|
{
|
|
|
|
FdoSecrets::settings()->setConfirmAccessItem(true);
|
|
|
|
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
auto item = getFirstItem(coll);
|
|
|
|
VERIFY(item);
|
|
|
|
auto sess = openSession(service, DhIetf1024Sha256Aes128CbcPkcs7::Algorithm);
|
|
|
|
VERIFY(sess);
|
|
|
|
|
|
|
|
DBUS_COMPARE(item->locked(), true);
|
|
|
|
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(unlocked, promptPath, service->Unlock({QDBusObjectPath(item->path())}));
|
|
|
|
// nothing is unlocked immediately without user's action
|
|
|
|
COMPARE(unlocked, {});
|
|
|
|
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
|
|
|
QSignalSpy spyPromptCompleted(prompt.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted.isValid());
|
|
|
|
|
|
|
|
// nothing is unlocked yet
|
|
|
|
COMPARE(spyPromptCompleted.count(), 0);
|
|
|
|
DBUS_COMPARE(item->locked(), true);
|
|
|
|
|
|
|
|
// drive the prompt
|
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
|
|
|
// only allow once
|
|
|
|
VERIFY(driveAccessControlDialog(false));
|
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 1));
|
2021-02-05 15:07:59 -05:00
|
|
|
{
|
|
|
|
auto args = spyPromptCompleted.takeFirst();
|
|
|
|
COMPARE(args.size(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
COMPARE(getSignalVariantArgument<QList<QDBusObjectPath>>(args.at(1)), {QDBusObjectPath(item->path())});
|
|
|
|
}
|
2021-09-18 19:55:37 -04:00
|
|
|
|
|
|
|
// unlocked
|
|
|
|
DBUS_COMPARE(item->locked(), false);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
2021-02-05 15:07:59 -05:00
|
|
|
|
|
|
|
// access the secret should reset the locking state
|
|
|
|
{
|
|
|
|
DBUS_GET(ss, item->GetSecret(QDBusObjectPath(sess->path())));
|
|
|
|
}
|
|
|
|
DBUS_COMPARE(item->locked(), true);
|
|
|
|
|
|
|
|
// unlock again with remember
|
|
|
|
{
|
|
|
|
DBUS_GET2(unlocked, promptPath, service->Unlock({QDBusObjectPath(item->path())}));
|
|
|
|
// nothing is unlocked immediately without user's action
|
|
|
|
COMPARE(unlocked, {});
|
|
|
|
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
|
|
|
QSignalSpy spyPromptCompleted(prompt.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted.isValid());
|
|
|
|
|
|
|
|
// nothing is unlocked yet
|
|
|
|
COMPARE(spyPromptCompleted.count(), 0);
|
|
|
|
DBUS_COMPARE(item->locked(), true);
|
|
|
|
|
|
|
|
// drive the prompt
|
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
|
|
|
// only allow and remember
|
|
|
|
VERIFY(driveAccessControlDialog(true));
|
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 1));
|
2021-02-05 15:07:59 -05:00
|
|
|
{
|
|
|
|
auto args = spyPromptCompleted.takeFirst();
|
|
|
|
COMPARE(args.size(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
COMPARE(getSignalVariantArgument<QList<QDBusObjectPath>>(args.at(1)), {QDBusObjectPath(item->path())});
|
|
|
|
}
|
2021-09-18 19:55:37 -04:00
|
|
|
|
|
|
|
// unlocked
|
|
|
|
DBUS_COMPARE(item->locked(), false);
|
2021-02-05 15:07:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// access the secret does not reset the locking state
|
|
|
|
{
|
|
|
|
DBUS_GET(ss, item->GetSecret(QDBusObjectPath(sess->path())));
|
|
|
|
}
|
|
|
|
DBUS_COMPARE(item->locked(), false);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
2022-02-26 17:22:20 -05:00
|
|
|
void TestGuiFdoSecrets::testServiceUnlockItemsIncludeFutureEntries()
|
|
|
|
{
|
|
|
|
FdoSecrets::settings()->setConfirmAccessItem(true);
|
|
|
|
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
auto item = getFirstItem(coll);
|
|
|
|
VERIFY(item);
|
|
|
|
auto sess = openSession(service, DhIetf1024Sha256Aes128CbcPkcs7::Algorithm);
|
|
|
|
VERIFY(sess);
|
|
|
|
|
|
|
|
DBUS_COMPARE(item->locked(), true);
|
|
|
|
|
|
|
|
{
|
|
|
|
DBUS_GET2(unlocked, promptPath, service->Unlock({QDBusObjectPath(item->path())}));
|
|
|
|
// nothing is unlocked immediately without user's action
|
|
|
|
COMPARE(unlocked, {});
|
|
|
|
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
|
|
|
QSignalSpy spyPromptCompleted(prompt.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted.isValid());
|
|
|
|
|
|
|
|
// nothing is unlocked yet
|
|
|
|
COMPARE(spyPromptCompleted.count(), 0);
|
|
|
|
DBUS_COMPARE(item->locked(), true);
|
|
|
|
|
|
|
|
// drive the prompt
|
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
|
|
|
// remember and include future entries
|
|
|
|
VERIFY(driveAccessControlDialog(true, true));
|
|
|
|
|
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 1));
|
|
|
|
{
|
|
|
|
auto args = spyPromptCompleted.takeFirst();
|
|
|
|
COMPARE(args.size(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
COMPARE(getSignalVariantArgument<QList<QDBusObjectPath>>(args.at(1)), {QDBusObjectPath(item->path())});
|
|
|
|
}
|
|
|
|
|
|
|
|
// unlocked
|
|
|
|
DBUS_COMPARE(item->locked(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check other entries are also unlocked
|
|
|
|
{
|
|
|
|
DBUS_GET(itemPaths, coll->items());
|
|
|
|
VERIFY(itemPaths.size() > 1);
|
|
|
|
auto anotherItem = getProxy<ItemProxy>(itemPaths.last());
|
|
|
|
VERIFY(anotherItem);
|
|
|
|
DBUS_COMPARE(anotherItem->locked(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 16:49:58 -05:00
|
|
|
void TestGuiFdoSecrets::testServiceLock()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(coll);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QSignalSpy spyCollectionCreated(service.data(), SIGNAL(CollectionCreated(QDBusObjectPath)));
|
|
|
|
VERIFY(spyCollectionCreated.isValid());
|
|
|
|
QSignalSpy spyCollectionDeleted(service.data(), SIGNAL(CollectionDeleted(QDBusObjectPath)));
|
|
|
|
VERIFY(spyCollectionDeleted.isValid());
|
|
|
|
QSignalSpy spyCollectionChanged(service.data(), SIGNAL(CollectionChanged(QDBusObjectPath)));
|
|
|
|
VERIFY(spyCollectionChanged.isValid());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// if the db is modified, prompt user
|
|
|
|
m_db->markAsModified();
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(locked, promptPath, service->Lock({QDBusObjectPath(coll->path())}));
|
|
|
|
COMPARE(locked, {});
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
|
|
|
QSignalSpy spyPromptCompleted(prompt.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted.isValid());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// prompt and click cancel
|
|
|
|
MessageBox::setNextAnswer(MessageBox::Cancel);
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
2021-09-18 19:55:37 -04:00
|
|
|
processEvents();
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 1));
|
2019-12-16 16:49:58 -05:00
|
|
|
auto args = spyPromptCompleted.takeFirst();
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(args.count(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), true);
|
|
|
|
COMPARE(getSignalVariantArgument<QList<QDBusObjectPath>>(args.at(1)), {});
|
2021-09-18 19:55:37 -04:00
|
|
|
|
|
|
|
DBUS_COMPARE(coll->locked(), false);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(locked, promptPath, service->Lock({QDBusObjectPath(coll->path())}));
|
|
|
|
COMPARE(locked, {});
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
|
|
|
QSignalSpy spyPromptCompleted(prompt.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted.isValid());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// prompt and click save
|
|
|
|
MessageBox::setNextAnswer(MessageBox::Save);
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
2021-09-18 19:55:37 -04:00
|
|
|
processEvents();
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 1));
|
2019-12-16 16:49:58 -05:00
|
|
|
auto args = spyPromptCompleted.takeFirst();
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(args.count(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
COMPARE(getSignalVariantArgument<QList<QDBusObjectPath>>(args.at(1)), {QDBusObjectPath(coll->path())});
|
2021-09-18 19:55:37 -04:00
|
|
|
|
|
|
|
DBUS_COMPARE(coll->locked(), true);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyCollectionCreated, 0));
|
2021-02-05 15:07:59 -05:00
|
|
|
QTRY_VERIFY(!spyCollectionChanged.isEmpty());
|
|
|
|
for (const auto& args : spyCollectionChanged) {
|
|
|
|
COMPARE(args.size(), 1);
|
|
|
|
COMPARE(args.at(0).value<QDBusObjectPath>().path(), coll->path());
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyCollectionDeleted, 0));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// locking item locks the whole db
|
|
|
|
unlockDatabaseInBackend();
|
|
|
|
{
|
|
|
|
auto item = getFirstItem(coll);
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(locked, promptPath, service->Lock({QDBusObjectPath(item->path())}));
|
|
|
|
COMPARE(locked, {});
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
MessageBox::setNextAnswer(MessageBox::Save);
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
2021-09-18 19:55:37 -04:00
|
|
|
processEvents();
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_COMPARE(coll->locked(), true);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
void TestGuiFdoSecrets::testServiceLockConcurrent()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
|
|
|
|
m_db->markAsModified();
|
|
|
|
|
|
|
|
DBUS_GET2(locked, promptPath, service->Lock({QDBusObjectPath(coll->path())}));
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
|
|
|
QSignalSpy spyPromptCompleted(prompt.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted.isValid());
|
|
|
|
|
|
|
|
DBUS_GET2(locked2, promptPath2, service->Lock({QDBusObjectPath(coll->path())}));
|
|
|
|
auto prompt2 = getProxy<PromptProxy>(promptPath2);
|
|
|
|
VERIFY(prompt2);
|
|
|
|
QSignalSpy spyPromptCompleted2(prompt2.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted2.isValid());
|
|
|
|
|
|
|
|
// prompt and click save
|
|
|
|
MessageBox::setNextAnswer(MessageBox::Save);
|
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
|
|
|
|
|
|
|
// second prompt should not show dialog
|
|
|
|
DBUS_VERIFY(prompt2->Prompt(""));
|
|
|
|
|
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 1));
|
|
|
|
{
|
|
|
|
auto args = spyPromptCompleted.takeFirst();
|
|
|
|
COMPARE(args.count(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
COMPARE(getSignalVariantArgument<QList<QDBusObjectPath>>(args.at(1)), {QDBusObjectPath(coll->path())});
|
|
|
|
}
|
|
|
|
|
|
|
|
VERIFY(waitForSignal(spyPromptCompleted2, 1));
|
|
|
|
{
|
|
|
|
auto args = spyPromptCompleted2.takeFirst();
|
|
|
|
COMPARE(args.count(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
COMPARE(getSignalVariantArgument<QList<QDBusObjectPath>>(args.at(1)), {QDBusObjectPath(coll->path())});
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUS_COMPARE(coll->locked(), true);
|
|
|
|
}
|
|
|
|
|
2019-12-16 16:49:58 -05:00
|
|
|
void TestGuiFdoSecrets::testSessionOpen()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
auto sess = openSession(service, PlainCipher::Algorithm);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(sess);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
sess = openSession(service, DhIetf1024Sha256Aes128CbcPkcs7::Algorithm);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(sess);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::testSessionClose()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
auto sess = openSession(service, PlainCipher::Algorithm);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(sess);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_VERIFY(sess->Close());
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::testCollectionCreate()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QSignalSpy spyCollectionCreated(service.data(), SIGNAL(CollectionCreated(QDBusObjectPath)));
|
|
|
|
VERIFY(spyCollectionCreated.isValid());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// returns existing if alias is nonempty and exists
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
auto existing = getDefaultCollection(service);
|
|
|
|
DBUS_GET2(collPath,
|
|
|
|
promptPath,
|
|
|
|
service->CreateCollection({{DBUS_INTERFACE_SECRET_COLLECTION + ".Label", "NewDB"}}, "default"));
|
|
|
|
COMPARE(promptPath, QDBusObjectPath("/"));
|
|
|
|
COMPARE(collPath.path(), existing->path());
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyCollectionCreated, 0));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// create new one and set properties
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(collPath,
|
|
|
|
promptPath,
|
|
|
|
service->CreateCollection({{DBUS_INTERFACE_SECRET_COLLECTION + ".Label", "Test NewDB"}}, "mydatadb"));
|
|
|
|
COMPARE(collPath, QDBusObjectPath("/"));
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
|
|
|
|
|
|
|
QSignalSpy spyPromptCompleted(prompt.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted.isValid());
|
|
|
|
|
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(driveNewDatabaseWizard());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 1));
|
2019-12-16 16:49:58 -05:00
|
|
|
auto args = spyPromptCompleted.takeFirst();
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(args.size(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
auto coll = getProxy<CollectionProxy>(getSignalVariantArgument<QDBusObjectPath>(args.at(1)));
|
|
|
|
VERIFY(coll);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_COMPARE(coll->label(), QStringLiteral("Test NewDB"));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyCollectionCreated, 1));
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
2020-06-06 09:55:45 -04:00
|
|
|
args = spyCollectionCreated.takeFirst();
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(args.size(), 1);
|
|
|
|
COMPARE(args.at(0).value<QDBusObjectPath>().path(), coll->path());
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::testCollectionDelete()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(coll);
|
2020-11-13 17:14:03 -05:00
|
|
|
// save the path which will be gone after the deletion.
|
2021-02-05 15:07:59 -05:00
|
|
|
auto collPath = coll->path();
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QSignalSpy spyCollectionDeleted(service.data(), SIGNAL(CollectionDeleted(QDBusObjectPath)));
|
|
|
|
VERIFY(spyCollectionDeleted.isValid());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
m_db->markAsModified();
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(promptPath, coll->Delete());
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
|
|
|
QSignalSpy spyPromptCompleted(prompt.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted.isValid());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// prompt and click save
|
|
|
|
MessageBox::setNextAnswer(MessageBox::Save);
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
// closing the tab should have deleted the database if not in testing
|
2019-12-16 16:49:58 -05:00
|
|
|
// but deleteLater is not processed in QApplication::processEvent
|
|
|
|
// see https://doc.qt.io/qt-5/qcoreapplication.html#processEvents
|
2021-09-18 19:55:37 -04:00
|
|
|
|
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 1));
|
|
|
|
auto args = spyPromptCompleted.takeFirst();
|
|
|
|
COMPARE(args.count(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
COMPARE(args.at(1).value<QDBusVariant>().variant().toString(), QStringLiteral(""));
|
2021-02-05 15:07:59 -05:00
|
|
|
|
|
|
|
// however, the object should already be taken down from dbus
|
|
|
|
{
|
|
|
|
auto reply = coll->locked();
|
|
|
|
VERIFY(reply.isFinished() && reply.isError());
|
|
|
|
COMPARE(reply.error().type(), QDBusError::UnknownObject);
|
|
|
|
}
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyCollectionDeleted, 1));
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
2020-06-06 09:55:45 -04:00
|
|
|
args = spyCollectionDeleted.takeFirst();
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(args.size(), 1);
|
|
|
|
COMPARE(args.at(0).value<QDBusObjectPath>().path(), collPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
void TestGuiFdoSecrets::testCollectionDeleteConcurrent()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
|
|
|
|
m_db->markAsModified();
|
|
|
|
DBUS_GET(promptPath, coll->Delete());
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
|
|
|
QSignalSpy spyPromptCompleted(prompt.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted.isValid());
|
|
|
|
|
|
|
|
// before interacting with the prompt, another request come in
|
|
|
|
DBUS_GET(promptPath2, coll->Delete());
|
|
|
|
auto prompt2 = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt2);
|
|
|
|
QSignalSpy spyPromptCompleted2(prompt2.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted2.isValid());
|
|
|
|
|
|
|
|
// prompt and click save
|
|
|
|
MessageBox::setNextAnswer(MessageBox::Save);
|
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
|
|
|
|
|
|
|
// there should be no prompt
|
|
|
|
DBUS_VERIFY(prompt2->Prompt(""));
|
|
|
|
|
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 1));
|
|
|
|
{
|
|
|
|
auto args = spyPromptCompleted.takeFirst();
|
|
|
|
COMPARE(args.count(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
COMPARE(args.at(1).value<QDBusVariant>().variant().toString(), QStringLiteral(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
VERIFY(waitForSignal(spyPromptCompleted2, 1));
|
|
|
|
{
|
|
|
|
auto args = spyPromptCompleted2.takeFirst();
|
|
|
|
COMPARE(args.count(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
COMPARE(args.at(1).value<QDBusVariant>().variant().toString(), QStringLiteral(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto reply = coll->locked();
|
|
|
|
VERIFY(reply.isFinished() && reply.isError());
|
|
|
|
COMPARE(reply.error().type(), QDBusError::UnknownObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
void TestGuiFdoSecrets::testCollectionChange()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
|
|
|
|
QSignalSpy spyCollectionChanged(service.data(), SIGNAL(CollectionChanged(QDBusObjectPath)));
|
|
|
|
VERIFY(spyCollectionChanged.isValid());
|
|
|
|
|
|
|
|
DBUS_VERIFY(coll->setLabel("anotherLabel"));
|
|
|
|
COMPARE(m_db->metadata()->name(), QStringLiteral("anotherLabel"));
|
|
|
|
QTRY_COMPARE(spyCollectionChanged.size(), 1);
|
|
|
|
{
|
|
|
|
auto args = spyCollectionChanged.takeFirst();
|
|
|
|
COMPARE(args.size(), 1);
|
|
|
|
COMPARE(args.at(0).value<QDBusObjectPath>().path(), coll->path());
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 19:02:56 -05:00
|
|
|
void TestGuiFdoSecrets::testHiddenFilename()
|
|
|
|
{
|
|
|
|
// when file name contains leading dot, all parts excepting the last should be used
|
|
|
|
// for collection name, and the registration should success
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(m_dbFile->rename(QFileInfo(*m_dbFile).path() + "/.Name.kdbx"));
|
2020-11-03 19:02:56 -05:00
|
|
|
|
|
|
|
// reset is necessary to not hold database longer and cause connections
|
|
|
|
// not cleaned up when the database tab is closed.
|
|
|
|
m_db.reset();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(m_tabWidget->closeAllDatabaseTabs());
|
2020-11-03 19:02:56 -05:00
|
|
|
m_tabWidget->addDatabaseTab(m_dbFile->fileName(), false, "a");
|
|
|
|
m_dbWidget = m_tabWidget->currentDatabaseWidget();
|
|
|
|
m_db = m_dbWidget->database();
|
|
|
|
|
|
|
|
// enable the service
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2020-11-03 19:02:56 -05:00
|
|
|
|
|
|
|
// collection is properly registered
|
|
|
|
auto coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
auto collObj = m_plugin->dbus()->pathToObject<Collection>(QDBusObjectPath(coll->path()));
|
|
|
|
VERIFY(collObj);
|
|
|
|
COMPARE(collObj->name(), QStringLiteral(".Name"));
|
2020-11-03 19:02:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::testDuplicateName()
|
|
|
|
{
|
|
|
|
QTemporaryDir dir;
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(dir.isValid());
|
2020-11-03 19:02:56 -05:00
|
|
|
// create another file under different path but with the same filename
|
|
|
|
QString anotherFile = dir.path() + "/" + QFileInfo(*m_dbFile).fileName();
|
|
|
|
m_dbFile->copy(anotherFile);
|
|
|
|
m_tabWidget->addDatabaseTab(anotherFile, false, "a");
|
|
|
|
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2020-11-03 19:02:56 -05:00
|
|
|
|
|
|
|
// when two databases have the same name, one of it will have part of its uuid suffixed
|
2021-02-05 15:07:59 -05:00
|
|
|
const QString pathNoSuffix = QStringLiteral("/org/freedesktop/secrets/collection/KeePassXC");
|
|
|
|
DBUS_GET(colls, service->collections());
|
|
|
|
COMPARE(colls.size(), 2);
|
|
|
|
COMPARE(colls[0].path(), pathNoSuffix);
|
|
|
|
VERIFY(colls[1].path() != pathNoSuffix);
|
2020-11-03 19:02:56 -05:00
|
|
|
}
|
|
|
|
|
2019-12-16 16:49:58 -05:00
|
|
|
void TestGuiFdoSecrets::testItemCreate()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(coll);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto sess = openSession(service, DhIetf1024Sha256Aes128CbcPkcs7::Algorithm);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(sess);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QSignalSpy spyItemCreated(coll.data(), SIGNAL(ItemCreated(QDBusObjectPath)));
|
|
|
|
VERIFY(spyItemCreated.isValid());
|
2020-11-13 17:14:03 -05:00
|
|
|
|
2019-12-16 16:49:58 -05:00
|
|
|
// create item
|
|
|
|
StringStringMap attributes{
|
|
|
|
{"application", "fdosecrets-test"},
|
|
|
|
{"attr-i[bute]", "![some] -value*"},
|
|
|
|
};
|
|
|
|
|
|
|
|
auto item = createItem(sess, coll, "abc", "Password", attributes, false);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(item);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2020-11-13 17:14:03 -05:00
|
|
|
// signals
|
|
|
|
{
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyItemCreated, 1));
|
2020-11-13 17:14:03 -05:00
|
|
|
auto args = spyItemCreated.takeFirst();
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(args.size(), 1);
|
|
|
|
COMPARE(args.at(0).value<QDBusObjectPath>().path(), item->path());
|
2020-11-13 17:14:03 -05:00
|
|
|
}
|
|
|
|
|
2019-12-16 16:49:58 -05:00
|
|
|
// attributes
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(actual, item->attributes());
|
2019-12-16 16:49:58 -05:00
|
|
|
for (const auto& key : attributes.keys()) {
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(actual[key], attributes[key]);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// label
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_COMPARE(item->label(), QStringLiteral("abc"));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// secrets
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(ss, item->GetSecret(QDBusObjectPath(sess->path())));
|
2021-04-04 08:56:00 -04:00
|
|
|
auto decrypted = m_clientCipher->decrypt(ss.unmarshal(m_plugin->dbus()));
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(decrypted.value, QByteArrayLiteral("Password"));
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// searchable
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems(attributes));
|
|
|
|
COMPARE(locked, {});
|
|
|
|
COMPARE(unlocked, {QDBusObjectPath(item->path())});
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(unlocked, coll->SearchItems(attributes));
|
|
|
|
VERIFY(unlocked.contains(QDBusObjectPath(item->path())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-07 01:50:25 -04:00
|
|
|
void TestGuiFdoSecrets::testItemCreateUnlock()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
auto sess = openSession(service, DhIetf1024Sha256Aes128CbcPkcs7::Algorithm);
|
|
|
|
VERIFY(sess);
|
|
|
|
|
|
|
|
// NOTE: entries are no longer valid after locking
|
|
|
|
lockDatabaseInBackend();
|
|
|
|
|
|
|
|
QSignalSpy spyItemCreated(coll.data(), SIGNAL(ItemCreated(QDBusObjectPath)));
|
|
|
|
VERIFY(spyItemCreated.isValid());
|
|
|
|
|
|
|
|
// create item
|
|
|
|
StringStringMap attributes{
|
|
|
|
{"application", "fdosecrets-test"},
|
|
|
|
{"attr-i[bute]", "![some] -value*"},
|
|
|
|
};
|
|
|
|
|
|
|
|
auto item = createItem(sess, coll, "abc", "Password", attributes, false, false, true);
|
|
|
|
VERIFY(item);
|
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
void TestGuiFdoSecrets::testItemChange()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
auto item = getFirstItem(coll);
|
|
|
|
VERIFY(item);
|
|
|
|
auto itemObj = m_plugin->dbus()->pathToObject<Item>(QDBusObjectPath(item->path()));
|
|
|
|
VERIFY(itemObj);
|
|
|
|
auto entry = itemObj->backend();
|
|
|
|
VERIFY(entry);
|
|
|
|
|
|
|
|
QSignalSpy spyItemChanged(coll.data(), SIGNAL(ItemChanged(QDBusObjectPath)));
|
|
|
|
VERIFY(spyItemChanged.isValid());
|
|
|
|
|
|
|
|
DBUS_VERIFY(item->setLabel("anotherLabel"));
|
|
|
|
COMPARE(entry->title(), QStringLiteral("anotherLabel"));
|
|
|
|
QTRY_VERIFY(!spyItemChanged.isEmpty());
|
|
|
|
for (const auto& args : spyItemChanged) {
|
|
|
|
COMPARE(args.size(), 1);
|
|
|
|
COMPARE(args.at(0).value<QDBusObjectPath>().path(), item->path());
|
|
|
|
}
|
|
|
|
|
|
|
|
spyItemChanged.clear();
|
|
|
|
DBUS_VERIFY(item->setAttributes({
|
|
|
|
{"abc", "def"},
|
|
|
|
}));
|
|
|
|
COMPARE(entry->attributes()->value("abc"), QStringLiteral("def"));
|
|
|
|
QTRY_VERIFY(!spyItemChanged.isEmpty());
|
|
|
|
for (const auto& args : spyItemChanged) {
|
|
|
|
COMPARE(args.size(), 1);
|
|
|
|
COMPARE(args.at(0).value<QDBusObjectPath>().path(), item->path());
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::testItemReplace()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(coll);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto sess = openSession(service, DhIetf1024Sha256Aes128CbcPkcs7::Algorithm);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(sess);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// create item
|
|
|
|
StringStringMap attr1{
|
|
|
|
{"application", "fdosecrets-test"},
|
|
|
|
{"attr-i[bute]", "![some] -value*"},
|
|
|
|
{"fdosecrets-attr", "1"},
|
|
|
|
};
|
|
|
|
StringStringMap attr2{
|
|
|
|
{"application", "fdosecrets-test"},
|
|
|
|
{"attr-i[bute]", "![some] -value*"},
|
|
|
|
{"fdosecrets-attr", "2"},
|
|
|
|
};
|
|
|
|
|
|
|
|
auto item1 = createItem(sess, coll, "abc1", "Password", attr1, false);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(item1);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto item2 = createItem(sess, coll, "abc2", "Password", attr2, false);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(item2);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{"application", "fdosecrets-test"}}));
|
|
|
|
QSet<QDBusObjectPath> expected{QDBusObjectPath(item1->path()), QDBusObjectPath(item2->path())};
|
|
|
|
COMPARE(QSet<QDBusObjectPath>::fromList(unlocked), expected);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QSignalSpy spyItemCreated(coll.data(), SIGNAL(ItemCreated(QDBusObjectPath)));
|
|
|
|
VERIFY(spyItemCreated.isValid());
|
|
|
|
QSignalSpy spyItemChanged(coll.data(), SIGNAL(ItemChanged(QDBusObjectPath)));
|
|
|
|
VERIFY(spyItemChanged.isValid());
|
2020-11-13 17:14:03 -05:00
|
|
|
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
|
|
|
// when replace, existing item with matching attr is updated
|
|
|
|
auto item3 = createItem(sess, coll, "abc3", "Password", attr2, true);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(item3);
|
|
|
|
COMPARE(item2->path(), item3->path());
|
|
|
|
DBUS_COMPARE(item3->label(), QStringLiteral("abc3"));
|
2020-11-13 17:14:03 -05:00
|
|
|
// there are still 2 entries
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{"application", "fdosecrets-test"}}));
|
|
|
|
QSet<QDBusObjectPath> expected{QDBusObjectPath(item1->path()), QDBusObjectPath(item2->path())};
|
|
|
|
COMPARE(QSet<QDBusObjectPath>::fromList(unlocked), expected);
|
2020-11-13 17:14:03 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyItemCreated, 0));
|
2020-11-13 17:14:03 -05:00
|
|
|
// there may be multiple changed signals, due to each item attribute is set separately
|
2021-02-05 15:07:59 -05:00
|
|
|
QTRY_VERIFY(!spyItemChanged.isEmpty());
|
2020-11-13 17:14:03 -05:00
|
|
|
for (const auto& args : spyItemChanged) {
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(args.size(), 1);
|
|
|
|
COMPARE(args.at(0).value<QDBusObjectPath>().path(), item3->path());
|
2020-11-13 17:14:03 -05:00
|
|
|
}
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
2020-11-13 17:14:03 -05:00
|
|
|
spyItemCreated.clear();
|
|
|
|
spyItemChanged.clear();
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
|
|
|
// when NOT replace, another entry is created
|
|
|
|
auto item4 = createItem(sess, coll, "abc4", "Password", attr2, false);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(item4);
|
|
|
|
DBUS_COMPARE(item2->label(), QStringLiteral("abc3"));
|
|
|
|
DBUS_COMPARE(item4->label(), QStringLiteral("abc4"));
|
2020-11-13 17:14:03 -05:00
|
|
|
// there are 3 entries
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{"application", "fdosecrets-test"}}));
|
|
|
|
QSet<QDBusObjectPath> expected{
|
|
|
|
QDBusObjectPath(item1->path()),
|
|
|
|
QDBusObjectPath(item2->path()),
|
|
|
|
QDBusObjectPath(item4->path()),
|
|
|
|
};
|
|
|
|
COMPARE(QSet<QDBusObjectPath>::fromList(unlocked), expected);
|
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyItemCreated, 1));
|
2020-11-13 17:14:03 -05:00
|
|
|
{
|
|
|
|
auto args = spyItemCreated.takeFirst();
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(args.size(), 1);
|
|
|
|
COMPARE(args.at(0).value<QDBusObjectPath>().path(), item4->path());
|
2020-11-13 17:14:03 -05:00
|
|
|
}
|
|
|
|
// there may be multiple changed signals, due to each item attribute is set separately
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(!spyItemChanged.isEmpty());
|
2020-11-13 17:14:03 -05:00
|
|
|
for (const auto& args : spyItemChanged) {
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(args.size(), 1);
|
|
|
|
COMPARE(args.at(0).value<QDBusObjectPath>().path(), item4->path());
|
2020-11-13 17:14:03 -05:00
|
|
|
}
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
void TestGuiFdoSecrets::testItemReplaceExistingLocked()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
auto sess = openSession(service, DhIetf1024Sha256Aes128CbcPkcs7::Algorithm);
|
|
|
|
VERIFY(sess);
|
|
|
|
|
|
|
|
// create item
|
|
|
|
StringStringMap attr1{
|
|
|
|
{"application", "fdosecrets-test"},
|
|
|
|
{"attr-i[bute]", "![some] -value*"},
|
|
|
|
{"fdosecrets-attr", "1"},
|
|
|
|
};
|
|
|
|
|
|
|
|
auto item = createItem(sess, coll, "abc1", "Password", attr1, false);
|
|
|
|
VERIFY(item);
|
|
|
|
|
|
|
|
// make sure the item is locked
|
|
|
|
{
|
|
|
|
auto itemObj = m_plugin->dbus()->pathToObject<Item>(QDBusObjectPath(item->path()));
|
|
|
|
VERIFY(itemObj);
|
|
|
|
auto entry = itemObj->backend();
|
|
|
|
VERIFY(entry);
|
|
|
|
FdoSecrets::settings()->setConfirmAccessItem(true);
|
|
|
|
m_client->setItemAuthorized(entry->uuid(), AuthDecision::Undecided);
|
|
|
|
DBUS_COMPARE(item->locked(), true);
|
|
|
|
}
|
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
// when replace with a locked item, there will be a prompt
|
2021-02-05 15:07:59 -05:00
|
|
|
auto item2 = createItem(sess, coll, "abc2", "PasswordUpdated", attr1, true, true);
|
|
|
|
VERIFY(item2);
|
|
|
|
COMPARE(item2->path(), item->path());
|
|
|
|
DBUS_COMPARE(item2->label(), QStringLiteral("abc2"));
|
|
|
|
}
|
|
|
|
|
2019-12-16 16:49:58 -05:00
|
|
|
void TestGuiFdoSecrets::testItemSecret()
|
|
|
|
{
|
|
|
|
const QString TEXT_PLAIN = "text/plain";
|
|
|
|
const QString APPLICATION_OCTET_STREAM = "application/octet-stream";
|
|
|
|
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(coll);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto item = getFirstItem(coll);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(item);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto sess = openSession(service, DhIetf1024Sha256Aes128CbcPkcs7::Algorithm);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(sess);
|
|
|
|
|
|
|
|
auto itemObj = m_plugin->dbus()->pathToObject<Item>(QDBusObjectPath(item->path()));
|
|
|
|
VERIFY(itemObj);
|
|
|
|
auto entry = itemObj->backend();
|
|
|
|
VERIFY(entry);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// plain text secret
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(encrypted, item->GetSecret(QDBusObjectPath(sess->path())));
|
2021-04-04 08:56:00 -04:00
|
|
|
auto ss = m_clientCipher->decrypt(encrypted.unmarshal(m_plugin->dbus()));
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(ss.contentType, TEXT_PLAIN);
|
|
|
|
COMPARE(ss.value, entry->password().toUtf8());
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
// get secret with notification
|
2019-12-16 16:49:58 -05:00
|
|
|
FdoSecrets::settings()->setShowNotification(true);
|
|
|
|
{
|
|
|
|
QSignalSpy spyShowNotification(m_plugin, SIGNAL(requestShowNotification(QString, QString, int)));
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(spyShowNotification.isValid());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(encrypted, item->GetSecret(QDBusObjectPath(sess->path())));
|
2021-04-04 08:56:00 -04:00
|
|
|
auto ss = m_clientCipher->decrypt(encrypted.unmarshal(m_plugin->dbus()));
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(ss.contentType, TEXT_PLAIN);
|
|
|
|
COMPARE(ss.value, entry->password().toUtf8());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(ss.contentType, TEXT_PLAIN);
|
|
|
|
COMPARE(ss.value, entry->password().toUtf8());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyShowNotification, 1));
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
FdoSecrets::settings()->setShowNotification(false);
|
|
|
|
|
|
|
|
// set secret with plain text
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
// first create Secret in wire format,
|
|
|
|
// then convert to internal format and encrypt
|
|
|
|
// finally convert encrypted internal format back to wire format to pass to SetSecret
|
2021-10-24 10:22:50 -04:00
|
|
|
const QByteArray expected = QByteArrayLiteral("NewPassword");
|
|
|
|
auto encrypted = encryptPassword(expected, TEXT_PLAIN, sess);
|
|
|
|
DBUS_VERIFY(item->SetSecret(encrypted));
|
|
|
|
COMPARE(entry->password().toUtf8(), expected);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// set secret with something else is saved as attachment
|
2021-10-24 10:22:50 -04:00
|
|
|
const QByteArray expected = QByteArrayLiteral("NewPasswordBinary");
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
2021-10-24 10:22:50 -04:00
|
|
|
auto encrypted = encryptPassword(expected, APPLICATION_OCTET_STREAM, sess);
|
|
|
|
DBUS_VERIFY(item->SetSecret(encrypted));
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(entry->password(), QStringLiteral(""));
|
2021-10-24 10:22:50 -04:00
|
|
|
}
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(encrypted, item->GetSecret(QDBusObjectPath(sess->path())));
|
2021-04-04 08:56:00 -04:00
|
|
|
auto ss = m_clientCipher->decrypt(encrypted.unmarshal(m_plugin->dbus()));
|
2021-10-24 10:22:50 -04:00
|
|
|
COMPARE(ss.contentType, APPLICATION_OCTET_STREAM);
|
|
|
|
COMPARE(ss.value, expected);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::testItemDelete()
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
FdoSecrets::settings()->setConfirmDeleteItem(true);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(coll);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto item = getFirstItem(coll);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(item);
|
2020-11-13 17:14:03 -05:00
|
|
|
// save the path which will be gone after the deletion.
|
2021-02-05 15:07:59 -05:00
|
|
|
auto itemPath = item->path();
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QSignalSpy spyItemDeleted(coll.data(), SIGNAL(ItemDeleted(QDBusObjectPath)));
|
|
|
|
VERIFY(spyItemDeleted.isValid());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(promptPath, item->Delete());
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QSignalSpy spyPromptCompleted(prompt.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted.isValid());
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// prompt and click save
|
2021-02-05 15:07:59 -05:00
|
|
|
auto itemObj = m_plugin->dbus()->pathToObject<Item>(QDBusObjectPath(item->path()));
|
|
|
|
VERIFY(itemObj);
|
|
|
|
MessageBox::setNextAnswer(MessageBox::Delete);
|
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 1));
|
2019-12-16 16:49:58 -05:00
|
|
|
auto args = spyPromptCompleted.takeFirst();
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(args.count(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
COMPARE(args.at(1).toString(), QStringLiteral(""));
|
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyItemDeleted, 1));
|
2021-02-05 15:07:59 -05:00
|
|
|
args = spyItemDeleted.takeFirst();
|
|
|
|
COMPARE(args.size(), 1);
|
|
|
|
COMPARE(args.at(0).value<QDBusObjectPath>().path(), itemPath);
|
|
|
|
}
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
void TestGuiFdoSecrets::testItemLockState()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
auto item = getFirstItem(coll);
|
|
|
|
VERIFY(item);
|
|
|
|
auto sess = openSession(service, DhIetf1024Sha256Aes128CbcPkcs7::Algorithm);
|
|
|
|
VERIFY(sess);
|
|
|
|
auto itemObj = m_plugin->dbus()->pathToObject<Item>(QDBusObjectPath(item->path()));
|
|
|
|
VERIFY(itemObj);
|
|
|
|
auto entry = itemObj->backend();
|
|
|
|
VERIFY(entry);
|
|
|
|
|
|
|
|
auto secret =
|
|
|
|
wire::Secret{
|
|
|
|
QDBusObjectPath(sess->path()),
|
|
|
|
{},
|
|
|
|
"NewPassword",
|
|
|
|
"text/plain",
|
|
|
|
}
|
|
|
|
.unmarshal(m_plugin->dbus());
|
2021-04-04 08:56:00 -04:00
|
|
|
auto encrypted = m_clientCipher->encrypt(secret).marshal();
|
2021-02-05 15:07:59 -05:00
|
|
|
|
|
|
|
// when access confirmation is disabled, item is unlocked when the collection is unlocked
|
|
|
|
FdoSecrets::settings()->setConfirmAccessItem(false);
|
|
|
|
DBUS_COMPARE(item->locked(), false);
|
|
|
|
|
|
|
|
// when access confirmation is enabled, item is locked if the client has no authorization
|
|
|
|
FdoSecrets::settings()->setConfirmAccessItem(true);
|
|
|
|
DBUS_COMPARE(item->locked(), true);
|
|
|
|
// however, item properties are still accessible as long as the collection is unlocked
|
|
|
|
DBUS_VERIFY(item->attributes());
|
|
|
|
DBUS_VERIFY(item->setAttributes({}));
|
|
|
|
DBUS_VERIFY(item->label());
|
|
|
|
DBUS_VERIFY(item->setLabel("abc"));
|
|
|
|
DBUS_VERIFY(item->created());
|
|
|
|
DBUS_VERIFY(item->modified());
|
|
|
|
// except secret, which is locked
|
|
|
|
{
|
|
|
|
auto reply = item->GetSecret(QDBusObjectPath(sess->path()));
|
|
|
|
VERIFY(reply.isError());
|
|
|
|
COMPARE(reply.error().name(), DBUS_ERROR_SECRET_IS_LOCKED);
|
|
|
|
}
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
auto reply = item->SetSecret(encrypted);
|
|
|
|
VERIFY(reply.isError());
|
|
|
|
COMPARE(reply.error().name(), DBUS_ERROR_SECRET_IS_LOCKED);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
2021-02-05 15:07:59 -05:00
|
|
|
|
|
|
|
// item is unlocked if the client is authorized
|
|
|
|
m_client->setItemAuthorized(entry->uuid(), AuthDecision::Allowed);
|
|
|
|
DBUS_COMPARE(item->locked(), false);
|
|
|
|
DBUS_VERIFY(item->GetSecret(QDBusObjectPath(sess->path())));
|
|
|
|
DBUS_VERIFY(item->SetSecret(encrypted));
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
2021-10-24 10:22:50 -04:00
|
|
|
void TestGuiFdoSecrets::testItemRejectSetReferenceFields()
|
|
|
|
{
|
|
|
|
// expose a subgroup, entries in it should not be able to retrieve data from entries outside it
|
|
|
|
auto rootEntry = m_db->rootGroup()->entries().first();
|
|
|
|
VERIFY(rootEntry);
|
|
|
|
auto subgroup = m_db->rootGroup()->findGroupByPath("/Homebanking/Subgroup");
|
|
|
|
VERIFY(subgroup);
|
|
|
|
FdoSecrets::settings()->setExposedGroup(m_db, subgroup->uuid());
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
auto item = getFirstItem(coll);
|
|
|
|
VERIFY(item);
|
|
|
|
auto sess = openSession(service, DhIetf1024Sha256Aes128CbcPkcs7::Algorithm);
|
|
|
|
VERIFY(sess);
|
|
|
|
|
|
|
|
const auto refText = QStringLiteral("{REF:P@T:%1}").arg(rootEntry->title());
|
|
|
|
|
|
|
|
// reject ref in label
|
|
|
|
{
|
|
|
|
auto reply = item->setLabel(refText);
|
|
|
|
VERIFY(reply.isFinished() && reply.isError());
|
|
|
|
COMPARE(reply.error().type(), QDBusError::InvalidArgs);
|
|
|
|
}
|
|
|
|
// reject ref in custom attributes
|
|
|
|
{
|
|
|
|
auto reply = item->setAttributes({{"steal", refText}});
|
|
|
|
VERIFY(reply.isFinished() && reply.isError());
|
|
|
|
COMPARE(reply.error().type(), QDBusError::InvalidArgs);
|
|
|
|
}
|
|
|
|
// reject ref in password
|
|
|
|
{
|
|
|
|
auto reply = item->SetSecret(encryptPassword(refText.toUtf8(), "text/plain", sess));
|
|
|
|
VERIFY(reply.isFinished() && reply.isError());
|
|
|
|
COMPARE(reply.error().type(), QDBusError::InvalidArgs);
|
|
|
|
}
|
|
|
|
// reject ref in content type
|
|
|
|
{
|
|
|
|
auto reply = item->SetSecret(encryptPassword("dummy", refText, sess));
|
|
|
|
VERIFY(reply.isFinished() && reply.isError());
|
|
|
|
COMPARE(reply.error().type(), QDBusError::InvalidArgs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 16:49:58 -05:00
|
|
|
void TestGuiFdoSecrets::testAlias()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// read default alias
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(collPath, service->ReadAlias("default"));
|
|
|
|
auto coll = getProxy<CollectionProxy>(collPath);
|
|
|
|
VERIFY(coll);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// set extra alias
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_VERIFY(service->SetAlias("another", QDBusObjectPath(collPath)));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// get using extra alias
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(collPath2, service->ReadAlias("another"));
|
|
|
|
COMPARE(collPath2, collPath);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::testDefaultAliasAlwaysPresent()
|
|
|
|
{
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// one collection, which is default alias
|
|
|
|
auto coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(coll);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// after locking, the collection is still there, but locked
|
|
|
|
lockDatabaseInBackend();
|
|
|
|
|
|
|
|
coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(coll);
|
|
|
|
DBUS_COMPARE(coll->locked(), true);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// unlock the database, the alias and collection is present
|
|
|
|
unlockDatabaseInBackend();
|
|
|
|
|
|
|
|
coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(coll);
|
|
|
|
DBUS_COMPARE(coll->locked(), false);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::testExposeSubgroup()
|
|
|
|
{
|
|
|
|
auto subgroup = m_db->rootGroup()->findGroupByPath("/Homebanking/Subgroup");
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(subgroup);
|
2019-12-16 16:49:58 -05:00
|
|
|
FdoSecrets::settings()->setExposedGroup(m_db, subgroup->uuid());
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
auto coll = getDefaultCollection(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(coll);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// exposing subgroup does not expose entries in other groups
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(itemPaths, coll->items());
|
|
|
|
QSet<Entry*> exposedEntries;
|
|
|
|
for (const auto& itemPath : itemPaths) {
|
|
|
|
exposedEntries << m_plugin->dbus()->pathToObject<Item>(itemPath)->backend();
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(exposedEntries, QSet<Entry*>::fromList(subgroup->entries()));
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
2020-11-02 23:01:04 -05:00
|
|
|
void TestGuiFdoSecrets::testModifyingExposedGroup()
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
|
|
|
// test when exposed group is removed the collection is not exposed anymore
|
|
|
|
auto subgroup = m_db->rootGroup()->findGroupByPath("/Homebanking");
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(subgroup);
|
2019-12-16 16:49:58 -05:00
|
|
|
FdoSecrets::settings()->setExposedGroup(m_db, subgroup->uuid());
|
|
|
|
auto service = enableService();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(service);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(collPaths, service->collections());
|
|
|
|
COMPARE(collPaths.size(), 1);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
m_db->metadata()->setRecycleBinEnabled(true);
|
|
|
|
m_db->recycleGroup(subgroup);
|
2021-09-18 19:55:37 -04:00
|
|
|
processEvents();
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(collPaths, service->collections());
|
|
|
|
COMPARE(collPaths, {});
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// test setting another exposed group, the collection will be exposed again
|
|
|
|
FdoSecrets::settings()->setExposedGroup(m_db, m_db->rootGroup()->uuid());
|
2021-09-18 19:55:37 -04:00
|
|
|
processEvents();
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(collPaths, service->collections());
|
|
|
|
COMPARE(collPaths.size(), 1);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-06 17:47:34 -04:00
|
|
|
void TestGuiFdoSecrets::testNoExposeRecycleBin()
|
|
|
|
{
|
|
|
|
// when the recycle bin is underneath the exposed group
|
|
|
|
// be careful not to expose entries in there
|
|
|
|
|
|
|
|
FdoSecrets::settings()->setExposedGroup(m_db, m_db->rootGroup()->uuid());
|
|
|
|
m_db->metadata()->setRecycleBinEnabled(true);
|
|
|
|
|
|
|
|
auto entry = m_db->rootGroup()->entries().first();
|
|
|
|
VERIFY(entry);
|
|
|
|
m_db->recycleEntry(entry);
|
|
|
|
processEvents();
|
|
|
|
|
|
|
|
auto service = enableService();
|
|
|
|
VERIFY(service);
|
|
|
|
|
|
|
|
auto coll = getDefaultCollection(service);
|
|
|
|
VERIFY(coll);
|
|
|
|
|
|
|
|
// exposing subgroup does not expose entries in other groups
|
|
|
|
DBUS_GET(itemPaths, coll->items());
|
|
|
|
QSet<Entry*> exposedEntries;
|
|
|
|
for (const auto& itemPath : itemPaths) {
|
|
|
|
exposedEntries << m_plugin->dbus()->pathToObject<Item>(itemPath)->backend();
|
|
|
|
}
|
|
|
|
VERIFY(!exposedEntries.contains(entry));
|
|
|
|
|
|
|
|
// searching should not return the entry
|
|
|
|
DBUS_GET2(unlocked, locked, service->SearchItems({{"Title", entry->title()}}));
|
|
|
|
COMPARE(locked, {});
|
|
|
|
COMPARE(unlocked, {});
|
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
void TestGuiFdoSecrets::lockDatabaseInBackend()
|
|
|
|
{
|
2022-05-07 03:38:10 -04:00
|
|
|
m_tabWidget->lockDatabases();
|
2021-02-05 15:07:59 -05:00
|
|
|
m_db.reset();
|
2021-09-18 19:55:37 -04:00
|
|
|
processEvents();
|
2021-02-05 15:07:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::unlockDatabaseInBackend()
|
|
|
|
{
|
|
|
|
m_dbWidget->performUnlockDatabase("a");
|
|
|
|
m_db = m_dbWidget->database();
|
2021-09-18 19:55:37 -04:00
|
|
|
processEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::processEvents()
|
|
|
|
{
|
|
|
|
// Couldn't use QApplication::processEvents, because per Qt documentation:
|
|
|
|
// events that are posted while the function runs will be queued until a later round of event processing.
|
|
|
|
// and we may post QTimer single shot events during event handling to achieve async method.
|
|
|
|
// So we directly call event dispatcher in a loop until no events can be handled
|
|
|
|
while (QAbstractEventDispatcher::instance()->processEvents(QEventLoop::AllEvents)) {
|
|
|
|
// pass
|
|
|
|
}
|
2021-02-05 15:07:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// the following functions have return value, switch macros to the version supporting that
|
|
|
|
#undef VERIFY
|
|
|
|
#undef VERIFY2
|
|
|
|
#undef COMPARE
|
|
|
|
#define VERIFY(stmt) VERIFY2_RET(stmt, "")
|
|
|
|
#define VERIFY2 VERIFY2_RET
|
|
|
|
#define COMPARE COMPARE_RET
|
|
|
|
|
|
|
|
QSharedPointer<ServiceProxy> TestGuiFdoSecrets::enableService()
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
|
|
|
FdoSecrets::settings()->setEnabled(true);
|
|
|
|
VERIFY(m_plugin);
|
|
|
|
m_plugin->updateServiceState();
|
2021-02-05 15:07:59 -05:00
|
|
|
return getProxy<ServiceProxy>(QDBusObjectPath(DBUS_PATH_SECRETS));
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QSharedPointer<SessionProxy> TestGuiFdoSecrets::openSession(const QSharedPointer<ServiceProxy>& service,
|
|
|
|
const QString& algo)
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
|
|
|
VERIFY(service);
|
|
|
|
|
|
|
|
if (algo == PlainCipher::Algorithm) {
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(output, sessPath, service->OpenSession(algo, QDBusVariant("")));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
return getProxy<SessionProxy>(sessPath);
|
2019-12-16 16:49:58 -05:00
|
|
|
} else if (algo == DhIetf1024Sha256Aes128CbcPkcs7::Algorithm) {
|
2021-04-04 08:56:00 -04:00
|
|
|
DBUS_GET2(output, sessPath, service->OpenSession(algo, QDBusVariant(m_clientCipher->negotiationOutput())));
|
|
|
|
m_clientCipher->updateClientPublicKey(output.variant().toByteArray());
|
2021-02-05 15:07:59 -05:00
|
|
|
return getProxy<SessionProxy>(sessPath);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
2021-02-05 15:07:59 -05:00
|
|
|
QTest::qFail("Unsupported algorithm", __FILE__, __LINE__);
|
|
|
|
return {};
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QSharedPointer<CollectionProxy> TestGuiFdoSecrets::getDefaultCollection(const QSharedPointer<ServiceProxy>& service)
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
|
|
|
VERIFY(service);
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(collPath, service->ReadAlias("default"));
|
|
|
|
return getProxy<CollectionProxy>(collPath);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QSharedPointer<ItemProxy> TestGuiFdoSecrets::getFirstItem(const QSharedPointer<CollectionProxy>& coll)
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
|
|
|
VERIFY(coll);
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(itemPaths, coll->items());
|
|
|
|
VERIFY(!itemPaths.isEmpty());
|
|
|
|
return getProxy<ItemProxy>(itemPaths.first());
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QSharedPointer<ItemProxy> TestGuiFdoSecrets::createItem(const QSharedPointer<SessionProxy>& sess,
|
|
|
|
const QSharedPointer<CollectionProxy>& coll,
|
|
|
|
const QString& label,
|
|
|
|
const QString& pass,
|
|
|
|
const StringStringMap& attr,
|
|
|
|
bool replace,
|
2022-05-07 01:50:25 -04:00
|
|
|
bool expectPrompt,
|
|
|
|
bool expectUnlockPrompt)
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
|
|
|
VERIFY(sess);
|
|
|
|
VERIFY(coll);
|
|
|
|
|
|
|
|
QVariantMap properties{
|
2021-02-05 15:07:59 -05:00
|
|
|
{DBUS_INTERFACE_SECRET_ITEM + ".Label", QVariant::fromValue(label)},
|
|
|
|
{DBUS_INTERFACE_SECRET_ITEM + ".Attributes", QVariant::fromValue(attr)},
|
2019-12-16 16:49:58 -05:00
|
|
|
};
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
wire::Secret ss;
|
|
|
|
ss.session = QDBusObjectPath(sess->path());
|
2019-12-16 16:49:58 -05:00
|
|
|
ss.value = pass.toLocal8Bit();
|
|
|
|
ss.contentType = "plain/text";
|
2021-04-04 08:56:00 -04:00
|
|
|
auto encrypted = m_clientCipher->encrypt(ss.unmarshal(m_plugin->dbus())).marshal();
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(itemPath, promptPath, coll->CreateItem(properties, encrypted, replace));
|
|
|
|
|
|
|
|
auto prompt = getProxy<PromptProxy>(promptPath);
|
|
|
|
VERIFY(prompt);
|
|
|
|
QSignalSpy spyPromptCompleted(prompt.data(), SIGNAL(Completed(bool, QDBusVariant)));
|
|
|
|
VERIFY(spyPromptCompleted.isValid());
|
|
|
|
|
|
|
|
// drive the prompt
|
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
2022-05-07 01:50:25 -04:00
|
|
|
|
|
|
|
bool unlockFound = driveUnlockDialog();
|
|
|
|
COMPARE(unlockFound, expectUnlockPrompt);
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
bool found = driveAccessControlDialog();
|
|
|
|
COMPARE(found, expectPrompt);
|
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(waitForSignal(spyPromptCompleted, 1));
|
2021-02-05 15:07:59 -05:00
|
|
|
auto args = spyPromptCompleted.takeFirst();
|
|
|
|
COMPARE(args.size(), 2);
|
|
|
|
COMPARE(args.at(0).toBool(), false);
|
|
|
|
itemPath = getSignalVariantArgument<QDBusObjectPath>(args.at(1));
|
|
|
|
|
|
|
|
return getProxy<ItemProxy>(itemPath);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
2021-10-24 10:22:50 -04:00
|
|
|
FdoSecrets::wire::Secret
|
|
|
|
TestGuiFdoSecrets::encryptPassword(QByteArray value, QString contentType, const QSharedPointer<SessionProxy>& sess)
|
|
|
|
{
|
|
|
|
wire::Secret ss;
|
|
|
|
ss.contentType = std::move(contentType);
|
|
|
|
ss.value = std::move(value);
|
|
|
|
ss.session = QDBusObjectPath(sess->path());
|
|
|
|
return m_clientCipher->encrypt(ss.unmarshal(m_plugin->dbus())).marshal();
|
|
|
|
}
|
|
|
|
|
2022-02-26 17:22:20 -05:00
|
|
|
bool TestGuiFdoSecrets::driveAccessControlDialog(bool remember, bool includeFutureEntries)
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
2021-09-18 19:55:37 -04:00
|
|
|
processEvents();
|
|
|
|
for (auto w : QApplication::topLevelWidgets()) {
|
2021-02-05 15:07:59 -05:00
|
|
|
if (!w->isWindow()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto dlg = qobject_cast<AccessControlDialog*>(w);
|
2021-09-18 19:55:37 -04:00
|
|
|
if (dlg && dlg->isVisible()) {
|
2021-02-05 15:07:59 -05:00
|
|
|
auto rememberCheck = dlg->findChild<QCheckBox*>("rememberCheck");
|
|
|
|
VERIFY(rememberCheck);
|
|
|
|
rememberCheck->setChecked(remember);
|
2022-02-26 17:22:20 -05:00
|
|
|
|
|
|
|
if (includeFutureEntries) {
|
|
|
|
dlg->done(AccessControlDialog::AllowAll);
|
|
|
|
} else {
|
|
|
|
dlg->done(AccessControlDialog::AllowSelected);
|
|
|
|
}
|
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
processEvents();
|
|
|
|
VERIFY(dlg->isHidden());
|
2021-02-05 15:07:59 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
2021-02-05 15:07:59 -05:00
|
|
|
|
2021-09-18 19:55:37 -04:00
|
|
|
bool TestGuiFdoSecrets::driveNewDatabaseWizard()
|
|
|
|
{
|
|
|
|
// processEvents will block because the NewDatabaseWizard is shown using exec
|
|
|
|
// which creates a local QEventLoop.
|
|
|
|
// so we do a little trick here to get the return value back
|
|
|
|
bool ret = false;
|
|
|
|
QTimer::singleShot(0, this, [this, &ret]() {
|
|
|
|
ret = [this]() -> bool {
|
|
|
|
auto wizard = m_tabWidget->findChild<NewDatabaseWizard*>();
|
|
|
|
VERIFY(wizard);
|
|
|
|
|
|
|
|
COMPARE(wizard->currentId(), 0);
|
|
|
|
wizard->next();
|
|
|
|
wizard->next();
|
|
|
|
COMPARE(wizard->currentId(), 2);
|
|
|
|
|
|
|
|
// enter password
|
2022-04-13 05:46:47 -04:00
|
|
|
auto* passwordEdit =
|
|
|
|
wizard->findChild<PasswordWidget*>("enterPasswordEdit")->findChild<QLineEdit*>("passwordEdit");
|
|
|
|
auto* passwordRepeatEdit =
|
|
|
|
wizard->findChild<PasswordWidget*>("repeatPasswordEdit")->findChild<QLineEdit*>("passwordEdit");
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(passwordEdit);
|
|
|
|
VERIFY(passwordRepeatEdit);
|
|
|
|
QTest::keyClicks(passwordEdit, "test");
|
|
|
|
QTest::keyClick(passwordEdit, Qt::Key::Key_Tab);
|
|
|
|
QTest::keyClicks(passwordRepeatEdit, "test");
|
|
|
|
|
|
|
|
// save database to temporary file
|
|
|
|
TemporaryFile tmpFile;
|
|
|
|
VERIFY(tmpFile.open());
|
|
|
|
tmpFile.close();
|
|
|
|
fileDialog()->setNextFileName(tmpFile.fileName());
|
|
|
|
|
|
|
|
wizard->accept();
|
|
|
|
|
|
|
|
tmpFile.remove();
|
|
|
|
return true;
|
|
|
|
}();
|
|
|
|
});
|
|
|
|
processEvents();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-05-07 03:38:10 -04:00
|
|
|
bool TestGuiFdoSecrets::driveUnlockDialog(DatabaseWidget* target)
|
2021-09-18 19:55:37 -04:00
|
|
|
{
|
|
|
|
processEvents();
|
|
|
|
auto dbOpenDlg = m_tabWidget->findChild<DatabaseOpenDialog*>();
|
|
|
|
VERIFY(dbOpenDlg);
|
2022-05-07 01:50:25 -04:00
|
|
|
if (!dbOpenDlg->isVisible()) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-05-07 03:38:10 -04:00
|
|
|
dbOpenDlg->setActiveDatabaseTab(target);
|
|
|
|
|
2022-04-13 05:46:47 -04:00
|
|
|
auto editPassword = dbOpenDlg->findChild<PasswordWidget*>("editPassword")->findChild<QLineEdit*>("passwordEdit");
|
2021-09-18 19:55:37 -04:00
|
|
|
VERIFY(editPassword);
|
|
|
|
editPassword->setFocus();
|
|
|
|
QTest::keyClicks(editPassword, "a");
|
|
|
|
QTest::keyClick(editPassword, Qt::Key_Enter);
|
|
|
|
processEvents();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TestGuiFdoSecrets::waitForSignal(QSignalSpy& spy, int expectedCount)
|
|
|
|
{
|
|
|
|
processEvents();
|
|
|
|
// If already expected count, do not wait and return immediately
|
|
|
|
if (spy.count() == expectedCount) {
|
|
|
|
return true;
|
|
|
|
} else if (spy.count() > expectedCount) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
spy.wait();
|
|
|
|
COMPARE(spy.count(), expectedCount);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
#undef VERIFY
|
|
|
|
#define VERIFY QVERIFY
|
|
|
|
#undef COMPARE
|
|
|
|
#define COMPARE QCOMPARE
|