From 2ff5efa9a47b3732ba73d3a65b6285a7f7cdabd4 Mon Sep 17 00:00:00 2001 From: John Olav Lund Date: Wed, 18 Dec 2024 13:03:52 +0100 Subject: [PATCH] fix: Update authentication and client tests with the Authenticator class changes Ticket: MEN-7873 Changelog: None Signed-off-by: John Olav Lund --- tests/src/api/auth_test.cpp | 30 ++++++++++++++++++++++++------ tests/src/api/client_test.cpp | 30 ++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/tests/src/api/auth_test.cpp b/tests/src/api/auth_test.cpp index 05782060f..6d9bd5a71 100644 --- a/tests/src/api/auth_test.cpp +++ b/tests/src/api/auth_test.cpp @@ -30,6 +30,8 @@ #include #endif +#include + using namespace std; namespace auth = mender::api::auth; @@ -52,6 +54,22 @@ class AuthDBusTests : public testing_dbus::DBusTests {}; class AuthDBusTests : public testing::Test {}; #endif +class NoopInventoryClient : virtual public mender::update::inventory::InventoryAPI { + error::Error PushData( + const string &inventory_generators_dir, + events::EventLoop &loop, + mender::api::Client &client, + mender::update::inventory::APIResponseHandler api_handler) override { + api_handler(error::NoError); + return error::NoError; + } + void ClearDataCache() override { + } +}; + +shared_ptr inventory_client = + make_shared(); + TEST_F(AuthDBusTests, AuthenticatorBasicTest) { #ifndef MENDER_USE_DBUS GTEST_SKIP(); @@ -70,7 +88,7 @@ TEST_F(AuthDBusTests, AuthenticatorBasicTest) { }); dbus_server.AdvertiseObject(dbus_obj); - auth::AuthenticatorDBus authenticator {loop}; + auth::AuthenticatorDBus authenticator {loop, inventory_client}; bool action_called = false; auto err = authenticator.WithToken( @@ -107,7 +125,7 @@ TEST_F(AuthDBusTests, AuthenticatorTwoActionsTest) { }); dbus_server.AdvertiseObject(dbus_obj); - auth::AuthenticatorDBus authenticator {loop}; + auth::AuthenticatorDBus authenticator {loop, inventory_client}; bool action1_called = false; bool action2_called = false; @@ -177,7 +195,7 @@ TEST_F(AuthDBusTests, AuthenticatorTwoActionsWithTokenClearTest) { }); dbus_server.AdvertiseObject(dbus_obj); - auth::AuthenticatorDBus authenticator {loop, chrono::seconds {2}}; + auth::AuthenticatorDBus authenticator {loop, inventory_client, chrono::seconds {2}}; bool action1_called = false; bool action2_called = false; @@ -240,7 +258,7 @@ TEST_F(AuthDBusTests, AuthenticatorTwoActionsWithTokenClearAndTimeoutTest) { }); dbus_server.AdvertiseObject(dbus_obj); - auth::AuthenticatorDBus authenticator {loop, chrono::seconds {2}}; + auth::AuthenticatorDBus authenticator {loop, inventory_client, chrono::seconds {2}}; bool action1_called = false; bool action2_called = false; @@ -302,7 +320,7 @@ TEST_F(AuthDBusTests, AuthenticatorBasicRealLifeTest) { }); dbus_server.AdvertiseObject(dbus_obj); - auth::AuthenticatorDBus authenticator {loop, chrono::seconds {2}}; + auth::AuthenticatorDBus authenticator {loop, inventory_client, chrono::seconds {2}}; bool action_called = false; auto err = authenticator.WithToken( @@ -328,7 +346,7 @@ TEST(AuthNoDBusTests, AuthenticatorAttemptNoDBus) { setenv("DBUS_SYSTEM_BUS_ADDRESS", "dummy-address", 1); TestEventLoop loop; - auth::AuthenticatorDBus authenticator {loop}; + auth::AuthenticatorDBus authenticator {loop, inventory_client}; int action_called = false; auto err = authenticator.WithToken( diff --git a/tests/src/api/client_test.cpp b/tests/src/api/client_test.cpp index 25ef105b4..7808d2c6c 100644 --- a/tests/src/api/client_test.cpp +++ b/tests/src/api/client_test.cpp @@ -34,6 +34,8 @@ #include #endif +#include + using namespace std; namespace api = mender::api; @@ -56,6 +58,22 @@ using TestEventLoop = mender::common::testing::TestEventLoop; const string TEST_PORT = "8088"; +class NoopInventoryClient : virtual public mender::update::inventory::InventoryAPI { + error::Error PushData( + const string &inventory_generators_dir, + events::EventLoop &loop, + mender::api::Client &client, + mender::update::inventory::APIResponseHandler api_handler) override { + api_handler(error::NoError); + return error::NoError; + } + void ClearDataCache() override { + } +}; + +shared_ptr inventory_client = + make_shared(); + #ifdef MENDER_USE_DBUS class APIClientTests : public testing_dbus::DBusTests { protected: @@ -136,7 +154,7 @@ TEST_F(APIClientTests, ClientBasicTest) { }); dbus_server.AdvertiseObject(dbus_obj); - auth::AuthenticatorDBus authenticator {loop, chrono::seconds {2}}; + auth::AuthenticatorDBus authenticator {loop, inventory_client, chrono::seconds {2}}; http::ClientConfig client_config {""}; api::HTTPClient client {client_config, loop, authenticator}; @@ -243,7 +261,7 @@ TEST_F(APIClientTests, TwoClientsTest) { }); dbus_server.AdvertiseObject(dbus_obj); - auth::AuthenticatorDBus authenticator {loop, chrono::seconds {2}}; + auth::AuthenticatorDBus authenticator {loop, inventory_client, chrono::seconds {2}}; http::ClientConfig client_config {""}; api::HTTPClient client1 {client_config, loop, authenticator}; @@ -425,7 +443,7 @@ TEST_F(APIClientTests, ClientReauthenticationTest) { }); dbus_server.AdvertiseObject(dbus_obj); - auth::AuthenticatorDBus authenticator {loop, chrono::seconds {2}}; + auth::AuthenticatorDBus authenticator {loop, inventory_client, chrono::seconds {2}}; http::ClientConfig client_config {""}; api::HTTPClient client {client_config, loop, authenticator}; @@ -529,7 +547,7 @@ TEST_F(APIClientTests, ClientEarlyAuthErrorTest) { // no DBus server to handle auth here - auth::AuthenticatorDBus authenticator {loop, chrono::seconds {2}}; + auth::AuthenticatorDBus authenticator {loop, inventory_client, chrono::seconds {2}}; http::ClientConfig client_config {""}; api::HTTPClient client {client_config, loop, authenticator}; @@ -641,7 +659,7 @@ TEST_F(APIClientTests, ClientAuthenticationTimeoutFailureTest) { }); dbus_server.AdvertiseObject(dbus_obj); - auth::AuthenticatorDBus authenticator {loop, chrono::seconds {2}}; + auth::AuthenticatorDBus authenticator {loop, inventory_client, chrono::seconds {2}}; http::ClientConfig client_config {""}; api::HTTPClient client {client_config, loop, authenticator}; @@ -807,7 +825,7 @@ TEST_F(APIClientTests, ClientReauthenticationFailureTest) { }); dbus_server.AdvertiseObject(dbus_obj); - auth::AuthenticatorDBus authenticator {loop, chrono::seconds {2}}; + auth::AuthenticatorDBus authenticator {loop, inventory_client, chrono::seconds {2}}; http::ClientConfig client_config {""}; api::HTTPClient client {client_config, loop, authenticator};