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

Disable update check in AIT and implement CTI service mock #23374

Merged
merged 3 commits into from May 15, 2024

Conversation

GGP1
Copy link
Member

@GGP1 GGP1 commented May 10, 2024

Related issue
Closes #23362

Description

Disables the update check service in the API integration tests by default and implements a mock for the CTI service to use it in specific test cases.

Logs/Alerts example

Running server
gasti@gasti:~/work/wazuh/api/test/integration/env/base/cti$ python3 http_sever.py
Listening on port 4041...
127.0.0.1 - - [10/May/2024 10:00:48] "GET /cti/v1/ping HTTP/1.1" 200 -
CTI ping
gasti@gasti:~/work/wazuh/api/test/integration/env/base/cti$ curl http://127.0.0.1:4041/cti/v1/ping
{"data": {"major": [], "minor": [{"description": "", "published_date": "2024-05-10T16:06:52Z", "semver": {"major": 4, "minor": 9, "patch": 0}, "tag": "v4.9.0", "title": "Wazuh v4.9.0"}], "patch": []}}
Building docker image
gasti@gasti:~/work/wazuh/api/test/integration/env/base/cti$ docker build -t cti_server .
[+] Building 20.5s (7/7) FINISHED                                                                              docker:default
 => [internal] load build definition from Dockerfile                                                                     0.0s
 => => transferring dockerfile: 136B                                                                                     0.0s
 => [internal] load metadata for docker.io/library/python:3.12-alpine                                                    1.5s
 => [internal] load .dockerignore                                                                                        0.0s
 => => transferring context: 2B                                                                                          0.0s
 => [internal] load build context                                                                                        0.0s
 => => transferring context: 169B                                                                                        0.0s
 => [1/2] FROM docker.io/library/python:3.12-alpine@sha256:ef097620baf1272e38264207003b0982285da3236a20ed829bf6bbf1e85  15.7s
 => => resolve docker.io/library/python:3.12-alpine@sha256:ef097620baf1272e38264207003b0982285da3236a20ed829bf6bbf1e85f  0.0s
 => => sha256:3a6cecfe70039fd21206783553d33ea4753700f031a2490428311619801d02f7 13.96MB / 13.96MB                        14.9s
 => => sha256:60d2faee92e78fe7518f0ff1645cd7320bf6b140ff885fdec2a1ea1d878f0dca 239B / 239B                               6.0s
 => => sha256:b62713ed4827911d38bb5a9ac322efa0408b4bb135863b4b15c4bc383e59918b 2.70MB / 2.70MB                           9.8s
 => => sha256:ef097620baf1272e38264207003b0982285da3236a20ed829bf6bbf1e85fe3cb 1.65kB / 1.65kB                           0.0s
 => => sha256:c583b8590a197db1f6efece2dd244b0259cb6f82c4acc654bfbe48e00e20a7b9 1.37kB / 1.37kB                           0.0s
 => => sha256:f44387b482817f41bdac1892c45711adaedb3a7dd381844cdc3f360e66314d7a 6.02kB / 6.02kB                           0.0s
 => => extracting sha256:3a6cecfe70039fd21206783553d33ea4753700f031a2490428311619801d02f7                                0.4s
 => => extracting sha256:60d2faee92e78fe7518f0ff1645cd7320bf6b140ff885fdec2a1ea1d878f0dca                                0.0s
 => => extracting sha256:b62713ed4827911d38bb5a9ac322efa0408b4bb135863b4b15c4bc383e59918b                                0.2s
 => [2/2] COPY . .                                                                                                       0.2s
 => exporting to image                                                                                                   0.2s
 => => exporting layers                                                                                                  0.0s
 => => writing image sha256:53b65ca654239d3a5097d87e503c6b7627e2066cad4d6ca9db6de38bf87174ea                             0.0s
 => => naming to docker.io/library/cti_server
Running docker image
gasti@gasti:~/work/wazuh/api/test/integration/env/base/cti$ docker run --net=host cti_server
Listening on port 4041...
127.0.0.1 - - [10/May/2024 13:21:14] "GET /cti/v1/ping HTTP/1.1" 200 -
CTI ping
gasti@gasti:~/work/wazuh/api/test/integration/env/base/cti$ curl http://127.0.0.1:4041/cti/v1/ping
{"data": {"major": [], "minor": [{"description": "", "published_date": "2024-05-10T16:06:52Z", "semver": {"major": 4, "minor": 9, "patch": 0}, "tag": "v4.9.0", "title": "Wazuh v4.9.0"}], "patch": []}}
CTI ping inside compose environment
gasti@gasti:~/work/wazuh/api/test/integration/env/base/cti$ docker exec -it env-wazuh-master-1 bash
root@wazuh-master:/# curl http://cti:4041/cti/v1/ping
{"data": {"major": [], "minor": [{"description": "Description", "published_date": "2024-05-10T16:06:52Z", "semver": {"mayor": 4, "minor": 9, "patch": 0}, "tag": "v4.9.0", "title": "Wazuh v4.9.0"}], "patch": []}, "errors": {"detail": ""}}

