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

Add Imposter to our development tools #500

Closed
3 of 4 tasks
AlexRuiz7 opened this issue Oct 28, 2024 · 2 comments · Fixed by wazuh/wazuh-indexer-plugins#130
Closed
3 of 4 tasks

Add Imposter to our development tools #500

AlexRuiz7 opened this issue Oct 28, 2024 · 2 comments · Fixed by wazuh/wazuh-indexer-plugins#130
Assignees
Labels
level/task Task issue request/operational Operational requests type/enhancement Enhancement issue

Comments

@AlexRuiz7
Copy link
Member

AlexRuiz7 commented Oct 28, 2024

Description

The Command Manager plugin is interacting with an HTTP RESTful API in the Wazuh Server. We need to mock this service to develop and test our code, avoiding setting up a complete Wazuh Server.

As for now, the Command Manager interacts with the Management API (M_API) in two ways:

  • POST /security/user/authenticate, to log in to the API and obtain a JWT token.
  • POST /orders/, to send the pending orders.

We need to mock these 2 endpoints to test our code under different behaviors, success and failure, to properly handle them.

The @wazuh/devel-dashboard team has been using Imposter as a mock server for quite some time now. We'll also use this tool as we are already familiar with it, and has proven to fit our needs.

Imposter allows different deployment methods that can be useful for us:

  • imposter-cli: easy and straightforward to set up and use.
  • Docker: most portable solution.
  • JAR: the way to go to include it in our development and testing environment. Requires most effort.

Imposter can be configured to load an OpenAPI spec file and to respond to whatever we need on each endpoint call. The most recent spec for the Management API is here.

https://github.com/wazuh/wazuh/blob/enhancement/25599-server-orders-distribution/api/api/spec/spec.yaml

Functional requirements

  • Imposter responds to POST /security/user/authenticate providing a valid JWT token.
  • Imposter responds to POST /orders/, with a valid JSON reply, as specified in the spec.
  • Imposter loads the specified OpenAPI spec file. We may need to change often, for example, to test changes that are under development on a particular Git branch.

Plan

  • Include Imposter to our tooling.
  • Create an appropriate user manual for this tool.
  • Include Imposter to the Command Manager test dependencies for automatic testing.
  • Create tests that use the mock server.
@AlexRuiz7 AlexRuiz7 added level/task Task issue request/operational Operational requests type/enhancement Enhancement issue labels Oct 28, 2024
@AlexRuiz7
Copy link
Member Author

AlexRuiz7 commented Oct 28, 2024

To reuse the JS script to generate a valid token from the Wazuh Dashboard tooling, we need to add this environment variable.

export IMPOSTER_JS_PLUGIN=js-graal-compat 

outofcoffee/imposter#581

@wazuhci wazuhci moved this to Backlog in Release 5.0.0 Oct 28, 2024
@wazuhci wazuhci moved this from Backlog to In progress in Release 5.0.0 Oct 29, 2024
@mcasas993 mcasas993 linked a pull request Nov 4, 2024 that will close this issue
@AlexRuiz7 AlexRuiz7 linked a pull request Nov 5, 2024 that will close this issue
@wazuhci wazuhci moved this from In progress to Pending review in Release 5.0.0 Nov 6, 2024
@mcasas993
Copy link
Member

I had problems with import the necessaries classes to include Imposter in the unit tests. It's not urgent to include imposter in the unit tests, so I opened an issue in the Imposter repository.

@wazuhci wazuhci moved this from Pending review to Done in Release 5.0.0 Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level/task Task issue request/operational Operational requests type/enhancement Enhancement issue
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants