Skip to content

Commit

Permalink
fix: Update authentication and client tests with the Authenticator cl…
Browse files Browse the repository at this point in the history
…ass changes

Ticket: MEN-7873
Changelog: None

Signed-off-by: John Olav Lund <[email protected]>
  • Loading branch information
John Olav Lund committed Dec 19, 2024
1 parent 49dc3b9 commit 2ff5efa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
30 changes: 24 additions & 6 deletions tests/src/api/auth_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <common/platform/testing_dbus.hpp>
#endif

#include <mender-update/inventory.hpp>

using namespace std;

namespace auth = mender::api::auth;
Expand All @@ -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<mender::update::inventory::InventoryAPI> inventory_client =
make_shared<NoopInventoryClient>();

TEST_F(AuthDBusTests, AuthenticatorBasicTest) {
#ifndef MENDER_USE_DBUS
GTEST_SKIP();
Expand All @@ -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(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
30 changes: 24 additions & 6 deletions tests/src/api/client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <common/platform/testing_dbus.hpp>
#endif

#include <mender-update/inventory.hpp>

using namespace std;

namespace api = mender::api;
Expand All @@ -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<mender::update::inventory::InventoryAPI> inventory_client =
make_shared<NoopInventoryClient>();

#ifdef MENDER_USE_DBUS
class APIClientTests : public testing_dbus::DBusTests {
protected:
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit 2ff5efa

Please sign in to comment.