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
Merged

Conversation

vikman90
Copy link
Member

Summary

This pull request addresses two issues:

Changes

  • Database Handling:
    • 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

  • AgentInfo Tests:
    • Updated existing tests to validate the new behavior of Set() and Save().
    • Verified that database writes only occur after Save() is called.
  • 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.
  • Manual Testing:

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

sqlite3 agent_info.db 'select * from agent_info'

||

Registration success

./wazuh-agent --config-file wazuh-agent.yml --register-agent --user wazuh --password topsecret --name dummy

wazuh-agent registered

sqlite3 agent_info.db 'select * from agent_info'

dummy|vEcz2euGDR2mTAxn4Fu6KrCIOhmsfq7U|114563d6-a9ae-4aec-aa58-7f0ee0500bab

@vikman90 vikman90 added type/bug Bug issue mvp Minimum Viable Product refinement labels Nov 19, 2024
@vikman90 vikman90 self-assigned this Nov 19, 2024
@vikman90 vikman90 linked an issue Nov 19, 2024 that may be closed by this pull request
@vikman90 vikman90 linked an issue Nov 19, 2024 that may be closed by this pull request
Copy link
Member

@jr0me jr0me left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Maybe the tests need improvement, I'm not sure about the changes introduced, but it looks like we are losing some checks there.

@TomasTurina TomasTurina merged commit a2405d2 into master Nov 19, 2024
5 checks passed
@TomasTurina TomasTurina deleted the fix/314-registration-failure branch November 19, 2024 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mvp Minimum Viable Product refinement type/bug Bug issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Agent Registration Fails Due to 201 Status Code Agent Saves Registration Information Even on Failure
3 participants