Tests

Test environment containers
gasti@gasti:~/work/wazuh/api/test/integration/env/base$ docker ps -a
CONTAINER ID   IMAGE                              COMMAND                  CREATED          STATUS                    PORTS                                           NAMES
d7092476bcee   integration_test_wazuh-agent_old   "/scripts/entrypoint…"   30 seconds ago   Up 27 seconds (healthy)                                                   env-wazuh-agent7-1
d6da7102bcd2   integration_test_wazuh-agent_old   "/scripts/entrypoint…"   30 seconds ago   Up 27 seconds (healthy)                                                   env-wazuh-agent6-1
080d1d7eab1c   integration_test_wazuh-agent_old   "/scripts/entrypoint…"   30 seconds ago   Up 27 seconds (healthy)                                                   env-wazuh-agent8-1
2dcd3fecfe99   integration_test_wazuh-agent       "/scripts/entrypoint…"   30 seconds ago   Up 27 seconds (healthy)                                                   env-wazuh-agent4-1
8f38fe5cc37a   integration_test_wazuh-agent       "/scripts/entrypoint…"   30 seconds ago   Up 28 seconds (healthy)                                                   env-wazuh-agent2-1
626e93e53614   integration_test_wazuh-agent       "/scripts/entrypoint…"   30 seconds ago   Up 27 seconds (healthy)                                                   env-wazuh-agent3-1
1555e3340f19   integration_test_wazuh-agent       "/scripts/entrypoint…"   30 seconds ago   Up 28 seconds (healthy)                                                   env-wazuh-agent1-1
9064492438e0   integration_test_wazuh-agent_old   "/scripts/entrypoint…"   30 seconds ago   Up 28 seconds (healthy)                                                   env-wazuh-agent5-1
4b97d57c3af0   integration_test_wazuh-manager     "/scripts/entrypoint…"   30 seconds ago   Up 28 seconds (healthy)                                                   env-wazuh-worker1-1
7f646653102e   integration_test_nginx-lb          "/scripts/entrypoint…"   30 seconds ago   Up 28 seconds (healthy)   80/tcp                                          env-nginx-lb-1
ae19db31da14   integration_test_wazuh-manager     "/scripts/entrypoint…"   30 seconds ago   Up 28 seconds (healthy)                                                   env-wazuh-worker2-1
818b358cc64b   integration_test_wazuh-manager     "/scripts/entrypoint…"   30 seconds ago   Up 29 seconds (healthy)   0.0.0.0:55000->55000/tcp, :::55000->55000/tcp   env-wazuh-master-1
2d0599480b80   integration_test_cti               "/bin/sh -c 'python3…"   30 seconds ago   Up 29 seconds             4041/tcp                                        env-cti-1
test_manager_endpoints.tavern.yaml
(venv) gasti@gasti:~/work/wazuh/api/test/integration$ pytest -vv test_manager_endpoints.tavern.yaml
============================================================================ test session starts ============================================================================
platform linux -- Python 3.10.14, pytest-7.3.1, pluggy-1.5.0 -- /home/gasti/work/wazuh/venv/bin/python
cachedir: .pytest_cache
metadata: {'Python': '3.10.14', 'Platform': 'Linux-6.1.0-20-amd64-x86_64-with-glibc2.36', 'Packages': {'pytest': '7.3.1', 'pluggy': '1.5.0'}, 'Plugins': {'trio': '0.7.0', 'asyncio': '0.18.1', 'tavern': '1.23.5', 'html': '2.1.1', 'metadata': '3.1.1', 'anyio': '4.1.0', 'aiohttp': '1.0.4'}}
rootdir: /home/gasti/work/wazuh/api/test/integration
configfile: pytest.ini
plugins: trio-0.7.0, asyncio-0.18.1, tavern-1.23.5, html-2.1.1, metadata-3.1.1, anyio-4.1.0, aiohttp-1.0.4
asyncio: mode=auto
collected 35 items                                                                                                                                                          

