diff options
author | Saturneric <[email protected]> | 2021-09-20 09:35:57 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2021-09-20 09:35:57 +0000 |
commit | 8544bb3ed9ccf09f3082c3032381a1b61dc5e122 (patch) | |
tree | e5b12fd9c1331718dd60926ed7b4056361a8b68f /test/GpgCoreTestKeyModel.cpp | |
parent | Support multi-channel Context. (diff) | |
download | GpgFrontend-8544bb3ed9ccf09f3082c3032381a1b61dc5e122.tar.gz GpgFrontend-8544bb3ed9ccf09f3082c3032381a1b61dc5e122.zip |
The basic functions of the core pass the test.
Adjust and improve the core part of the interface.
Diffstat (limited to '')
-rw-r--r-- | test/GpgCoreTestKeyModel.cpp (renamed from test/GpgCoreTest.cpp) | 137 |
1 files changed, 18 insertions, 119 deletions
diff --git a/test/GpgCoreTest.cpp b/test/GpgCoreTestKeyModel.cpp index 7705e8b0..1d405cf4 100644 --- a/test/GpgCoreTest.cpp +++ b/test/GpgCoreTestKeyModel.cpp @@ -24,110 +24,17 @@ #include "GpgFrontendTest.h" -#include <gpg-error.h> -#include <gtest/gtest.h> -#include <boost/date_time/gregorian/parsers.hpp> -#include <boost/dll.hpp> -#include <boost/filesystem/operations.hpp> -#include <boost/filesystem/path.hpp> -#include <fstream> -#include <memory> -#include <string> -#include <vector> - -#include "gpg/GpgConstants.h" #include "gpg/function/GpgKeyGetter.h" -#include "gpg/function/GpgKeyImportExportor.h" -#include "gpg/function/GpgKeyOpera.h" - -TEST(GpgKeyTest, GpgCoreTest) {} -class GpgCoreTest : public ::testing::Test { - protected: - std::vector<GpgFrontend::StdBypeArrayPtr> secret_keys_; - - boost::filesystem::path parent_path = - boost::dll::program_location().parent_path(); - - boost::filesystem::path config_path = parent_path / "conf" / "core.cfg"; - - GpgCoreTest() = default; - - virtual ~GpgCoreTest() = default; - - virtual void SetUp() { - DLOG(INFO) << "SetUp called"; - using namespace libconfig; - Config cfg; - ASSERT_NO_THROW(cfg.readFile(config_path.c_str())); - - const Setting& root = cfg.getRoot(); - ASSERT_TRUE(root.exists("independent_database")); - bool independent_database = true; - ASSERT_TRUE(root.lookupValue("independent_database", independent_database)); - - DLOG(INFO) << "SetUp independent_database"; - if (independent_database) { - ASSERT_TRUE(root.exists("independent_db_path")); - std::string relative_db_path; - - ASSERT_TRUE(root.lookupValue("independent_db_path", relative_db_path)); - auto db_path = parent_path / relative_db_path; - if (!boost::filesystem::exists(db_path)) { - boost::filesystem::create_directory(db_path); - } - - DLOG(INFO) << "GpgFrontend::GpgContext::CreateInstance"; - GpgFrontend::GpgContext::CreateInstance( - 1, std::make_unique<GpgFrontend::GpgContext>(true, db_path.c_str())); - DLOG(INFO) << "db_path " << db_path; - } - - ASSERT_TRUE(root.exists("data_path")); - std::string relative_data_path; - ASSERT_TRUE(root.lookupValue("data_path", relative_data_path)); - auto data_path = parent_path / relative_data_path; - ASSERT_TRUE(boost::filesystem::exists(data_path)); - - if (root.exists("load_keys.private_keys")) { - LOG(INFO) << "loading private keys"; - auto& private_keys = root.lookup("load_keys.private_keys"); - for (auto it = private_keys.begin(); it != private_keys.end(); it++) { - ASSERT_TRUE(it->exists("filename")); - std::string filename; - it->lookupValue("filename", filename); - auto data_file_path = data_path / filename; - DLOG(INFO) << "private file path" << data_file_path.string(); - std::string data = - GpgFrontend::read_all_data_in_file(data_file_path.string()); - secret_keys_.push_back(std::make_unique<std::string>(data)); - } - LOG(INFO) << "loaded private keys"; - } - - GpgFrontend::GpgContext::GetInstance(1).SetPassphraseCb( - GpgFrontend::GpgContext::test_passphrase_cb); - for (auto& secret_key : secret_keys_) { - GpgFrontend::GpgKeyImportExportor::GetInstance(1).ImportKey( - std::move(secret_key)); - } - } - - virtual void TearDown() {} - - private: - void dealing_private_keys() {} - - void configure_independent_database() {} -}; +// Should be used once and once-only +INITIALIZE_EASYLOGGINGPP TEST_F(GpgCoreTest, CoreInitTest) { - auto& ctx = GpgFrontend::GpgContext::GetInstance(1); - DLOG(INFO) << "CoreInitTest ctx DatabasePath " << ctx.GetInfo().DatabasePath; + auto& ctx = GpgFrontend::GpgContext::GetInstance(default_channel); auto& ctx_default = GpgFrontend::GpgContext::GetInstance(); - DLOG(INFO) << "CoreInitTest ctx_default DatabasePath " - << ctx_default.GetInfo().DatabasePath; ASSERT_TRUE(ctx.good()); + ASSERT_TRUE(ctx_default.good()); + ASSERT_EQ(ctx_default.GetInfo().DatabasePath, "default"); } TEST_F(GpgCoreTest, GpgDataTest) { @@ -137,14 +44,12 @@ TEST_F(GpgCoreTest, GpgDataTest) { GpgFrontend::GpgData data(data_buff.data(), data_buff.size()); auto out_buffer = data.Read2Buffer(); - LOG(INFO) << "in_buffer size " << data_buff.size(); - LOG(INFO) << "out_buffer size " << out_buffer->size(); ASSERT_EQ(out_buffer->size(), 64); } TEST_F(GpgCoreTest, GpgKeyTest) { - auto key = GpgFrontend::GpgKeyGetter::GetInstance(1).GetKey( - "9490795B78F8AFE9F93BD09281704859182661FB"); + auto key = GpgFrontend::GpgKeyGetter::GetInstance(default_channel) + .GetKey("9490795B78F8AFE9F93BD09281704859182661FB"); ASSERT_TRUE(key.good()); ASSERT_TRUE(key.is_private_key()); ASSERT_TRUE(key.has_master_key()); @@ -186,8 +91,8 @@ TEST_F(GpgCoreTest, GpgKeyTest) { } TEST_F(GpgCoreTest, GpgSubKeyTest) { - auto key = GpgFrontend::GpgKeyGetter::GetInstance(1).GetKey( - "9490795B78F8AFE9F93BD09281704859182661FB"); + auto key = GpgFrontend::GpgKeyGetter::GetInstance(default_channel) + .GetKey("9490795B78F8AFE9F93BD09281704859182661FB"); auto sub_keys = key.subKeys(); ASSERT_EQ(sub_keys->size(), 2); @@ -216,8 +121,8 @@ TEST_F(GpgCoreTest, GpgSubKeyTest) { } TEST_F(GpgCoreTest, GpgUIDTest) { - auto key = GpgFrontend::GpgKeyGetter::GetInstance(1).GetKey( - "9490795B78F8AFE9F93BD09281704859182661FB"); + auto key = GpgFrontend::GpgKeyGetter::GetInstance(default_channel) + .GetKey("9490795B78F8AFE9F93BD09281704859182661FB"); auto uids = key.uids(); ASSERT_EQ(uids->size(), 1); auto& uid = uids->front(); @@ -231,8 +136,8 @@ TEST_F(GpgCoreTest, GpgUIDTest) { } TEST_F(GpgCoreTest, GpgKeySignatureTest) { - auto key = GpgFrontend::GpgKeyGetter::GetInstance(1).GetKey( - "9490795B78F8AFE9F93BD09281704859182661FB"); + auto key = GpgFrontend::GpgKeyGetter::GetInstance(default_channel) + .GetKey("9490795B78F8AFE9F93BD09281704859182661FB"); auto uids = key.uids(); ASSERT_EQ(uids->size(), 1); auto& uid = uids->front(); @@ -255,17 +160,11 @@ TEST_F(GpgCoreTest, GpgKeySignatureTest) { } TEST_F(GpgCoreTest, GpgKeyGetterTest) { - auto key = GpgFrontend::GpgKeyGetter::GetInstance(1).GetKey( - "9490795B78F8AFE9F93BD09281704859182661FB"); + auto key = GpgFrontend::GpgKeyGetter::GetInstance(default_channel) + .GetKey("9490795B78F8AFE9F93BD09281704859182661FB"); ASSERT_TRUE(key.good()); - auto keys = GpgFrontend::GpgKeyGetter::GetInstance(1).FetchKey(); - ASSERT_GE(keys->size(), 1); - + auto keys = + GpgFrontend::GpgKeyGetter::GetInstance(default_channel).FetchKey(); + ASSERT_GE(keys->size(), secret_keys_.size()); ASSERT_TRUE(find(keys->begin(), keys->end(), key) != keys->end()); } - -TEST_F(GpgCoreTest, GpgKeyDeleteTest) { - // GpgFrontend::GpgKeyOpera::GetInstance().DeleteKeys( - // std::move(std::make_unique<std::vector<std::string>>( - // 1, "9490795B78F8AFE9F93BD09281704859182661FB"))); -} |