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 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()) {
81 QFile::remove(settingsFile);
82 QFile::copy(m_settingsBackupPath, settingsFile);
83 QFile::remove(m_settingsBackupPath);
87void tst_settings::getPasswordConfigurationDefault() {
89 QVERIFY(config.
length >= 0);
93void tst_settings::setAndGetPasswordConfiguration() {
94 PasswordConfiguration config;
102 QCOMPARE(readConfig.
length, 20);
104 "Password config should be ALPHABETICAL");
107void tst_settings::getProfilesEmpty() {
108 QHash<QString, QHash<QString, QString>> emptyProfiles;
111 QHash<QString, QHash<QString, QString>> profiles =
113 QVERIFY(profiles.isEmpty());
116void tst_settings::setAndGetProfiles() {
117 QHash<QString, QHash<QString, QString>> profiles;
118 QHash<QString, QString> profile1;
119 profile1.insert(
"path",
"/test/path");
120 profile1.insert(
"signingKey",
"ABC123");
121 profiles.insert(
"profile1", profile1);
125 QHash<QString, QHash<QString, QString>> readProfiles =
127 QVERIFY(!readProfiles.isEmpty());
128 QVERIFY(readProfiles.contains(
"profile1"));
129 QCOMPARE(readProfiles[
"profile1"][
"path"], QString(
"/test/path"));
132void tst_settings::setAndGetVersion() {
135 QVERIFY2(version ==
"1.5.1",
"Version should be 1.5.1");
138void tst_settings::setAndGetGeometry() {
139 QByteArray geometry(
"test_geometry_data");
142 QVERIFY2(read == geometry,
"Geometry should match");
145void tst_settings::getPassStore() {
147 QVERIFY2(store.isEmpty() || store.startsWith(
"/") || store.contains(
"/"),
148 "Pass store should be empty or a plausible path");
151void tst_settings::setAndGetPassStore() {
154 QVERIFY(store.contains(
"test-store"));
160 void (*setter)(
const bool &);
161 bool (*getter)(
const bool &);
164const BoolSetting boolSettings[] = {
213void tst_settings::boolRoundTrip_data() {
214 QTest::addColumn<QString>(
"setting");
215 QTest::addColumn<bool>(
"testValue");
217 for (
const auto &s : boolSettings) {
218 QByteArray name(s.name);
219 QTest::newRow(name +
"_true") << s.name <<
true;
220 QTest::newRow(name +
"_false") << s.name <<
false;
224void tst_settings::boolRoundTrip() {
225 QFETCH(QString, setting);
226 QFETCH(
bool, testValue);
228 for (
const auto &s : boolSettings) {
229 if (setting == s.name) {
231 QVERIFY2(s.getter(!testValue) == testValue,
232 qPrintable(QString(
"%1 should be %2, got %3")
234 .arg(testValue ?
"true" :
"false")
235 .arg(s.getter(!testValue) ?
"true" :
"false")));
239 QFAIL(qPrintable(QString(
"Unknown setting: %1").arg(setting)));
242void tst_settings::setAndGetClipBoardType() {
247void tst_settings::setAndGetPasswordLength() {
250 QCOMPARE(config.
length, 24);
256 void (*setter)(
const int &);
257 int (*getter)(
const int &);
260const IntSetting intSettings[] = {
267struct StringSetting {
269 void (*setter)(
const QString &);
270 QString (*getter)(
const QString &);
273const StringSetting stringSettings[] = {
297void tst_settings::intRoundTrip_data() {
298 QTest::addColumn<QString>(
"setting");
299 QTest::addColumn<int>(
"testValue");
301 for (
const auto &s : intSettings) {
302 QByteArray name(s.name);
303 QTest::newRow(name +
"_30") << s.name << 30;
304 QTest::newRow(name +
"_60") << s.name << 60;
308void tst_settings::intRoundTrip() {
309 QFETCH(QString, setting);
310 QFETCH(
int, testValue);
312 for (
const auto &s : intSettings) {
313 if (setting == s.name) {
315 QCOMPARE(s.getter(-1), testValue);
319 QFAIL(qPrintable(QString(
"Unknown setting: %1").arg(setting)));
322void tst_settings::stringRoundTrip_data() {
323 QTest::addColumn<QString>(
"setting");
324 QTest::addColumn<QString>(
"testValue");
326 auto addString = [](
const char *name,
const QString &value) {
327 QTest::newRow((QByteArray(name) +
"_" + value.toUtf8()).constData())
331 addString(
"passSigningKey",
"testkey123");
332 addString(
"passSigningKey",
"anotherkey456");
333 addString(
"passExecutable",
"/usr/bin/pass");
334 addString(
"passExecutable",
"/usr/local/bin/pass");
335 addString(
"gitExecutable",
"/usr/bin/git");
336 addString(
"gitExecutable",
"/usr/local/bin/git");
337 addString(
"gpgExecutable",
"/usr/bin/gpg");
338 addString(
"gpgExecutable",
"/usr/local/bin/gpg");
339 addString(
"pwgenExecutable",
"/usr/bin/pwgen");
340 addString(
"pwgenExecutable",
"/usr/local/bin/pwgen");
341 addString(
"qrencodeExecutable",
"/usr/bin/qrencode");
342 addString(
"qrencodeExecutable",
"/usr/local/bin/qrencode");
343 addString(
"webDavUrl",
"https://dav.example.com/pass");
344 addString(
"webDavUrl",
"https://dav2.example.com/pass");
345 addString(
"webDavUser",
"testuser");
346 addString(
"webDavUser",
"admin");
347 addString(
"webDavPassword",
"secretpassword");
348 addString(
"webDavPassword",
"anothersecret");
349 addString(
"profile",
"work");
350 addString(
"profile",
"personal");
351 addString(
"passTemplate",
"username: {username}\npassword: {password}");
352 addString(
"passTemplate",
"user: {username}\npass: {password}");
355void tst_settings::stringRoundTrip() {
356 QFETCH(QString, setting);
357 QFETCH(QString, testValue);
359 for (
const auto &s : stringSettings) {
360 if (setting == s.name) {
362 QCOMPARE(s.getter(QString()), testValue);
366 QFAIL(qPrintable(QString(
"Unknown setting: %1").arg(setting)));
369void tst_settings::autoDetectGit() {
370 QTemporaryDir tempDir;
373 QDir gitDir(tempDir.path());
374 QVERIFY(gitDir.mkdir(
".git"));
380 "Should auto-detect .git and return true when default is true");
385 "Should return false when default is false, even if .git exists");
387 QVERIFY(gitDir.rmdir(
".git"));
393 "Should return true default when .git not present");
398 "Should return false default when .git not present");
401void tst_settings::setAndGetSavestate() {
402 QByteArray state(
"test_state_data");
405 QVERIFY2(read == state,
"Savestate should match");
408void tst_settings::setAndGetPos() {
409 QPoint pos(100, 200);
412 QVERIFY2(read == pos,
"Pos should match");
415void tst_settings::setAndGetSize() {
416 QSize size(800, 600);
419 QVERIFY2(read == size,
"Size should match");
422void tst_settings::setAndGetDialogGeometry() {
423 const QString key =
"testDialog";
424 QByteArray geometry(
"test_dialog_geometry");
427 QVERIFY2(read == geometry,
"Dialog geometry should match");
430void tst_settings::setAndGetDialogPos() {
431 const QString key =
"testDialog";
432 QPoint pos(100, 200);
435 QVERIFY2(read == pos,
"Dialog pos should match");
438void tst_settings::setAndGetDialogSize() {
439 const QString key =
"testDialog";
440 QSize size(640, 480);
443 QVERIFY2(read == size,
"Dialog size should match");
446void tst_settings::setAndGetDialogMaximized() {
447 const QString key =
"testDialog";
450 QVERIFY2(read ==
true,
"Dialog maximized should be true");
453 QVERIFY2(read ==
false,
"Dialog maximized should be false");
456void tst_settings::setAndGetPasswordCharsSelection() {
463void tst_settings::setAndGetPasswordChars() {
467 "PasswordChars should contain 'abc'");
472void tst_settings::setAndGetMultipleProfiles() {
473 QHash<QString, QHash<QString, QString>> profiles;
474 QHash<QString, QString> profile1;
475 profile1[
"path"] =
"/path/to/store1";
476 profiles[
"profile1"] = std::move(profile1);
478 QHash<QString, QString> profile2;
479 profile2[
"path"] =
"/path/to/store2";
480 profiles[
"profile2"] = std::move(profile2);
483 QHash<QString, QHash<QString, QString>> readProfiles =
485 QVERIFY(readProfiles.size() >= 1);
486 QVERIFY(readProfiles.contains(
"profile1"));
487 QVERIFY(readProfiles.contains(
"profile2"));
488 QVERIFY(readProfiles[
"profile1"].contains(
"path"));
489 QVERIFY(readProfiles[
"profile2"].contains(
"path"));
492void tst_settings::setAndGetProfileDefault() {
493 const QString expectedProfile = QStringLiteral(
"defaultProfile");
499#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 void setPasswordCharsselection(const int &passwordCharsSelection)
Save password character selection mode.
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 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.