test_manager_endpoints.tavern.yaml::GET /manager/status PASSED                                                                                                        [  2%]
test_manager_endpoints.tavern.yaml::GET /manager/info PASSED                                                                                                          [  5%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[alerts] PASSED                                                                               [  8%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[auth] PASSED                                                                                 [ 11%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[cis-cat] PASSED                                                                              [ 14%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[cluster] PASSED                                                                              [ 17%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[command] PASSED                                                                              [ 20%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[global] PASSED                                                                               [ 22%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[localfile] PASSED                                                                            [ 25%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[osquery] PASSED                                                                              [ 28%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[remote] PASSED                                                                               [ 31%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[rootcheck] PASSED                                                                            [ 34%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[ruleset] PASSED                                                                              [ 37%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[sca] PASSED                                                                                  [ 40%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[syscheck] PASSED                                                                             [ 42%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[syscollector] PASSED                                                                         [ 45%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[vulnerability-detection] PASSED                                                              [ 48%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration?{section}[indexer] PASSED                                                                              [ 51%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration PASSED                                                                                                 [ 54%]
test_manager_endpoints.tavern.yaml::GET /manager/daemons/stats PASSED                                                                                                 [ 57%]
test_manager_endpoints.tavern.yaml::GET /manager/stats PASSED                                                                                                         [ 60%]
test_manager_endpoints.tavern.yaml::GET /manager/stats/hourly PASSED                                                                                                  [ 62%]
test_manager_endpoints.tavern.yaml::GET /manager/stats/weekly PASSED                                                                                                  [ 65%]
test_manager_endpoints.tavern.yaml::GET /manager/stats/analysisd PASSED                                                                                               [ 68%]
test_manager_endpoints.tavern.yaml::GET /manager/stats/remoted PASSED                                                                                                 [ 71%]
test_manager_endpoints.tavern.yaml::GET /manager/api/config PASSED                                                                                                    [ 74%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration/validation (OK) PASSED                                                                                 [ 77%]
test_manager_endpoints.tavern.yaml::GET /manager/configuration/{component}/{configuration} PASSED                                                                     [ 80%]
test_manager_endpoints.tavern.yaml::PUT /manager/configuration PASSED                                                                                                 [ 82%]
test_manager_endpoints.tavern.yaml::GET /manager/version/check PASSED                                                                                                 [ 85%]
test_manager_endpoints.tavern.yaml::GET /manager/version/check with update_check disabled PASSED                                                                      [ 88%]
test_manager_endpoints.tavern.yaml::GET /manager/version/check with update check service error PASSED                                                                 [ 91%]
test_manager_endpoints.tavern.yaml::GET /manager/logs PASSED                                                                                                          [ 94%]
test_manager_endpoints.tavern.yaml::GET /manager/logs/summary PASSED                                                                                                  [ 97%]
test_manager_endpoints.tavern.yaml::PUT /manager/restart PASSED                                                                                                       [100%]

============================================================================= warnings summary ==============================================================================
../../../venv/lib/python3.10/site-packages/_pytest/nodes.py:642
  /home/gasti/work/wazuh/venv/lib/python3.10/site-packages/_pytest/nodes.py:642: PytestRemovedIn8Warning: The (fspath: py.path.local) argument to YamlFile is deprecated. Please use the (path: pathlib.Path) argument instead.
  See https://docs.pytest.org/en/latest/deprecations.html#fspath-argument-for-node-constructors-replaced-with-pathlib-path
    return super().from_parent(parent=parent, fspath=fspath, path=path, **kw)

test_manager_endpoints.tavern.yaml: 35 warnings
  <frozen importlib._bootstrap>:283: DeprecationWarning: the load_module() method is deprecated and slated for removal in Python 3.12; use exec_module() instead

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=============================================================== 35 passed, 36 warnings in 1107.13s (0:18:27) ================================================================

@GGP1 GGP1 self-assigned this May 10, 2024
@GGP1 GGP1 linked an issue May 10, 2024 that may be closed by this pull request
4 tasks
@GGP1 GGP1 force-pushed the fix/23362-ait-disable-update-check branch from 39fc777 to 374173b Compare May 10, 2024 15:17
nico-stefani
nico-stefani previously approved these changes May 14, 2024
Copy link
Member

@nico-stefani nico-stefani left a comment

Choose a reason for hiding this comment

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

I ran the pipeline and the related tests and environment were OK, LGTM!

Copy link
Member

@Selutario Selutario left a comment

Choose a reason for hiding this comment

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

Nice job! There is a conflict to solve after merging #23314.

@Selutario Selutario merged commit ce19a29 into 4.9.0 May 15, 2024
2 checks passed
@Selutario Selutario deleted the fix/23362-ait-disable-update-check branch May 15, 2024 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable update_check in API tavern tests
3 participants