mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-04-01 19:47:39 +03:00
Remove Config::createTempFileInstance
This commit is contained in:
parent
fcb32efd05
commit
37ddbb3cd2
12 changed files with 63 additions and 39 deletions
|
@ -619,21 +619,6 @@ void Config::createConfigFromFile(const QString& configFileName, const QString&
|
|||
qApp);
|
||||
}
|
||||
|
||||
void Config::createTempFileInstance()
|
||||
{
|
||||
if (m_instance) {
|
||||
delete m_instance;
|
||||
}
|
||||
auto tmpFileName = QString("%1/%2_settings.XXXXXX").arg(QDir::tempPath(), QCoreApplication::applicationName());
|
||||
auto tmpFile = new QTemporaryFile(tmpFileName);
|
||||
if (!tmpFile->open()) {
|
||||
Q_ASSERT_X(false, __func__, "Failed to create temporary config settings file");
|
||||
}
|
||||
tmpFile->close();
|
||||
m_instance = new Config(tmpFileName, "", qApp);
|
||||
tmpFile->setParent(m_instance);
|
||||
}
|
||||
|
||||
bool Config::isPortable()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
|
|
|
@ -230,7 +230,6 @@ public:
|
|||
|
||||
static Config* instance();
|
||||
static void createConfigFromFile(const QString& configFileName, const QString& localConfigFileName = {});
|
||||
static void createTempFileInstance();
|
||||
static bool isPortable();
|
||||
static QString portableConfigDir();
|
||||
|
||||
|
|
|
@ -154,16 +154,16 @@ endif()
|
|||
|
||||
if(WITH_XC_AUTOTYPE)
|
||||
add_unit_test(NAME testautotype SOURCES TestAutoType.cpp
|
||||
LIBS ${TEST_LIBRARIES})
|
||||
LIBS testsupport ${TEST_LIBRARIES})
|
||||
set_target_properties(testautotype PROPERTIES ENABLE_EXPORTS ON)
|
||||
endif()
|
||||
|
||||
if(WITH_XC_SSHAGENT)
|
||||
add_unit_test(NAME testopensshkey SOURCES TestOpenSSHKey.cpp
|
||||
LIBS sshagent ${TEST_LIBRARIES})
|
||||
LIBS sshagent testsupport ${TEST_LIBRARIES})
|
||||
if(NOT WIN32)
|
||||
add_unit_test(NAME testsshagent SOURCES TestSSHAgent.cpp
|
||||
LIBS sshagent ${TEST_LIBRARIES})
|
||||
LIBS sshagent testsupport ${TEST_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
|
|
@ -30,13 +30,15 @@
|
|||
#include "crypto/Crypto.h"
|
||||
#include "gui/MessageBox.h"
|
||||
#include "gui/osutils/OSUtils.h"
|
||||
#include "util/TemporaryFile.h"
|
||||
|
||||
QTEST_GUILESS_MAIN(TestAutoType)
|
||||
|
||||
void TestAutoType::initTestCase()
|
||||
{
|
||||
QVERIFY(Crypto::init());
|
||||
Config::createTempFileInstance();
|
||||
// Create temporary config file
|
||||
Config::createConfigFromFile(TemporaryFile::createTempConfigFile(), {});
|
||||
config()->set(Config::AutoTypeDelay, 1);
|
||||
config()->set(Config::Security_AutoTypeAsk, false);
|
||||
AutoType::createTestInstance();
|
||||
|
|
|
@ -66,7 +66,9 @@ void TestCli::initTestCase()
|
|||
{
|
||||
QVERIFY(Crypto::init());
|
||||
|
||||
Config::createTempFileInstance();
|
||||
// Create temporary config file
|
||||
Config::createConfigFromFile(TemporaryFile::createTempConfigFile(), {});
|
||||
|
||||
QLocale::setDefault(QLocale::c());
|
||||
Bootstrap::bootstrap();
|
||||
|
||||
|
|
|
@ -30,17 +30,19 @@ QTEST_GUILESS_MAIN(TestSSHAgent)
|
|||
void TestSSHAgent::initTestCase()
|
||||
{
|
||||
QVERIFY(Crypto::init());
|
||||
Config::createTempFileInstance();
|
||||
|
||||
m_agentSocketFile.setAutoRemove(true);
|
||||
QVERIFY(m_agentSocketFile.open());
|
||||
// Create temporary config file
|
||||
Config::createConfigFromFile(TemporaryFile::createTempConfigFile(), {});
|
||||
|
||||
m_agentSocketFileName = m_agentSocketFile.fileName();
|
||||
// default config must not enable agent
|
||||
SSHAgent agent;
|
||||
QVERIFY(!agent.isEnabled());
|
||||
|
||||
m_agentSocketFile.reset(new TemporaryFile(this));
|
||||
|
||||
m_agentSocketFileName = m_agentSocketFile->fileName();
|
||||
QVERIFY(!m_agentSocketFileName.isEmpty());
|
||||
|
||||
// let ssh-agent re-create it as a socket
|
||||
QVERIFY(m_agentSocketFile.remove());
|
||||
|
||||
QStringList arguments;
|
||||
arguments << "-D" << "-a" << m_agentSocketFileName;
|
||||
|
||||
|
@ -85,13 +87,18 @@ void TestSSHAgent::initTestCase()
|
|||
QVERIFY(m_key.parsePKCS1PEM(keyData));
|
||||
}
|
||||
|
||||
void TestSSHAgent::init()
|
||||
{
|
||||
// Reset the config state
|
||||
SSHAgent agent;
|
||||
agent.setEnabled(false);
|
||||
QString empty;
|
||||
agent.setAuthSockOverride(empty);
|
||||
}
|
||||
|
||||
void TestSSHAgent::testConfiguration()
|
||||
{
|
||||
SSHAgent agent;
|
||||
|
||||
// default config must not enable agent
|
||||
QVERIFY(!agent.isEnabled());
|
||||
|
||||
agent.setEnabled(true);
|
||||
QVERIFY(agent.isEnabled());
|
||||
|
||||
|
@ -291,6 +298,4 @@ void TestSSHAgent::cleanupTestCase()
|
|||
m_agentProcess.terminate();
|
||||
m_agentProcess.waitForFinished();
|
||||
}
|
||||
|
||||
m_agentSocketFile.remove();
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#define TESTSSHAGENT_H
|
||||
|
||||
#include "sshagent/OpenSSHKey.h"
|
||||
#include "util/TemporaryFile.h"
|
||||
#include <QProcess>
|
||||
#include <QTemporaryFile>
|
||||
#include <QUuid>
|
||||
|
||||
class TestSSHAgent : public QObject
|
||||
|
@ -29,6 +29,7 @@ class TestSSHAgent : public QObject
|
|||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void init();
|
||||
void testConfiguration();
|
||||
void testIdentity();
|
||||
void testRemoveOnClose();
|
||||
|
@ -41,7 +42,7 @@ private slots:
|
|||
void cleanupTestCase();
|
||||
|
||||
private:
|
||||
QTemporaryFile m_agentSocketFile;
|
||||
QScopedPointer<TemporaryFile> m_agentSocketFile;
|
||||
QString m_agentSocketFileName;
|
||||
QProcess m_agentProcess;
|
||||
OpenSSHKey m_key;
|
||||
|
|
|
@ -94,7 +94,10 @@ int main(int argc, char* argv[])
|
|||
void TestGui::initTestCase()
|
||||
{
|
||||
QVERIFY(Crypto::init());
|
||||
Config::createTempFileInstance();
|
||||
|
||||
// Create temporary config file
|
||||
Config::createConfigFromFile(TemporaryFile::createTempConfigFile(), {});
|
||||
|
||||
QLocale::setDefault(QLocale::c());
|
||||
Application::bootstrap();
|
||||
|
||||
|
|
|
@ -58,7 +58,8 @@ int main(int argc, char* argv[])
|
|||
void TestGuiBrowser::initTestCase()
|
||||
{
|
||||
QVERIFY(Crypto::init());
|
||||
Config::createTempFileInstance();
|
||||
// Create temporary config file
|
||||
Config::createConfigFromFile(TemporaryFile::createTempConfigFile(), {});
|
||||
// Disable autosave so we can test the modified file indicator
|
||||
config()->set(Config::AutoSaveAfterEveryChange, false);
|
||||
config()->set(Config::AutoSaveOnExit, false);
|
||||
|
|
|
@ -136,7 +136,8 @@ TestGuiFdoSecrets::~TestGuiFdoSecrets() = default;
|
|||
void TestGuiFdoSecrets::initTestCase()
|
||||
{
|
||||
VERIFY(Crypto::init());
|
||||
Config::createTempFileInstance();
|
||||
// Create temporary config file
|
||||
Config::createConfigFromFile(TemporaryFile::createTempConfigFile(), {});
|
||||
config()->set(Config::AutoSaveAfterEveryChange, false);
|
||||
config()->set(Config::AutoSaveOnExit, false);
|
||||
config()->set(Config::GUI_ShowTrayIcon, true);
|
||||
|
|
|
@ -17,6 +17,29 @@
|
|||
|
||||
#include "TemporaryFile.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QPointer>
|
||||
|
||||
namespace
|
||||
{
|
||||
QPointer<TemporaryFile> g_tempConfigFile;
|
||||
}
|
||||
|
||||
QString TemporaryFile::createTempConfigFile()
|
||||
{
|
||||
if (!qApp) {
|
||||
Q_ASSERT(false);
|
||||
return {};
|
||||
}
|
||||
if (g_tempConfigFile) {
|
||||
delete g_tempConfigFile;
|
||||
}
|
||||
auto tmpFileName = QString("%1/%2_settings.XXXXXX").arg(QDir::tempPath(), QCoreApplication::applicationName());
|
||||
g_tempConfigFile = new TemporaryFile(tmpFileName, qApp);
|
||||
return g_tempConfigFile->fileName();
|
||||
}
|
||||
|
||||
TemporaryFile::TemporaryFile()
|
||||
: TemporaryFile(nullptr)
|
||||
{
|
||||
|
|
|
@ -34,6 +34,8 @@ public:
|
|||
using QFile::open;
|
||||
bool open();
|
||||
bool copyFromFile(const QString& otherFileName);
|
||||
|
||||
static QString createTempConfigFile();
|
||||
};
|
||||
|
||||
#endif // KEEPASSXC_TEMPORARYFILE_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue