19 void cleanupTestCase();
20 void getPasswordConfigurationDefault();
21 void setAndGetPasswordConfiguration();
22 void getProfilesEmpty();
23 void setAndGetProfiles();
24 void setAndGetVersion();
25 void setAndGetGeometry();
27 void setAndGetPassStore();
28 void boolRoundTrip_data();
30 void intRoundTrip_data();
32 void stringRoundTrip_data();
33 void stringRoundTrip();
34 void setAndGetClipBoardType();
35 void setAndGetPasswordLength();
37 void setAndGetSavestate();
40 void setAndGetDialogGeometry();
41 void setAndGetDialogPos();
42 void setAndGetDialogSize();
43 void setAndGetDialogMaximized();
44 void setAndGetPasswordCharsSelection();
45 void setAndGetPasswordChars();
46 void setAndGetMultipleProfiles();
47 void setAndGetProfileDefault();
50 QString m_settingsBackupPath;
51 bool m_isPortableMode =
false;
54void tst_settings::initTestCase() {
58 QString portable_ini =
59 QCoreApplication::applicationDirPath() + QDir::separator() +
"qtpass.ini";
60 m_isPortableMode = QFile::exists(portable_ini);
62 if (m_isPortableMode) {
65 m_settingsBackupPath = settingsFile +
".bak";
66 QFile::remove(m_settingsBackupPath);
67 QVERIFY(QFile::copy(settingsFile, m_settingsBackupPath));
69 m_settingsBackupPath.clear();
72 <<
"Non-portable mode detected. Tests may modify registry settings.";
76void tst_settings::cleanupTestCase() {
79 if (m_isPortableMode && !m_settingsBackupPath.isEmpty()) {
82 QVERIFY2(QFile::remove(settingsFile) || !QFile::exists(settingsFile),
83 "Failed to remove current settings file before restore");
84 QVERIFY2(QFile::copy(m_settingsBackupPath, settingsFile),
85 "Failed to restore settings file from backup");
86 QVERIFY2(QFile::remove(m_settingsBackupPath),
87 "Failed to remove temporary settings backup file");
91void tst_settings::getPasswordConfigurationDefault() {
93 QVERIFY(config.
length >= 0);
97void tst_settings::setAndGetPasswordConfiguration() {
98 PasswordConfiguration config;
106 QCOMPARE(readConfig.
length, 20);
108 "Password config should be ALPHABETICAL");
111void tst_settings::getProfilesEmpty() {
112 QHash<QString, QHash<QString, QString>> emptyProfiles;
115 QHash<QString, QHash<QString, QString>> profiles =
117 QVERIFY(profiles.isEmpty());
120void tst_settings::setAndGetProfiles() {
121 QHash<QString, QHash<QString, QString>> profiles;
122 QHash<QString, QString> profile1;
123 profile1.insert(
"path",
"/test/path");
124 profile1.insert(
"signingKey",
"ABC123");
125 profiles.insert(
"profile1", profile1);
129 QHash<QString, QHash<QString, QString>> readProfiles =
131 QVERIFY(!readProfiles.isEmpty());
132 QVERIFY(readProfiles.contains(
"profile1"));
133 QCOMPARE(readProfiles[
"profile1"][
"path"], QString(
"/test/path"));
136void tst_settings::setAndGetVersion() {
139 QVERIFY2(version ==
"1.5.1",
"Version should be 1.5.1");
142void tst_settings::setAndGetGeometry() {
143 QByteArray geometry(
"test_geometry_data");
146 QVERIFY2(read == geometry,
"Geometry should match");
149void tst_settings::getPassStore() {
151 QVERIFY2(store.isEmpty() || store.startsWith(
"/") || store.contains(
"/"),
152 "Pass store should be empty or a plausible path");
155void tst_settings::setAndGetPassStore() {
158 QVERIFY(store.contains(
"test-store"));
164 void (*setter)(
const bool &);
165 bool (*getter)(
const bool &);
168const BoolSetting boolSettings[] = {
217void tst_settings::boolRoundTrip_data() {
218 QTest::addColumn<QString>(
"setting");
219 QTest::addColumn<bool>(
"testValue");
221 for (
const auto &s : boolSettings) {
222 QByteArray name(s.name);
223 QTest::newRow(name +
"_true") << s.name <<
true;
224 QTest::newRow(name +
"_false") << s.name <<
false;
228void tst_settings::boolRoundTrip() {
229 QFETCH(QString, setting);
230 QFETCH(
bool, testValue);
232 for (
const auto &s : boolSettings) {
233 if (setting == s.name) {
235 QVERIFY2(s.getter(!testValue) == testValue,
236 qPrintable(QString(
"%1 should be %2, got %3")
238 .arg(testValue ?
"true" :
"false")
239 .arg(s.getter(!testValue) ?
"true" :
"false")));
243 QFAIL(qPrintable(QString(
"Unknown setting: %1").arg(setting)));
246void tst_settings::setAndGetClipBoardType() {
251void tst_settings::setAndGetPasswordLength() {
254 QCOMPARE(config.
length, 24);
260 void (*setter)(
const int &);
261 int (*getter)(
const int &);
264const IntSetting intSettings[] = {
271struct StringSetting {
273 void (*setter)(
const QString &);
274 QString (*getter)(
const QString &);
277const StringSetting stringSettings[] = {
301void tst_settings::intRoundTrip_data() {
302 QTest::addColumn<QString>(
"setting");
303 QTest::addColumn<int>(
"testValue");
305 for (
const auto &s : intSettings) {
306 QByteArray name(s.name);
307 QTest::newRow(name +
"_30") << s.name << 30;
308 QTest::newRow(name +
"_60") << s.name << 60;
312void tst_settings::intRoundTrip() {
313 QFETCH(QString, setting);
314 QFETCH(
int, testValue);
316 for (
const auto &s : intSettings) {
317 if (setting == s.name) {
319 QCOMPARE(s.getter(-1), testValue);
323 QFAIL(qPrintable(QString(
"Unknown setting: %1").arg(setting)));
326void tst_settings::stringRoundTrip_data() {
327 QTest::addColumn<QString>(
"setting");
328 QTest::addColumn<QString>(
"testValue");
330 auto addString = [](
const char *name,
const QString &value) {
331 QTest::newRow((QByteArray(name) +
"_" + value.toUtf8()).constData())
335 addString(
"passSigningKey",
"testkey123");
336 addString(
"passSigningKey",
"anotherkey456");
337 addString(
"passExecutable",
"/usr/bin/pass");
338 addString(
"passExecutable",
"/usr/local/bin/pass");
339 addString(
"gitExecutable",
"/usr/bin/git");
340 addString(
"gitExecutable",
"/usr/local/bin/git");
341 addString(
"gpgExecutable",
"/usr/bin/gpg");
342 addString(
"gpgExecutable",
"/usr/local/bin/gpg");
343 addString(
"pwgenExecutable",
"/usr/bin/pwgen");
344 addString(
"pwgenExecutable",
"/usr/local/bin/pwgen");
345 addString(
"qrencodeExecutable",
"/usr/bin/qrencode");
346 addString(
"qrencodeExecutable",
"/usr/local/bin/qrencode");
347 addString(
"webDavUrl",
"https://dav.example.com/pass");
348 addString(
"webDavUrl",
"https://dav2.example.com/pass");
349 addString(
"webDavUser",
"testuser");
350 addString(
"webDavUser",
"admin");
351 addString(
"webDavPassword",
"secretpassword");
352 addString(
"webDavPassword",
"anothersecret");
353 addString(
"profile",
"work");
354 addString(
"profile",
"personal");
355 addString(
"passTemplate",
"username: {username}\npassword: {password}");
356 addString(
"passTemplate",
"user: {username}\npass: {password}");
359void tst_settings::stringRoundTrip() {
360 QFETCH(QString, setting);
361 QFETCH(QString, testValue);
363 for (
const auto &s : stringSettings) {
364 if (setting == s.name) {
366 QCOMPARE(s.getter(QString()), testValue);
370 QFAIL(qPrintable(QString(
"Unknown setting: %1").arg(setting)));
373void tst_settings::autoDetectGit() {
374 QTemporaryDir tempDir;
377 QDir gitDir(tempDir.path());
378 QVERIFY(gitDir.mkdir(
".git"));
384 "Should auto-detect .git and return true when default is true");
389 "Should return false when default is false, even if .git exists");
391 QVERIFY(gitDir.rmdir(
".git"));
397 "Should return true default when .git not present");
402 "Should return false default when .git not present");
405void tst_settings::setAndGetSavestate() {
406 QByteArray state(
"test_state_data");
409 QVERIFY2(read == state,
"Savestate should match");
412void tst_settings::setAndGetPos() {
413 QPoint pos(100, 200);
416 QVERIFY2(read == pos,
"Pos should match");
419void tst_settings::setAndGetSize() {
420 QSize size(800, 600);
423 QVERIFY2(read == size,
"Size should match");
426void tst_settings::setAndGetDialogGeometry() {
427 const QString key =
"testDialog";
428 QByteArray geometry(
"test_dialog_geometry");
431 QVERIFY2(read == geometry,
"Dialog geometry should match");
434void tst_settings::setAndGetDialogPos() {
435 const QString key =
"testDialog";
436 QPoint pos(100, 200);
439 QVERIFY2(read == pos,
"Dialog pos should match");
442void tst_settings::setAndGetDialogSize() {
443 const QString key =
"testDialog";
444 QSize size(640, 480);
447 QVERIFY2(read == size,
"Dialog size should match");
450void tst_settings::setAndGetDialogMaximized() {
451 const QString key =
"testDialog";
454 QVERIFY2(read ==
true,
"Dialog maximized should be true");
457 QVERIFY2(read ==
false,
"Dialog maximized should be false");
460void tst_settings::setAndGetPasswordCharsSelection() {
467void tst_settings::setAndGetPasswordChars() {
471 "PasswordChars should contain 'abc'");
476void tst_settings::setAndGetMultipleProfiles() {
477 QHash<QString, QHash<QString, QString>> profiles;
478 QHash<QString, QString> profile1;
479 profile1[
"path"] =
"/path/to/store1";
480 profiles[
"profile1"] = std::move(profile1);
482 QHash<QString, QString> profile2;
483 profile2[
"path"] =
"/path/to/store2";
484 profiles[
"profile2"] = std::move(profile2);
487 QHash<QString, QHash<QString, QString>> readProfiles =
489 QVERIFY(!readProfiles.isEmpty());
490 QVERIFY2(readProfiles.size() == 2,
"Should have exactly 2 profiles");
491 QVERIFY(readProfiles.contains(
"profile1"));
492 QVERIFY(readProfiles.contains(
"profile2"));
493 QVERIFY(readProfiles[
"profile1"].contains(
"path"));
494 QVERIFY(readProfiles[
"profile2"].contains(
"path"));
497void tst_settings::setAndGetProfileDefault() {
498 const QString expectedProfile = QStringLiteral(
"defaultProfile");
504#include "tst_settings.moc"
static auto isUseSelection(const bool &defaultValue=QVariant().toBool()) -> bool
Get whether to use selection (X11) for clipboard.
static void setMaximized(const bool &maximized)
Save maximized state.
static void setStartMinimized(const bool &startMinimized)
Save start-minimized flag.
static void setUseWebDav(const bool &useWebDav)
Save WebDAV integration flag.
static auto isUseAutoclear(const bool &defaultValue=QVariant().toBool()) -> bool
Get whether to use autoclear for clipboard.
static void setAutoclearPanelSeconds(const int &autoClearPanelSeconds)
Save panel autoclear seconds.
static void setPassExecutable(const QString &passExecutable)
Save pass executable path.
static auto getWebDavPassword(const QString &defaultValue=QVariant().toString()) -> QString
Get WebDAV password.
static auto isStartMinimized(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether application should start minimized.
static void setHidePassword(const bool &hidePassword)
Save hide password setting.
static auto isUseOtp(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether OTP support is enabled.
static void setPwgenExecutable(const QString &pwgenExecutable)
Save pwgen executable path.
static auto getPwgenExecutable(const QString &defaultValue=QVariant().toString()) -> QString
Get pwgen executable path.
static void setProfile(const QString &profile)
Save active profile name.
static void setUseTrayIcon(const bool &useTrayIcon)
Save tray icon support flag.
static void setWebDavPassword(const QString &webDavPassword)
Save WebDAV password.
static auto getInstance() -> QtPassSettings *
Get the singleton instance.
static auto isNoLineWrapping(const bool &defaultValue=QVariant().toBool()) -> bool
Get whether to disable line wrapping.
static auto getWebDavUser(const QString &defaultValue=QVariant().toString()) -> QString
Get WebDAV username.
static void setPassStore(const QString &passStore)
Save password store path.
static auto getDialogPos(const QString &key, const QPoint &defaultValue=QVariant().toPoint()) -> QPoint
Get saved dialog position.
static auto isHideContent(const bool &defaultValue=QVariant().toBool()) -> bool
Get whether to hide content (password + username).
static void setPasswordConfiguration(const PasswordConfiguration &config)
Save complete password generation configuration.
static auto getSize(const QSize &defaultValue=QVariant().toSize()) -> QSize
Get saved window size.
static void setHideOnClose(const bool &hideOnClose)
Save hide-on-close flag.
static auto getPasswordConfiguration() -> PasswordConfiguration
Get complete password generation configuration.
static auto isUseQrencode(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether qrencode support is enabled.
static void setPasswordLength(const int &passwordLength)
Save password length setting.
static auto isUseAutoclearPanel(const bool &defaultValue=QVariant().toBool()) -> bool
Get whether to use panel autoclear.
static auto isAutoPull(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether automatic pull is enabled.
static void setGitExecutable(const QString &gitExecutable)
Save git executable path.
static void setPasswordChars(const QString &passwordChars)
Save custom password characters.
static auto isUseGit(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether Git integration is enabled.
static void setUseOtp(const bool &useOtp)
Save OTP support flag.
static void setProfiles(const QHash< QString, QHash< QString, QString > > &profiles)
Save all configured profiles.
static auto getClipBoardType(const Enums::clipBoardType &defaultValue=Enums::CLIPBOARD_NEVER) -> Enums::clipBoardType
Get clipboard type as enum.
static void setUsePwgen(const bool &usePwgen)
Save pwgen support flag.
static auto isTemplateAllFields(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether template applies to all fields.
static void setPassSigningKey(const QString &passSigningKey)
Save GPG signing key.
static auto isUsePass(const bool &defaultValue=QVariant().toBool()) -> bool
Get whether to use pass (true) or GPG (false).
static auto getPassStore(const QString &defaultValue=QVariant().toString()) -> QString
Get password store directory path.
static auto getVersion(const QString &defaultValue=QVariant().toString()) -> QString
Get saved application version.
static auto isUseTemplate(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether template usage is enabled.
static auto isUseTrayIcon(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether tray icon support is enabled.
static void setUseTemplate(const bool &useTemplate)
Save template usage flag.
static void setDialogPos(const QString &key, const QPoint &pos)
Save dialog position.
static auto isAvoidCapitals(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether uppercase characters should be avoided.
static auto isAddGPGId(const bool &defaultValue=QVariant().toBool()) -> bool
Get whether to auto-add GPG ID when receiving files.
static auto getGpgExecutable(const QString &defaultValue=QVariant().toString()) -> QString
Get GPG executable path.
static void setAutoPull(const bool &autoPull)
Save automatic pull flag.
static auto getPassSigningKey(const QString &defaultValue=QVariant().toString()) -> QString
Get GPG signing key for pass.
static void setPassTemplate(const QString &passTemplate)
Save pass entry template.
static auto isUseSymbols(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether symbol characters are enabled.
static auto getQrencodeExecutable(const QString &defaultValue=QVariant().toString()) -> QString
Get qrencode executable path.
static auto getDialogSize(const QString &key, const QSize &defaultValue=QVariant().toSize()) -> QSize
Get saved dialog size.
static void setGpgExecutable(const QString &gpgExecutable)
Save GPG executable path.
static void setPasswordCharsSelection(const int &passwordCharsSelection)
Save password character selection mode.
static void setPos(const QPoint &pos)
Save window position.
static void setVersion(const QString &version)
Save application version.
static void setUseAutoclear(const bool &useAutoclear)
Save use autoclear setting.
static auto isLessRandom(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether less random password generation is enabled.
static void setAlwaysOnTop(const bool &alwaysOnTop)
Save always-on-top flag.
static auto getPassTemplate(const QString &defaultValue=QVariant().toString()) -> QString
Get pass entry template.
static void setWebDavUser(const QString &webDavUser)
Save WebDAV username.
static void setDisplayAsIs(const bool &displayAsIs)
Save display as-is setting.
static auto isMaximized(const bool &defaultValue=QVariant().toBool()) -> bool
Get maximized state.
static void setUseMonospace(const bool &useMonospace)
Save use monospace setting.
static void setDialogSize(const QString &key, const QSize &size)
Save dialog size.
static void setAvoidCapitals(const bool &avoidCapitals)
Save uppercase avoidance flag.
static void setDialogMaximized(const QString &key, const bool &maximized)
Save dialog maximized state.
static void setQrencodeExecutable(const QString &qrencodeExecutable)
Save qrencode executable path.
static void setWebDavUrl(const QString &webDavUrl)
Save WebDAV URL.
static auto getProfile(const QString &defaultValue=QVariant().toString()) -> QString
Get active profile name.
static auto getWebDavUrl(const QString &defaultValue=QVariant().toString()) -> QString
Get WebDAV URL.
static auto isUseMonospace(const bool &defaultValue=QVariant().toBool()) -> bool
Get whether to use monospace font.
static void setAddGPGId(const bool &addGPGId)
Save add GPG ID setting.
static void setUsePass(const bool &usePass)
Save use pass setting.
static auto isUseWebDav(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether WebDAV integration is enabled.
static auto isDialogMaximized(const QString &key, const bool &defaultValue=QVariant().toBool()) -> bool
Get dialog maximized state.
static auto getAutoclearPanelSeconds(const int &defaultValue=QVariant().toInt()) -> int
Get panel autoclear delay in seconds.
static auto isUsePwgen(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether pwgen support is enabled.
static void setSavestate(const QByteArray &saveState)
Save window state.
static auto isAlwaysOnTop(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether main window should stay always on top.
static auto isAvoidNumbers(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether numeric characters should be avoided.
static auto isHidePassword(const bool &defaultValue=QVariant().toBool()) -> bool
Get whether to hide password in UI.
static void setDialogGeometry(const QString &key, const QByteArray &geometry)
Save dialog geometry.
static auto getPassExecutable(const QString &defaultValue=QVariant().toString()) -> QString
Get pass executable path.
static void setUseAutoclearPanel(const bool &useAutoclearPanel)
Save use autoclear panel setting.
static void setAutoclearSeconds(const int &autoClearSeconds)
Save autoclear seconds.
static void setNoLineWrapping(const bool &noLineWrapping)
Save no line wrapping setting.
static void setUseQrencode(const bool &useQrencode)
Save qrencode support flag.
static auto getPos(const QPoint &defaultValue=QVariant().toPoint()) -> QPoint
Get saved window position.
static void setAvoidNumbers(const bool &avoidNumbers)
Save numeric avoidance flag.
static auto getDialogGeometry(const QString &key, const QByteArray &defaultValue=QVariant().toByteArray()) -> QByteArray
Get saved dialog geometry.
static auto isHideOnClose(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether closing the window hides the application.
static void setAutoPush(const bool &autoPush)
Save automatic push flag.
static void setClipBoardType(const int &clipBoardType)
Save clipboard type.
static auto getProfiles() -> QHash< QString, QHash< QString, QString > >
Get all configured profiles.
static void setSize(const QSize &size)
Save window size.
static void setLessRandom(const bool &lessRandom)
Save less-random generation flag.
static auto getAutoclearSeconds(const int &defaultValue=QVariant().toInt()) -> int
Get autoclear delay in seconds.
static void setHideContent(const bool &hideContent)
Save hide content setting.
static auto isAutoPush(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether automatic push is enabled.
static void setGeometry(const QByteArray &geometry)
Save window geometry.
static void setUseSelection(const bool &useSelection)
Save use selection setting.
static auto getGitExecutable(const QString &defaultValue=QVariant().toString()) -> QString
Get git executable path.
static void setTemplateAllFields(const bool &templateAllFields)
Save template-all-fields flag.
static auto getGeometry(const QByteArray &defaultValue=QVariant().toByteArray()) -> QByteArray
Get saved window geometry.
static void setUseSymbols(const bool &useSymbols)
Save symbol usage flag.
static auto isDisplayAsIs(const bool &defaultValue=QVariant().toBool()) -> bool
Get whether to display password as-is (no modification).
static void setUseGit(const bool &useGit)
Save Git integration flag.
static auto getSavestate(const QByteArray &defaultValue=QVariant().toByteArray()) -> QByteArray
Get saved window state.
int length
Length of the password.
enum PasswordConfiguration::characterSet selected
QString Characters[CHARSETS_COUNT]
The different character sets.