Refactored the AgentInfo component to delay database writes until registration is confirmed.
Introduced a Save() method to persist data only after successful registration.
Registration Status Code:
Modified the expected status code for registration responses from 200 to 201.
Tests
[X] AgentInfo Tests:
Updated existing tests to validate the new behavior of Set() and Save().
Verified that database writes only occur after Save() is called.
[X] AgentRegistration Tests:
Adapted tests to account for the 201 status code as a success indicator.
Ensured the agent correctly interprets 201 and does not fail the registration process.
[X] Manual Testing:
Tested with a mock server using Imposter: #281
Verified that 201 responses result in successful registration.
Confirmed that the database remains unmodified in cases of registration failure.
[!IMPORTANT]
In this change, we simplify the RegistrationTestSuccessWithEmptyKey test, since this test makes the agent produce a random key. Since persistence is removed, the mock does not have access to the new key. However, the persistence behavior of AgentRegistration is checked in RegistrationSuccess.
Manual testing
Registration failure
./wazuh-agent --config-file wazuh-agent.yml --register-agent --user wazuh --password topsecret --name other
Failed to authenticate with the manager
wazuh-agent registration failed
Summary
This pull request addresses two issues:
314
318
Changes
AgentInfo
component to delay database writes until registration is confirmed.Save()
method to persist data only after successful registration.200
to201
.Tests
Set()
andSave()
.Save()
is called.201
status code as a success indicator.201
and does not fail the registration process.201
responses result in successful registration.Manual testing
Registration failure
Registration success