diff --git a/common/include/common/IAuthenticationManager.hpp b/common/include/common/IAuthenticationManager.hpp index 262b9601e..e2d265ae1 100644 --- a/common/include/common/IAuthenticationManager.hpp +++ b/common/include/common/IAuthenticationManager.hpp @@ -5,9 +5,8 @@ // Standard imports #include - namespace SDMS { - +struct LogContext; /** * Interface class for managing authenticating * @@ -26,7 +25,7 @@ class IAuthenticationManager { * Increments the number of times that the key has been accessed, this is *useful information when deciding if a key should be purged. **/ - virtual void incrementKeyAccessCounter(const std::string &public_key) = 0; + virtual void incrementKeyAccessCounter(const std::string &public_key, LogContext log_context) = 0; /** * Will return true if the public key is known. This is also dependent on the @@ -39,7 +38,7 @@ class IAuthenticationManager { * - SESSION * - PERSISTENT **/ - virtual bool hasKey(const std::string &pub_key) const = 0; + virtual bool hasKey(const std::string &pub_key, LogContext log_context) const = 0; /** * Will get the unique id or throw an error @@ -49,7 +48,7 @@ class IAuthenticationManager { * - SESSION * - PERSISTENT - user or repo **/ - virtual std::string getUID(const std::string &pub_key) const = 0; + virtual std::string getUID(const std::string &pub_key, LogContext log_context) const = 0; /** * Purge keys if needed diff --git a/common/source/operators/AuthenticationOperator.cpp b/common/source/operators/AuthenticationOperator.cpp index e611bd74f..50a82bd4e 100644 --- a/common/source/operators/AuthenticationOperator.cpp +++ b/common/source/operators/AuthenticationOperator.cpp @@ -4,10 +4,14 @@ // Local public includes #include "common/TraceException.hpp" +#include "common/DynaLog.hpp" // Standard includes #include #include +#include +#include +#include namespace SDMS { @@ -25,17 +29,22 @@ void AuthenticationOperator::execute(IMessage &message) { if (message.exists(MessageAttribute::KEY) == 0) { EXCEPT(1, "'KEY' attribute not defined."); } + // 🔹 Generate correlation ID for this request + boost::uuids::random_generator generator; + boost::uuids::uuid uuid = generator(); + LogContext log_context; + log_context.correlation_id = boost::uuids::to_string(uuid); m_authentication_manager->purge(); std::string key = std::get(message.get(MessageAttribute::KEY)); std::string uid = "anon"; - if (m_authentication_manager->hasKey(key)) { - m_authentication_manager->incrementKeyAccessCounter(key); + if (m_authentication_manager->hasKey(key, log_context)) { + m_authentication_manager->incrementKeyAccessCounter(key, log_context); try { - uid = m_authentication_manager->getUID(key); + uid = m_authentication_manager->getUID(key, log_context); } catch (const std::exception& e) { // Log the exception to help diagnose authentication issues std::cerr << "[AuthenticationOperator] Failed to get UID for key: " diff --git a/common/tests/unit/test_OperatorFactory.cpp b/common/tests/unit/test_OperatorFactory.cpp index f91bdcc2a..9f07f9fed 100644 --- a/common/tests/unit/test_OperatorFactory.cpp +++ b/common/tests/unit/test_OperatorFactory.cpp @@ -10,6 +10,7 @@ #include "common/MessageFactory.hpp" #include "common/OperatorFactory.hpp" #include "common/OperatorTypes.hpp" +#include "common/DynaLog.hpp" // Third party includes #include @@ -38,15 +39,15 @@ class DummyAuthManager : public IAuthenticationManager { /** * Methods only available via the interface **/ - virtual void incrementKeyAccessCounter(const std::string &pub_key) final { + virtual void incrementKeyAccessCounter(const std::string &pub_key, LogContext log_context) final { ++m_counters.at(pub_key); } - virtual bool hasKey(const std::string &pub_key) const { + virtual bool hasKey(const std::string &pub_key, LogContext log_context) const { return m_counters.count(pub_key); } // Just assume all keys map to the anon_uid - virtual std::string getUID(const std::string &) const { + virtual std::string getUID(const std::string &, LogContext log_context) const { return "authenticated_uid"; } diff --git a/core/server/AuthMap.cpp b/core/server/AuthMap.cpp index 3db306f97..0b7b32702 100644 --- a/core/server/AuthMap.cpp +++ b/core/server/AuthMap.cpp @@ -168,7 +168,8 @@ size_t AuthMap::size(const PublicKeyType pub_key_type) const { } void AuthMap::incrementKeyAccessCounter(const PublicKeyType pub_key_type, - const std::string &public_key) { + const std::string &public_key, + LogContext log_context) { if (pub_key_type == PublicKeyType::TRANSIENT) { lock_guard lock(m_trans_clients_mtx); if (m_trans_auth_clients.count(public_key)) { @@ -183,7 +184,8 @@ void AuthMap::incrementKeyAccessCounter(const PublicKeyType pub_key_type, } bool AuthMap::hasKey(const PublicKeyType pub_key_type, - const std::string &public_key) const { + const std::string &public_key, + LogContext log_context) const { if (pub_key_type == PublicKeyType::TRANSIENT) { lock_guard lock(m_trans_clients_mtx); return m_trans_auth_clients.count(public_key) > 0; @@ -203,7 +205,7 @@ bool AuthMap::hasKey(const PublicKeyType pub_key_type, try { DatabaseAPI db(m_db_url, m_db_user, m_db_pass); std::string uid; - if (db.uidByPubKey(public_key, uid)) { + if (db.uidByPubKey(public_key, uid, log_context)) { return true; } } catch (const std::exception& e) { @@ -217,9 +219,10 @@ bool AuthMap::hasKey(const PublicKeyType pub_key_type, } std::string AuthMap::getUID(const PublicKeyType pub_key_type, - const std::string &public_key) const { + const std::string &public_key, + LogContext log_context) const { - std::string uid = getUIDSafe(pub_key_type, public_key); + std::string uid = getUIDSafe(pub_key_type, public_key, log_context); if (uid.empty()) { if (pub_key_type == PublicKeyType::TRANSIENT) { @@ -238,7 +241,8 @@ std::string AuthMap::getUID(const PublicKeyType pub_key_type, } std::string AuthMap::getUIDSafe(const PublicKeyType pub_key_type, - const std::string &public_key) const { + const std::string &public_key, + LogContext log_context) const { if (pub_key_type == PublicKeyType::TRANSIENT) { lock_guard lock(m_trans_clients_mtx); if (m_trans_auth_clients.count(public_key)) { @@ -261,7 +265,7 @@ std::string AuthMap::getUIDSafe(const PublicKeyType pub_key_type, // Check database for user keys DatabaseAPI db(m_db_url, m_db_user, m_db_pass); std::string uid; - if (db.uidByPubKey(public_key, uid)) { + if (db.uidByPubKey(public_key, uid, log_context)) { return uid; } } diff --git a/core/server/AuthMap.hpp b/core/server/AuthMap.hpp index 7ffaeda77..4780bd2b5 100644 --- a/core/server/AuthMap.hpp +++ b/core/server/AuthMap.hpp @@ -8,6 +8,7 @@ // Local common includes #include "common/IAuthenticationManager.hpp" +#include "common/DynaLog.hpp" // Standard includes #include @@ -113,13 +114,15 @@ class AuthMap { *does not exist. Best to call hasKey first. **/ std::string getUID(const PublicKeyType pub_key_type, - const std::string &public_key) const; + const std::string &public_key, + LogContext log_context) const; /** * Safe version that returns empty string if key not found **/ std::string getUIDSafe(const PublicKeyType pub_key_type, - const std::string &public_key) const; + const std::string &public_key, + LogContext log_context) const; /** * Will return the number of keys of the provided type. Does not currently @@ -128,7 +131,8 @@ class AuthMap { size_t size(const PublicKeyType pub_key_type) const; bool hasKey(const PublicKeyType pub_key_type, - const std::string &public_key) const; + const std::string &public_key, + LogContext log_context) const; /*********************************************************************************** * Manipulators @@ -138,7 +142,8 @@ class AuthMap { * Increase the recorded times the the public key has been accessed by one. **/ void incrementKeyAccessCounter(const PublicKeyType pub_key_type, - const std::string &public_key); + const std::string &public_key, + LogContext log_context); /** * Adds the key to the AuthMap object diff --git a/core/server/AuthenticationManager.cpp b/core/server/AuthenticationManager.cpp index 62b1d29b2..be9a51911 100644 --- a/core/server/AuthenticationManager.cpp +++ b/core/server/AuthenticationManager.cpp @@ -4,6 +4,7 @@ // Common includes #include "common/TraceException.hpp" +#include "common/DynaLog.hpp" // Standard includes #include @@ -69,46 +70,47 @@ void AuthenticationManager::purge(const PublicKeyType pub_key_type) { } void AuthenticationManager::incrementKeyAccessCounter( - const std::string &public_key) { + const std::string &public_key, + LogContext log_context) { std::lock_guard lock(m_lock); - if (m_auth_mapper.hasKey(PublicKeyType::TRANSIENT, public_key)) { + if (m_auth_mapper.hasKey(PublicKeyType::TRANSIENT, public_key, log_context)) { m_auth_mapper.incrementKeyAccessCounter(PublicKeyType::TRANSIENT, - public_key); - } else if (m_auth_mapper.hasKey(PublicKeyType::SESSION, public_key)) { - m_auth_mapper.incrementKeyAccessCounter(PublicKeyType::SESSION, public_key); + public_key, log_context); + } else if (m_auth_mapper.hasKey(PublicKeyType::SESSION, public_key, log_context)) { + m_auth_mapper.incrementKeyAccessCounter(PublicKeyType::SESSION, public_key, log_context); } // Ignore persistent cases because counter does nothing for them } -bool AuthenticationManager::hasKey(const std::string &public_key) const { +bool AuthenticationManager::hasKey(const std::string &public_key, LogContext log_context) const { std::lock_guard lock(m_lock); - if (m_auth_mapper.hasKey(PublicKeyType::TRANSIENT, public_key)) { + if (m_auth_mapper.hasKey(PublicKeyType::TRANSIENT, public_key, log_context)) { return true; } - if (m_auth_mapper.hasKey(PublicKeyType::SESSION, public_key)) { + if (m_auth_mapper.hasKey(PublicKeyType::SESSION, public_key, log_context)) { return true; } - if (m_auth_mapper.hasKey(PublicKeyType::PERSISTENT, public_key)) { + if (m_auth_mapper.hasKey(PublicKeyType::PERSISTENT, public_key, log_context)) { return true; } return false; } -std::string AuthenticationManager::getUID(const std::string &public_key) const { +std::string AuthenticationManager::getUID(const std::string &public_key, LogContext log_context) const { std::lock_guard lock(m_lock); - if (m_auth_mapper.hasKey(PublicKeyType::TRANSIENT, public_key)) { - return m_auth_mapper.getUID(PublicKeyType::TRANSIENT, public_key); + if (m_auth_mapper.hasKey(PublicKeyType::TRANSIENT, public_key, log_context)) { + return m_auth_mapper.getUID(PublicKeyType::TRANSIENT, public_key, log_context); } - if (m_auth_mapper.hasKey(PublicKeyType::SESSION, public_key)) { - return m_auth_mapper.getUID(PublicKeyType::SESSION, public_key); + if (m_auth_mapper.hasKey(PublicKeyType::SESSION, public_key, log_context)) { + return m_auth_mapper.getUID(PublicKeyType::SESSION, public_key, log_context); } - if (m_auth_mapper.hasKey(PublicKeyType::PERSISTENT, public_key)) { - return m_auth_mapper.getUID(PublicKeyType::PERSISTENT, public_key); + if (m_auth_mapper.hasKey(PublicKeyType::PERSISTENT, public_key, log_context)) { + return m_auth_mapper.getUID(PublicKeyType::PERSISTENT, public_key, log_context); } EXCEPT(1, "Unrecognized public_key during execution of getUID."); @@ -122,9 +124,10 @@ void AuthenticationManager::addKey(const PublicKeyType &pub_key_type, } bool AuthenticationManager::hasKey(const PublicKeyType &pub_key_type, - const std::string &public_key) const { + const std::string &public_key, + LogContext log_context) const { std::lock_guard lock(m_lock); - return m_auth_mapper.hasKey(pub_key_type, public_key); + return m_auth_mapper.hasKey(pub_key_type, public_key, log_context); } void AuthenticationManager::migrateKey(const PublicKeyType &from_type, @@ -150,21 +153,21 @@ void AuthenticationManager::clearAllNonPersistentKeys() { m_auth_mapper.clearAllNonPersistentKeys(); } -std::string AuthenticationManager::getUIDSafe(const std::string &public_key) const { +std::string AuthenticationManager::getUIDSafe(const std::string &public_key, LogContext log_context) const { std::lock_guard lock(m_lock); // Try each key type in order - std::string uid = m_auth_mapper.getUIDSafe(PublicKeyType::TRANSIENT, public_key); + std::string uid = m_auth_mapper.getUIDSafe(PublicKeyType::TRANSIENT, public_key, log_context); if (!uid.empty()) { return uid; } - uid = m_auth_mapper.getUIDSafe(PublicKeyType::SESSION, public_key); + uid = m_auth_mapper.getUIDSafe(PublicKeyType::SESSION, public_key, log_context); if (!uid.empty()) { return uid; } - uid = m_auth_mapper.getUIDSafe(PublicKeyType::PERSISTENT, public_key); + uid = m_auth_mapper.getUIDSafe(PublicKeyType::PERSISTENT, public_key, log_context); if (!uid.empty()) { return uid; } diff --git a/core/server/AuthenticationManager.hpp b/core/server/AuthenticationManager.hpp index 65468df4a..a888ace3c 100644 --- a/core/server/AuthenticationManager.hpp +++ b/core/server/AuthenticationManager.hpp @@ -54,7 +54,7 @@ class AuthenticationManager : public IAuthenticationManager { *allotted purge time frame. If the count is above one then the session key *not be purged. **/ - virtual void incrementKeyAccessCounter(const std::string &public_key) final; + virtual void incrementKeyAccessCounter(const std::string &public_key, LogContext log_context) final; /** * This will purge all keys of a particular type that have expired. @@ -79,7 +79,7 @@ class AuthenticationManager : public IAuthenticationManager { * - SESSION * - PERSISTENT **/ - virtual bool hasKey(const std::string &pub_key) const final; + virtual bool hasKey(const std::string &pub_key, LogContext log_context) const final; void addKey(const PublicKeyType &pub_key_type, const std::string &public_key, const std::string &uid); @@ -87,7 +87,7 @@ class AuthenticationManager : public IAuthenticationManager { /** * Check if a specific key exists in a specific map type **/ - bool hasKey(const PublicKeyType &pub_key_type, const std::string &public_key) const; + bool hasKey(const PublicKeyType &pub_key_type, const std::string &public_key, LogContext log_context) const; /** * Migrate a key from one type to another @@ -121,13 +121,13 @@ class AuthenticationManager : public IAuthenticationManager { * - SESSION * - PERSISTENT **/ - virtual std::string getUID(const std::string &pub_key) const final; + virtual std::string getUID(const std::string &pub_key, LogContext log_context) const final; /** * Safe version that returns empty string if key not found * instead of throwing an exception **/ - std::string getUIDSafe(const std::string &pub_key) const; + std::string getUIDSafe(const std::string &pub_key, LogContext log_context) const; }; } // namespace Core diff --git a/core/server/Condition.cpp b/core/server/Condition.cpp index 9b6c81c45..fbe9799e5 100644 --- a/core/server/Condition.cpp +++ b/core/server/Condition.cpp @@ -4,6 +4,9 @@ // Standard includes #include +#include +#include +#include namespace SDMS { namespace Core { @@ -11,10 +14,16 @@ namespace Core { void Promote::enforce(AuthMap &auth_map, const std::string &public_key) { if (auth_map.hasKeyType(m_promote_from, public_key)) { size_t access_count = auth_map.getAccessCount(m_promote_from, public_key); + boost::uuids::random_generator generator; + boost::uuids::uuid uuid = generator(); + + LogContext log_context; + log_context.correlation_id = boost::uuids::to_string(uuid); + if (access_count >= m_transient_to_session_count_threshold) { // Convert transient key to session key if has been accessed more than the // threshold - std::string uid = auth_map.getUID(m_promote_from, public_key); + std::string uid = auth_map.getUID(m_promote_from, public_key, log_context); auth_map.addKey(m_promote_to, public_key, uid); } // Remove expired short lived transient key diff --git a/core/server/Config.cpp b/core/server/Config.cpp index 579d184bd..e1b34453c 100644 --- a/core/server/Config.cpp +++ b/core/server/Config.cpp @@ -78,8 +78,8 @@ void Config::loadRepositoryConfig(AuthenticationManager &auth_manager, DL_TRACE(log_context, "Registering repo " << r.id()); // Check for duplicate keys across different maps - bool in_transient = auth_manager.hasKey(PublicKeyType::TRANSIENT, r.pub_key()); - bool in_session = auth_manager.hasKey(PublicKeyType::SESSION, r.pub_key()); + bool in_transient = auth_manager.hasKey(PublicKeyType::TRANSIENT, r.pub_key(), log_context); + bool in_session = auth_manager.hasKey(PublicKeyType::SESSION, r.pub_key(), log_context); if (in_transient && in_session) { // Key exists in both maps - this is an inconsistent state @@ -114,7 +114,7 @@ void Config::loadRepositoryConfig(AuthenticationManager &auth_manager, DL_TRACE(log_context, "Validating repository keys after loading"); for (const auto& repo_pair : m_repos) { const RepoData& repo = repo_pair.second; - if (auth_manager.hasKey(PublicKeyType::PERSISTENT, repo.pub_key())) { + if (auth_manager.hasKey(PublicKeyType::PERSISTENT, repo.pub_key(), log_context)) { DL_TRACE(log_context, "Key for " << repo.id() << " verified in PERSISTENT map"); } else { DL_ERROR(log_context, "KEY MISSING! Repository " << repo.id() diff --git a/core/server/DatabaseAPI.cpp b/core/server/DatabaseAPI.cpp index cdf752e6c..7e1d98edc 100644 --- a/core/server/DatabaseAPI.cpp +++ b/core/server/DatabaseAPI.cpp @@ -169,7 +169,7 @@ long DatabaseAPI::dbGet(const char *a_url_path, } } -bool DatabaseAPI::dbGetRaw(const std::string url, string &a_result) { +bool DatabaseAPI::dbGetRaw(const std::string url, string &a_result, LogContext log_context) { a_result.clear(); char error[CURL_ERROR_SIZE]; @@ -183,8 +183,17 @@ bool DatabaseAPI::dbGetRaw(const std::string url, string &a_result) { curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &a_result); curl_easy_setopt(m_curl, CURLOPT_ERRORBUFFER, error); curl_easy_setopt(m_curl, CURLOPT_HTTPGET, 1); + struct curl_slist* headers = nullptr; + + // safe: curl_slist_append copies the string internally + std::string header = "x-correlation-id: " + log_context.correlation_id; + headers = curl_slist_append(headers, header.c_str()); + + // attach headers to the CURL handle + curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, headers); CURLcode res = curl_easy_perform(m_curl); + curl_slist_free_all(headers); long http_code = 0; curl_easy_getinfo(m_curl, CURLINFO_RESPONSE_CODE, &http_code); if (res == CURLE_OK && (http_code >= 200 && http_code < 300)) @@ -303,10 +312,11 @@ void DatabaseAPI::clientLinkIdentity(const std::string &a_identity, } bool DatabaseAPI::uidByPubKey(const std::string &a_pub_key, - std::string &a_uid) { + std::string &a_uid, + LogContext log_context) { const string url = buildSearchParamURL("usr/find/by_pub_key", {{"pub_key", a_pub_key}}); - return dbGetRaw(url, a_uid); + return dbGetRaw(url, a_uid, log_context); } bool DatabaseAPI::userGetKeys(std::string &a_pub_key, std::string &a_priv_key, @@ -394,7 +404,7 @@ void DatabaseAPI::userSetAccessToken(const std::string &a_acc_tok, params.push_back({"other_token_data", other_token_data}); } const string url = buildSearchParamURL("usr/token/set", params); - dbGetRaw(url, result); + dbGetRaw(url, result, log_context); DL_TRACE(log_context, "token expires in: " << to_string(a_expires_in)); } @@ -445,11 +455,11 @@ void DatabaseAPI::getExpiringAccessTokens( TRANSLATE_END(result, log_context) } -void DatabaseAPI::purgeTransferRecords(size_t age) { +void DatabaseAPI::purgeTransferRecords(size_t age, LogContext log_context) { string result; const string url = buildSearchParamURL("xfr/purge", {{"age", to_string(age)}}); - dbGetRaw(url, result); + dbGetRaw(url, result, log_context); } void DatabaseAPI::userCreate(const SDMS::UserCreateRequest &a_request, diff --git a/core/server/DatabaseAPI.hpp b/core/server/DatabaseAPI.hpp index fa9327c50..ac4230223 100644 --- a/core/server/DatabaseAPI.hpp +++ b/core/server/DatabaseAPI.hpp @@ -43,7 +43,7 @@ class DatabaseAPI { LogContext log_context); void clientLinkIdentity(const std::string &a_identity, LogContext log_context); - bool uidByPubKey(const std::string &a_pub_key, std::string &a_uid); + bool uidByPubKey(const std::string &a_pub_key, std::string &a_uid, LogContext log_context); bool userGetKeys(std::string &a_pub_key, std::string &a_priv_key, LogContext log_context); void userSetKeys(const std::string &a_pub_key, const std::string &a_priv_key, @@ -69,7 +69,7 @@ class DatabaseAPI { void getExpiringAccessTokens(uint32_t a_expires_in, std::vector &a_expiring_tokens, LogContext log_context); - void purgeTransferRecords(size_t age); + void purgeTransferRecords(size_t age, LogContext log_context); void checkPerms(const SDMS::CheckPermsRequest &a_request, SDMS::CheckPermsReply &a_reply, LogContext log_context); void getPerms(const SDMS::GetPermsRequest &a_request, @@ -333,7 +333,7 @@ class DatabaseAPI { long dbGet(const char *a_url_path, const std::vector> &a_params, libjson::Value &a_result, LogContext, bool a_log = true); - bool dbGetRaw(const std::string url, std::string &a_result); + bool dbGetRaw(const std::string url, std::string &a_result, LogContext log_context); long dbPost(const char *a_url_path, const std::vector> &a_params, const std::string *a_body, libjson::Value &a_result, LogContext); diff --git a/core/server/tests/unit/test_AuthMap.cpp b/core/server/tests/unit/test_AuthMap.cpp index 02678d2e2..4a60a238d 100644 --- a/core/server/tests/unit/test_AuthMap.cpp +++ b/core/server/tests/unit/test_AuthMap.cpp @@ -25,6 +25,7 @@ BOOST_GLOBAL_FIXTURE(GlobalProtobufTeardown); BOOST_AUTO_TEST_SUITE(AuthMapTest) BOOST_AUTO_TEST_CASE(testing_AuthMap) { + SDMS::LogContext log_context; time_t active_transient_key_time = 30; time_t active_session_key_time = 30; std::string db_url = "https://db/sdms/blah"; @@ -40,11 +41,11 @@ BOOST_AUTO_TEST_CASE(testing_AuthMap) { auth_map.addKey(PublicKeyType::TRANSIENT, new_pub_key, user_id); BOOST_TEST(auth_map.size(PublicKeyType::TRANSIENT) == 1); - BOOST_TEST(auth_map.hasKey(PublicKeyType::TRANSIENT, new_pub_key)); - BOOST_TEST(auth_map.hasKey(PublicKeyType::SESSION, new_pub_key) == false); - BOOST_TEST(auth_map.hasKey(PublicKeyType::PERSISTENT, new_pub_key) == false); + BOOST_TEST(auth_map.hasKey(PublicKeyType::TRANSIENT, new_pub_key, log_context)); + BOOST_TEST(auth_map.hasKey(PublicKeyType::SESSION, new_pub_key, log_context) == false); + BOOST_TEST(auth_map.hasKey(PublicKeyType::PERSISTENT, new_pub_key, log_context) == false); - BOOST_TEST(auth_map.getUID(PublicKeyType::TRANSIENT, new_pub_key) == user_id); + BOOST_TEST(auth_map.getUID(PublicKeyType::TRANSIENT, new_pub_key, log_context) == user_id); } BOOST_AUTO_TEST_CASE(testing_AuthMap_setgetcount) { diff --git a/core/server/tests/unit/test_AuthenticationManager.cpp b/core/server/tests/unit/test_AuthenticationManager.cpp index 0cded3e03..27b00c713 100644 --- a/core/server/tests/unit/test_AuthenticationManager.cpp +++ b/core/server/tests/unit/test_AuthenticationManager.cpp @@ -31,6 +31,7 @@ BOOST_GLOBAL_FIXTURE(GlobalProtobufTeardown); BOOST_AUTO_TEST_SUITE(AuthenticationManagerTest) BOOST_AUTO_TEST_CASE(testing_AuthenticationManagerPurgeTrans) { + SDMS::LogContext log_context; std::map purge_intervals; purge_intervals[PublicKeyType::TRANSIENT] = 1; // Seconds @@ -59,16 +60,16 @@ BOOST_AUTO_TEST_CASE(testing_AuthenticationManagerPurgeTrans) { const std::string uid = "u/benz"; auth_manager.addKey(PublicKeyType::TRANSIENT, public_key, uid); - BOOST_TEST(auth_manager.hasKey(public_key)); - BOOST_TEST(boost::iequals(auth_manager.getUID(public_key), uid)); + BOOST_TEST(auth_manager.hasKey(public_key, log_context)); + BOOST_TEST(boost::iequals(auth_manager.getUID(public_key, log_context), uid)); // Run purge auth_manager.purge(PublicKeyType::TRANSIENT); std::cout << "Show output" << std::endl; // Nothing should happen because the interval was not surpassed - BOOST_TEST(auth_manager.hasKey(public_key)); - BOOST_TEST(boost::iequals(auth_manager.getUID(public_key), uid)); + BOOST_TEST(auth_manager.hasKey(public_key, log_context)); + BOOST_TEST(boost::iequals(auth_manager.getUID(public_key, log_context), uid)); // Sleep for the purge interval sleep(purge_intervals[PublicKeyType::TRANSIENT]); @@ -77,11 +78,11 @@ BOOST_AUTO_TEST_CASE(testing_AuthenticationManagerPurgeTrans) { auth_manager.purge(PublicKeyType::TRANSIENT); // Key should have been removed - BOOST_TEST(auth_manager.hasKey(public_key) == false); + BOOST_TEST(auth_manager.hasKey(public_key, log_context) == false); } BOOST_AUTO_TEST_CASE(testing_AuthenticationManagerPromotePurgeSession) { - + SDMS::LogContext log_context; std::map purge_intervals; purge_intervals[PublicKeyType::TRANSIENT] = 1; // Seconds purge_intervals[PublicKeyType::SESSION] = 2; // Seconds @@ -111,8 +112,8 @@ BOOST_AUTO_TEST_CASE(testing_AuthenticationManagerPromotePurgeSession) { auth_manager.addKey(PublicKeyType::TRANSIENT, public_key, uid); // Register two accesses to the public_key - auth_manager.incrementKeyAccessCounter(public_key); - auth_manager.incrementKeyAccessCounter(public_key); + auth_manager.incrementKeyAccessCounter(public_key, log_context); + auth_manager.incrementKeyAccessCounter(public_key, log_context); // Sleep for the purge interval sleep(purge_intervals[PublicKeyType::TRANSIENT]); @@ -122,15 +123,16 @@ BOOST_AUTO_TEST_CASE(testing_AuthenticationManagerPromotePurgeSession) { auth_manager.purge(PublicKeyType::TRANSIENT); // Should still have the key becuase it was promoted to a SESSION KEY - BOOST_TEST(auth_manager.hasKey(public_key)); + BOOST_TEST(auth_manager.hasKey(public_key, log_context)); // Nothing should happen at this point because the SESSION key is fresh auth_manager.purge(PublicKeyType::SESSION); - BOOST_TEST(auth_manager.hasKey(public_key)); + BOOST_TEST(auth_manager.hasKey(public_key, log_context)); } BOOST_AUTO_TEST_CASE(testing_AuthenticationManagerSessionReset) { + SDMS::LogContext log_context; std::map purge_intervals; purge_intervals[PublicKeyType::SESSION] = 2; // Seconds @@ -157,11 +159,11 @@ BOOST_AUTO_TEST_CASE(testing_AuthenticationManagerSessionReset) { const std::string uid = "u/benz"; auth_manager.addKey(PublicKeyType::SESSION, public_key, uid); - BOOST_TEST(auth_manager.hasKey(public_key)); - BOOST_TEST(boost::iequals(auth_manager.getUID(public_key), uid)); + BOOST_TEST(auth_manager.hasKey(public_key, log_context)); + BOOST_TEST(boost::iequals(auth_manager.getUID(public_key, log_context), uid)); // Register one accesses to the public_key - auth_manager.incrementKeyAccessCounter(public_key); + auth_manager.incrementKeyAccessCounter(public_key, log_context); // Sleep for the purge interval sleep(purge_intervals[PublicKeyType::SESSION]); @@ -171,17 +173,17 @@ BOOST_AUTO_TEST_CASE(testing_AuthenticationManagerSessionReset) { auth_manager.purge(PublicKeyType::SESSION); // Should still have the key becuase it was reset - BOOST_TEST(auth_manager.hasKey(public_key)); + BOOST_TEST(auth_manager.hasKey(public_key, log_context)); // Nothing should happen at this point because the SESSION key is fresh auth_manager.purge(PublicKeyType::SESSION); - BOOST_TEST(auth_manager.hasKey(public_key)); + BOOST_TEST(auth_manager.hasKey(public_key, log_context)); // Sleep for the purge interval of the SESSION sleep(purge_intervals[PublicKeyType::SESSION]); auth_manager.purge(PublicKeyType::SESSION); - BOOST_TEST(auth_manager.hasKey(public_key) == false); + BOOST_TEST(auth_manager.hasKey(public_key, log_context) == false); } BOOST_AUTO_TEST_SUITE_END()