diff options
author | saturneric <[email protected]> | 2023-12-16 07:11:32 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2023-12-16 07:11:32 +0000 |
commit | 08dd9b43481d189c60acc58941005dc25a58c77f (patch) | |
tree | 38e79c1a255339d9a80f39c8dbbd94a28ec124b7 /src/test/GpgFrontendTest.cpp | |
parent | fix: use secure memory management at impl class (diff) | |
download | GpgFrontend-08dd9b43481d189c60acc58941005dc25a58c77f.tar.gz GpgFrontend-08dd9b43481d189c60acc58941005dc25a58c77f.zip |
fix: repair test cases
Diffstat (limited to 'src/test/GpgFrontendTest.cpp')
-rw-r--r-- | src/test/GpgFrontendTest.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/test/GpgFrontendTest.cpp b/src/test/GpgFrontendTest.cpp index b356a380..0cc2c45e 100644 --- a/src/test/GpgFrontendTest.cpp +++ b/src/test/GpgFrontendTest.cpp @@ -41,6 +41,8 @@ #include "core/function/GlobalSettingStation.h" #include "core/function/basic/ChannelObject.h" #include "core/function/gpg/GpgContext.h" +#include "core/function/gpg/GpgKeyImportExporter.h" +#include "core/utils/IOUtils.h" #include "spdlog/spdlog.h" namespace GpgFrontend::Test { @@ -121,8 +123,43 @@ void ConfigureGpgContext() { }); } +void ImportPrivateKeys(std::filesystem::path data_path, + const libconfig::Setting& config) { + if (config.exists("load_keys.private_keys")) { + auto& private_keys = config.lookup("load_keys.private_keys"); + for (auto& private_key : private_keys) { + if (private_key.exists("filename")) { + std::string filename; + private_key.lookupValue("filename", filename); + auto data_file_path = data_path / filename; + std::string data = ReadAllDataInFile(data_file_path.string()); + auto secret_key_copy = SecureCreateSharedObject<std::string>(data); + GpgKeyImportExporter::GetInstance(kGpgFrontendDefaultChannel) + .ImportKey(secret_key_copy); + } + } + } +} + +void SetupGlobalTestEnv() { + auto app_path = GlobalSettingStation::GetInstance().GetAppDir(); + auto test_path = app_path / "test"; + auto test_config_path = test_path / "conf" / "test.cfg"; + auto test_data_path = test_path / "data"; + + SPDLOG_INFO("test config file path: {}", test_config_path.string()); + SPDLOG_INFO("test data file path: {}", test_data_path.string()); + + libconfig::Config cfg; + ASSERT_NO_THROW(cfg.readFile(test_config_path.c_str())); + + auto& root = cfg.getRoot(); + ImportPrivateKeys(test_data_path, root); +} + auto ExecuteAllTestCase(GpgFrontendContext args) -> int { ConfigureGpgContext(); + SetupGlobalTestEnv(); testing::InitGoogleTest(&args.argc, args.argv); return RUN_ALL_TESTS(); |