Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Agent Registration Behavior #319

Merged
merged 8 commits into from
Nov 19, 2024
24 changes: 8 additions & 16 deletions src/agent/tests/agent_registration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,17 @@ TEST_F(RegisterTest, RegistrationTestSuccess)
AgentInfoPersistance agentInfoPersistance;
agentInfoPersistance.ResetToDefault();

registration = std::make_unique<agent_registration::AgentRegistration>(
"user", "password", "4GhT7uFm1zQa9c2Vb7Lk8pYsX0WqZrNj", "agent_name", std::nullopt);
SysInfo sysInfo;
agent = std::make_unique<AgentInfo>([&sysInfo]() mutable { return sysInfo.os(); },
[&sysInfo]() mutable { return sysInfo.networks(); });

agent->SetKey("4GhT7uFm1zQa9c2Vb7Lk8pYsX0WqZrNj");
agent->SetName("agent_name");
agent->Save();

registration = std::make_unique<agent_registration::AgentRegistration>(
"user", "password", "4GhT7uFm1zQa9c2Vb7Lk8pYsX0WqZrNj", "agent_name", std::nullopt);

MockHttpClient mockHttpClient;

EXPECT_CALL(mockHttpClient, AuthenticateWithUserPassword(testing::_, testing::_, testing::_, testing::_))
Expand Down Expand Up @@ -152,29 +157,16 @@ TEST_F(RegisterTest, RegistrationTestSuccessWithEmptyKey)

registration =
std::make_unique<agent_registration::AgentRegistration>("user", "password", "", "agent_name", std::nullopt);
SysInfo sysInfo;
agent = std::make_unique<AgentInfo>([&sysInfo]() mutable { return sysInfo.os(); },
[&sysInfo]() mutable { return sysInfo.networks(); });

MockHttpClient mockHttpClient;

EXPECT_CALL(mockHttpClient, AuthenticateWithUserPassword(testing::_, testing::_, testing::_, testing::_))
.WillOnce(testing::Return("token"));

const auto bodyJson = agent->GetMetadataInfo(true);

http_client::HttpRequestParams reqParams(boost::beast::http::verb::post,
"https://localhost:55000",
"/agents",
agent->GetHeaderInfo(),
"token",
"",
bodyJson);

boost::beast::http::response<boost::beast::http::dynamic_body> expectedResponse;
expectedResponse.result(boost::beast::http::status::ok);

EXPECT_CALL(mockHttpClient, PerformHttpRequest(testing::Eq(reqParams))).WillOnce(testing::Return(expectedResponse));
EXPECT_CALL(mockHttpClient, PerformHttpRequest(testing::_)).WillOnce(testing::Return(expectedResponse));
jr0me marked this conversation as resolved.
Show resolved Hide resolved

// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
const bool res = registration->Register(mockHttpClient);
Expand Down