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"
|
2021-02-05 15:07:59 -05:00
|
|
|
#include "fdosecrets/dbus/DBusClient.h"
|
|
|
|
#include "fdosecrets/dbus/DBusMgr.h"
|
2019-12-16 16:49:58 -05:00
|
|
|
#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 "TestGlobal.h"
|
|
|
|
#include "config-keepassx-tests.h"
|
|
|
|
|
|
|
|
#include "core/Config.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/DatabaseWidget.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"
|
|
|
|
#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>
|
2020-11-03 19:02:56 -05:00
|
|
|
#include <QTemporaryDir>
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
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)
|
|
|
|
: DBusClient(dbus, QStringLiteral("local"), 0, "fake-client")
|
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();
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
// set keys for session encryption
|
|
|
|
m_serverPublic = MpiFromHex("e407997e8b918419cf851cf3345358fdf"
|
|
|
|
"ffb9564a220ac9c3934efd277cea20d17"
|
|
|
|
"467ecdc56e817f75ac39501f38a4a04ff"
|
|
|
|
"64d627e16c09981c7ad876da255b61c8e"
|
|
|
|
"6a8408236c2a4523cfe6961c26dbdfc77"
|
|
|
|
"c1a27a5b425ca71a019e829fae32c0b42"
|
|
|
|
"0e1b3096b48bc2ce9ccab1d1ff13a5eb4"
|
|
|
|
"b263cee30bdb1a57af9bfa93f");
|
|
|
|
m_serverPrivate = MpiFromHex("013f4f3381ef0ca11c4c7363079577b56"
|
|
|
|
"99b238644e0aba47e24bdba6173590216"
|
|
|
|
"4f1e12dd0944800a373e090e63192f53b"
|
|
|
|
"93583e9a9e50bb9d792aafaa3a0f5ae77"
|
|
|
|
"de0c3423f5820848d88ee3bdd01c889f2"
|
|
|
|
"7af58a02f5b6693d422b9d189b300d7b1"
|
|
|
|
"be5076b5795cf8808c31e2e2898368d18"
|
|
|
|
"ab5c26b0ea3480c9aba8154cf");
|
|
|
|
// use the same cipher to do the client side encryption, but exchange the position of client/server keys
|
|
|
|
m_cipher.reset(new DhIetf1024Sha256Aes128CbcPkcs7);
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(m_cipher->initialize(MpiFromBytes(MpiToBytes(m_serverPublic)),
|
|
|
|
MpiFromHex("30d18c6b328bac970c05bda6af2e708b9"
|
|
|
|
"d6bbbb6dc136c1a2d96e870fabc86ad74"
|
|
|
|
"1846a26a4197f32f65ea2e7580ad2afe3"
|
|
|
|
"dd5d6c1224b8368b0df2cd75d520a9ff9"
|
|
|
|
"7fe894cc7da71b7bd285b4633359c16c8"
|
|
|
|
"d341f822fa4f0fdf59b5d3448658c46a2"
|
|
|
|
"a86dbb14ff85823873f8a259ccc52bbb8"
|
|
|
|
"2b5a4c2a75447982553b42221"),
|
|
|
|
MpiFromHex("84aafe9c9f356f7762307f4d791acb59e"
|
|
|
|
"8e3fd562abdbb481d0587f8400ad6c51d"
|
|
|
|
"af561a1beb9a22c8cd4d2807367c5787b"
|
|
|
|
"2e06d631ccbb5194b6bb32211583ce688"
|
|
|
|
"f9c2cebc22a9e4d494d12ebdd570c61a1"
|
|
|
|
"62a94e88561d25ccd0415339d1f59e1b0"
|
|
|
|
"6bc6b6b5fde46e23b2410eb034be390d3"
|
|
|
|
"2407ec7ae90f0831f24afd5ac")));
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
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();
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
|
|
|
// 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());
|
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
|
|
|
|
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-02-05 15:07:59 -05:00
|
|
|
VERIFY(m_tabWidget->closeAllDatabaseTabs());
|
2019-12-16 16:49:58 -05:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
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-02-05 15:07:59 -05:00
|
|
|
auto entries = m_db->rootGroup()->entriesRecursive(false);
|
|
|
|
VERIFY(!entries.isEmpty());
|
|
|
|
const auto& entry = entries.first();
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyPromptCompleted.count(), 0);
|
|
|
|
DBUS_COMPARE(coll->locked(), true);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// drive 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-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyPromptCompleted.count(), 0);
|
|
|
|
DBUS_COMPARE(coll->locked(), true);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// interact with the dialog
|
|
|
|
QApplication::processEvents();
|
|
|
|
{
|
|
|
|
auto dbOpenDlg = m_tabWidget->findChild<DatabaseOpenDialog*>();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(dbOpenDlg);
|
2019-12-16 16:49:58 -05:00
|
|
|
auto editPassword = dbOpenDlg->findChild<QLineEdit*>("editPassword");
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(editPassword);
|
2019-12-16 16:49:58 -05:00
|
|
|
editPassword->setFocus();
|
|
|
|
QTest::keyClicks(editPassword, "a");
|
|
|
|
QTest::keyClick(editPassword, Qt::Key_Enter);
|
|
|
|
}
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
|
|
|
// unlocked
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_COMPARE(coll->locked(), false);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyPromptCompleted.count(), 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-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyCollectionCreated.count(), 0);
|
|
|
|
QTRY_VERIFY(!spyCollectionChanged.isEmpty());
|
|
|
|
for (const auto& args : spyCollectionChanged) {
|
|
|
|
COMPARE(args.size(), 1);
|
|
|
|
COMPARE(args.at(0).value<QDBusObjectPath>().path(), coll->path());
|
|
|
|
}
|
|
|
|
QTRY_COMPARE(spyCollectionDeleted.count(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
// unlocked
|
|
|
|
DBUS_COMPARE(item->locked(), false);
|
|
|
|
|
|
|
|
VERIFY(spyPromptCompleted.wait());
|
|
|
|
COMPARE(spyPromptCompleted.count(), 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())});
|
|
|
|
}
|
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));
|
|
|
|
|
|
|
|
// unlocked
|
|
|
|
DBUS_COMPARE(item->locked(), false);
|
|
|
|
|
|
|
|
VERIFY(spyPromptCompleted.wait());
|
|
|
|
COMPARE(spyPromptCompleted.count(), 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())});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
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(""));
|
2019-12-16 16:49:58 -05:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_COMPARE(coll->locked(), false);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyPromptCompleted.count(), 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)), {});
|
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(""));
|
2019-12-16 16:49:58 -05:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_COMPARE(coll->locked(), true);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyPromptCompleted.count(), 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())});
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyCollectionCreated.count(), 0);
|
|
|
|
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-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyCollectionDeleted.count(), 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(""));
|
2019-12-16 16:49:58 -05:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
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-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyCollectionCreated.count(), 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());
|
|
|
|
|
|
|
|
QTimer::singleShot(50, this, &TestGuiFdoSecrets::driveNewDatabaseWizard);
|
|
|
|
DBUS_VERIFY(prompt->Prompt(""));
|
2019-12-16 16:49:58 -05:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyPromptCompleted.count(), 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-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyCollectionCreated.count(), 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
void TestGuiFdoSecrets::driveNewDatabaseWizard()
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
|
|
|
auto wizard = m_tabWidget->findChild<NewDatabaseWizard*>();
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(wizard);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(wizard->currentId(), 0);
|
2019-12-16 16:49:58 -05:00
|
|
|
wizard->next();
|
|
|
|
wizard->next();
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(wizard->currentId(), 2);
|
2019-12-16 16:49:58 -05:00
|
|
|
|
|
|
|
// enter password
|
|
|
|
auto* passwordEdit = wizard->findChild<QLineEdit*>("enterPasswordEdit");
|
|
|
|
auto* passwordRepeatEdit = wizard->findChild<QLineEdit*>("repeatPasswordEdit");
|
|
|
|
QTest::keyClicks(passwordEdit, "test");
|
|
|
|
QTest::keyClick(passwordEdit, Qt::Key::Key_Tab);
|
|
|
|
QTest::keyClicks(passwordRepeatEdit, "test");
|
|
|
|
|
|
|
|
// save database to temporary file
|
|
|
|
TemporaryFile tmpFile;
|
2021-02-05 15:07:59 -05:00
|
|
|
VERIFY(tmpFile.open());
|
2019-12-16 16:49:58 -05:00
|
|
|
tmpFile.close();
|
|
|
|
fileDialog()->setNextFileName(tmpFile.fileName());
|
|
|
|
|
|
|
|
wizard->accept();
|
|
|
|
|
|
|
|
tmpFile.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02-05 15:07:59 -05:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
|
|
|
// 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-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyPromptCompleted.count(), 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).value<QDBusVariant>().variant().toString(), QStringLiteral(""));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyCollectionDeleted.count(), 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyItemCreated.count(), 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())));
|
|
|
|
auto decrypted = m_cipher->decrypt(ss.unmarshal(m_plugin->dbus()));
|
|
|
|
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())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyItemCreated.count(), 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);
|
|
|
|
|
|
|
|
QTRY_COMPARE(spyItemCreated.count(), 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// when replace with a locked item, there will be an prompt
|
|
|
|
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())));
|
|
|
|
auto ss = m_cipher->decrypt(encrypted.unmarshal(m_plugin->dbus()));
|
|
|
|
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())));
|
|
|
|
auto ss = m_cipher->decrypt(encrypted.unmarshal(m_plugin->dbus()));
|
|
|
|
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-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyShowNotification.count(), 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
|
|
|
|
wire::Secret ss;
|
2019-12-16 16:49:58 -05:00
|
|
|
ss.contentType = TEXT_PLAIN;
|
|
|
|
ss.value = "NewPassword";
|
2021-02-05 15:07:59 -05:00
|
|
|
ss.session = QDBusObjectPath(sess->path());
|
|
|
|
auto encrypted = m_cipher->encrypt(ss.unmarshal(m_plugin->dbus()));
|
|
|
|
DBUS_VERIFY(item->SetSecret(encrypted.marshal()));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(entry->password().toUtf8(), ss.value);
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// set secret with something else is saved as attachment
|
|
|
|
{
|
2021-02-05 15:07:59 -05:00
|
|
|
wire::Secret expected;
|
2019-12-16 16:49:58 -05:00
|
|
|
expected.contentType = APPLICATION_OCTET_STREAM;
|
2021-02-05 15:07:59 -05:00
|
|
|
expected.value = QByteArrayLiteral("NewPasswordBinary");
|
|
|
|
expected.session = QDBusObjectPath(sess->path());
|
|
|
|
DBUS_VERIFY(item->SetSecret(m_cipher->encrypt(expected.unmarshal(m_plugin->dbus())).marshal()));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
COMPARE(entry->password(), QStringLiteral(""));
|
2019-12-16 16:49:58 -05:00
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET(encrypted, item->GetSecret(QDBusObjectPath(sess->path())));
|
|
|
|
auto ss = m_cipher->decrypt(encrypted.unmarshal(m_plugin->dbus()));
|
|
|
|
COMPARE(ss.contentType, expected.contentType);
|
|
|
|
COMPARE(ss.value, expected.value);
|
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
|
|
|
QApplication::processEvents();
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
QTRY_COMPARE(spyPromptCompleted.count(), 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(""));
|
|
|
|
|
|
|
|
QTRY_COMPARE(spyItemDeleted.count(), 1);
|
|
|
|
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());
|
|
|
|
auto encrypted = m_cipher->encrypt(secret).marshal();
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
|
|
|
{
|
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());
|
|
|
|
QApplication::processEvents();
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
void TestGuiFdoSecrets::lockDatabaseInBackend()
|
|
|
|
{
|
|
|
|
m_dbWidget->lock();
|
|
|
|
m_db.reset();
|
|
|
|
QApplication::processEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGuiFdoSecrets::unlockDatabaseInBackend()
|
|
|
|
{
|
|
|
|
m_dbWidget->performUnlockDatabase("a");
|
|
|
|
m_db = m_dbWidget->database();
|
|
|
|
QApplication::processEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
|
|
|
|
DhIetf1024Sha256Aes128CbcPkcs7::fixNextServerKeys(MpiFromBytes(MpiToBytes(m_serverPrivate)),
|
|
|
|
MpiFromBytes(MpiToBytes(m_serverPublic)));
|
|
|
|
|
2021-02-05 15:07:59 -05:00
|
|
|
DBUS_GET2(output, sessPath, service->OpenSession(algo, QDBusVariant(m_cipher->m_publicKey)));
|
|
|
|
|
|
|
|
COMPARE(qvariant_cast<QByteArray>(output.variant()), MpiToBytes(m_serverPublic));
|
|
|
|
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,
|
|
|
|
bool expectPrompt)
|
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-02-05 15:07:59 -05:00
|
|
|
auto encrypted = m_cipher->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(""));
|
|
|
|
bool found = driveAccessControlDialog();
|
|
|
|
COMPARE(found, expectPrompt);
|
|
|
|
|
|
|
|
// wait for signal
|
|
|
|
VERIFY(spyPromptCompleted.wait());
|
|
|
|
COMPARE(spyPromptCompleted.count(), 1);
|
|
|
|
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-02-05 15:07:59 -05:00
|
|
|
bool TestGuiFdoSecrets::driveAccessControlDialog(bool remember)
|
2019-12-16 16:49:58 -05:00
|
|
|
{
|
|
|
|
QApplication::processEvents();
|
2021-02-05 15:07:59 -05:00
|
|
|
for (auto w : qApp->allWidgets()) {
|
|
|
|
if (!w->isWindow()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto dlg = qobject_cast<AccessControlDialog*>(w);
|
|
|
|
if (dlg) {
|
|
|
|
auto rememberCheck = dlg->findChild<QCheckBox*>("rememberCheck");
|
|
|
|
VERIFY(rememberCheck);
|
|
|
|
rememberCheck->setChecked(remember);
|
|
|
|
QTest::keyClick(dlg, Qt::Key_Enter);
|
|
|
|
QApplication::processEvents();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2019-12-16 16:49:58 -05:00
|
|
|
}
|
2021-02-05 15:07:59 -05:00
|
|
|
|
|
|
|
#undef VERIFY
|
|
|
|
#define VERIFY QVERIFY
|
|
|
|
#undef COMPARE
|
|
|
|
#define COMPARE QCOMPARE
|