From 596d2cf425c3c8495b4c4a58c61798afe9fdd536 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Sun, 26 Apr 2020 01:31:38 +0200 Subject: Refactor Config. Replaces all string configuration options with enum types that can be checked by the compiler. This prevents spelling errors, in-place configuration definitions, and inconsistent default values. The default value config getter signature was removed in favour of consistently and centrally default-initialised configuration values. Individual default values were adjusted for better security, such as the default password length, which was increased from 16 characters to 32. The already existing config option deprecation map was extended by a general migration procedure using configuration versioning. Settings were split into Roaming and Local settings, which go to their respective AppData locations on Windows. Fixes #2574 Fixes #2193 --- tests/TestAutoType.cpp | 12 ++++++------ tests/gui/TestGui.cpp | 14 +++++++------- tests/gui/TestGuiBrowser.cpp | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/TestAutoType.cpp b/tests/TestAutoType.cpp index e2ab5db1c..5898f0477 100644 --- a/tests/TestAutoType.cpp +++ b/tests/TestAutoType.cpp @@ -35,8 +35,8 @@ void TestAutoType::initTestCase() { QVERIFY(Crypto::init()); Config::createTempFileInstance(); - config()->set("AutoTypeDelay", 1); - config()->set("security/autotypeask", false); + config()->set(Config::AutoTypeDelay, 1); + config()->set(Config::Security_AutoTypeAsk, false); AutoType::createTestInstance(); QPluginLoader loader(resources()->pluginPath("keepassx-autotype-test")); @@ -54,7 +54,7 @@ void TestAutoType::initTestCase() void TestAutoType::init() { - config()->set("AutoTypeEntryTitleMatch", false); + config()->set(Config::AutoTypeEntryTitleMatch, false); m_test->clearActions(); m_db = QSharedPointer::create(); @@ -165,7 +165,7 @@ void TestAutoType::testGlobalAutoTypeWithOneMatch() void TestAutoType::testGlobalAutoTypeTitleMatch() { - config()->set("AutoTypeEntryTitleMatch", true); + config()->set(Config::AutoTypeEntryTitleMatch, true); m_test->setActiveWindowTitle("An Entry Title!"); m_test->triggerGlobalAutoType(); @@ -176,7 +176,7 @@ void TestAutoType::testGlobalAutoTypeTitleMatch() void TestAutoType::testGlobalAutoTypeUrlMatch() { - config()->set("AutoTypeEntryTitleMatch", true); + config()->set(Config::AutoTypeEntryTitleMatch, true); m_test->setActiveWindowTitle("Dummy - http://example.org/ - "); m_test->triggerGlobalAutoType(); @@ -187,7 +187,7 @@ void TestAutoType::testGlobalAutoTypeUrlMatch() void TestAutoType::testGlobalAutoTypeUrlSubdomainMatch() { - config()->set("AutoTypeEntryTitleMatch", true); + config()->set(Config::AutoTypeEntryTitleMatch, true); m_test->setActiveWindowTitle("Dummy - http://sub.example.org/ - "); m_test->triggerGlobalAutoType(); diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index f8fbfa7f1..3b97ffde8 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -99,14 +99,14 @@ void TestGui::initTestCase() QVERIFY(Crypto::init()); Config::createTempFileInstance(); // Disable autosave so we can test the modified file indicator - config()->set("AutoSaveAfterEveryChange", false); - config()->set("AutoSaveOnExit", false); + config()->set(Config::AutoSaveAfterEveryChange, false); + config()->set(Config::AutoSaveOnExit, false); // Enable the tray icon so we can test hiding/restoring the windowQByteArray - config()->set("GUI/ShowTrayIcon", true); + config()->set(Config::GUI_ShowTrayIcon, true); // Disable advanced settings mode (activate within individual tests to test advanced settings) - config()->set("GUI/AdvancedSettings", false); + config()->set(Config::GUI_AdvancedSettings, false); // Disable the update check first time alert - config()->set("UpdateCheckMessageShown", true); + config()->set(Config::UpdateCheckMessageShown, true); Bootstrap::bootstrapApplication(); @@ -342,7 +342,7 @@ void TestGui::testMergeDatabase() void TestGui::testAutoreloadDatabase() { - config()->set("AutoReloadOnChange", false); + config()->set(Config::AutoReloadOnChange, false); // Test accepting new file in autoreload MessageBox::setNextAnswer(MessageBox::Yes); @@ -375,7 +375,7 @@ void TestGui::testAutoreloadDatabase() // Test accepting a merge of edits into autoreload // Turn on autoload so we only get one messagebox (for the merge) - config()->set("AutoReloadOnChange", true); + config()->set(Config::AutoReloadOnChange, true); // Modify some entries testEditEntry(); diff --git a/tests/gui/TestGuiBrowser.cpp b/tests/gui/TestGuiBrowser.cpp index 1750caa80..7e5d89df4 100644 --- a/tests/gui/TestGuiBrowser.cpp +++ b/tests/gui/TestGuiBrowser.cpp @@ -69,14 +69,14 @@ void TestGuiBrowser::initTestCase() QVERIFY(Crypto::init()); Config::createTempFileInstance(); // Disable autosave so we can test the modified file indicator - config()->set("AutoSaveAfterEveryChange", false); - config()->set("AutoSaveOnExit", false); + config()->set(Config::AutoSaveAfterEveryChange, false); + config()->set(Config::AutoSaveOnExit, false); // Enable the tray icon so we can test hiding/restoring the windowQByteArray - config()->set("GUI/ShowTrayIcon", true); + config()->set(Config::GUI_ShowTrayIcon, true); // Disable advanced settings mode (activate within individual tests to test advanced settings) - config()->set("GUI/AdvancedSettings", false); + config()->set(Config::GUI_AdvancedSettings, false); // Disable the update check first time alert - config()->set("UpdateCheckMessageShown", true); + config()->set(Config::UpdateCheckMessageShown, true); m_mainWindow.reset(new MainWindow()); Bootstrap::restoreMainWindowState(*m_mainWindow); @@ -146,7 +146,7 @@ void TestGuiBrowser::cleanupTestCase() void TestGuiBrowser::testEntrySettings() { // Enable the Browser Integration - config()->set("Browser/Enabled", true); + config()->set(Config::Browser_Enabled, true); auto* toolBar = m_mainWindow->findChild("toolBar"); auto* entryView = m_dbWidget->findChild("entryView"); -- cgit v1.2.3