Skip to content

Commit

Permalink
fix: agent_info reset to default values
Browse files Browse the repository at this point in the history
Due to recent changes in the agent's info implementation,
where the sql logic was replaced with the SQLiteManager,
a bug was introduced in the ResetToDefaults method by which
the AgentInfo tables were not being cleaned up.
  • Loading branch information
jr0me committed Nov 13, 2024
1 parent 69ab7f8 commit 3ab8b5c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/agent/agent_info/src/agent_info_persistance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ void AgentInfoPersistance::ResetToDefault()
{
try
{
m_db->Remove(AGENT_INFO_TABLE_NAME);
m_db->Remove(AGENT_GROUP_TABLE_NAME);
m_db->DropTable(AGENT_INFO_TABLE_NAME);
m_db->DropTable(AGENT_GROUP_TABLE_NAME);
CreateAgentInfoTable();
CreateAgentGroupTable();
InsertDefaultAgentInfo();
}
catch (const std::exception& e)
Expand Down
17 changes: 15 additions & 2 deletions src/agent/tests/agent_registration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <gtest/gtest.h>

#include <agent_info.hpp>
#include <agent_info_persistance.hpp>
#include <agent_registration.hpp>
#include <ihttp_client.hpp>
#include <ihttp_socket.hpp>
Expand Down Expand Up @@ -67,6 +68,9 @@ class RegisterTest : public ::testing::Test

TEST_F(RegisterTest, RegistrationTestSuccess)
{
AgentInfoPersistance agentInfoPersistance;
agentInfoPersistance->ResetToDefault();

registration = std::make_unique<agent_registration::AgentRegistration>(
"user", "password", "4GhT7uFm1zQa9c2Vb7Lk8pYsX0WqZrNj", "agent_name", std::nullopt);
SysInfo sysInfo;
Expand All @@ -78,7 +82,7 @@ TEST_F(RegisterTest, RegistrationTestSuccess)
EXPECT_CALL(mockHttpClient, AuthenticateWithUserPassword(testing::_, testing::_, testing::_, testing::_))
.WillOnce(testing::Return("token"));

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

http_client::HttpRequestParams reqParams(boost::beast::http::verb::post,
"https://localhost:55000",
Expand All @@ -100,6 +104,9 @@ TEST_F(RegisterTest, RegistrationTestSuccess)

TEST_F(RegisterTest, RegistrationFailsIfAuthenticationFails)
{
AgentInfoPersistance agentInfoPersistance;
agentInfoPersistance->ResetToDefault();

registration = std::make_unique<agent_registration::AgentRegistration>(
"user", "password", "4GhT7uFm1zQa9c2Vb7Lk8pYsX0WqZrNj", "agent_name", std::nullopt);
agent = std::make_unique<AgentInfo>();
Expand All @@ -116,6 +123,9 @@ TEST_F(RegisterTest, RegistrationFailsIfAuthenticationFails)

TEST_F(RegisterTest, RegistrationFailsIfServerResponseIsNotOk)
{
AgentInfoPersistance agentInfoPersistance;
agentInfoPersistance->ResetToDefault();

registration = std::make_unique<agent_registration::AgentRegistration>(
"user", "password", "4GhT7uFm1zQa9c2Vb7Lk8pYsX0WqZrNj", "agent_name", std::nullopt);
agent = std::make_unique<AgentInfo>();
Expand All @@ -137,6 +147,9 @@ TEST_F(RegisterTest, RegistrationFailsIfServerResponseIsNotOk)

TEST_F(RegisterTest, RegistrationTestSuccessWithEmptyKey)
{
AgentInfoPersistance agentInfoPersistance;
agentInfoPersistance->ResetToDefault();

registration =
std::make_unique<agent_registration::AgentRegistration>("user", "password", "", "agent_name", std::nullopt);
SysInfo sysInfo;
Expand All @@ -148,7 +161,7 @@ TEST_F(RegisterTest, RegistrationTestSuccessWithEmptyKey)
EXPECT_CALL(mockHttpClient, AuthenticateWithUserPassword(testing::_, testing::_, testing::_, testing::_))
.WillOnce(testing::Return("token"));

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

http_client::HttpRequestParams reqParams(boost::beast::http::verb::post,
"https://localhost:55000",
Expand Down

0 comments on commit 3ab8b5c

Please sign in to comment.