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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions api/test/integration/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ variables:
<email_notification>no</email_notification>
<agents_disconnection_time>20s</agents_disconnection_time>
<agents_disconnection_alert_time>100s</agents_disconnection_alert_time>
<update_check>yes</update_check>
<update_check>no</update_check>
</global>

<logging>
Expand Down Expand Up @@ -197,7 +197,7 @@ variables:
</vulnerability-detection>
</ossec_config>

valid_ossec_conf_with_update_check_disabled:
valid_ossec_conf_with_update_check_enabled:
<ossec_config>
<global>
<jsonout_output>yes</jsonout_output>
Expand All @@ -207,7 +207,8 @@ variables:
<email_notification>no</email_notification>
<agents_disconnection_time>20s</agents_disconnection_time>
<agents_disconnection_alert_time>100s</agents_disconnection_alert_time>
<update_check>no</update_check>
<update_check>yes</update_check>
<cti-url>http://cti:4041</cti-url>
</global>

<logging>
Expand Down
9 changes: 9 additions & 0 deletions api/test/integration/env/base/cti/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.12-alpine

ENV PORT=4041

EXPOSE $PORT

COPY . .

CMD python3 http_server.py ${PORT}
71 changes: 71 additions & 0 deletions api/test/integration/env/base/cti/http_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (C) 2015, Wazuh Inc.
# Created by Wazuh, Inc. <info@wazuh.com>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import argparse
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
import re
import sys

MOCK_RESPONSE = {
'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': []
}
}

class Handler(BaseHTTPRequestHandler):
"""Custom HTTP request handler to respond to Wazuh's CTI service requests."""

def do_GET(self):
if re.search('/cti/v1/ping', self.path):
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.end_headers()

data = json.dumps(MOCK_RESPONSE).encode('utf-8')
self.wfile.write(data)
else:
self.send_response(403)
self.end_headers()

def _argparse() -> argparse.Namespace:
"""Parse command line arguments.

Returns
-------
argparse.Namespace
Simple object for storing attributes.
"""
parser = argparse.ArgumentParser()
parser.add_argument('port', action='store', default=4041, type=int, nargs='?',
help='Specify alternate port [default: 4041]')
return parser.parse_args()

def main():
args = _argparse()

server = HTTPServer(('0.0.0.0', args.port), Handler)
try:
print(f'Listening on port {args.port}...', file=sys.stderr)
server.serve_forever()
except KeyboardInterrupt:
pass
server.server_close()

if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions api/test/integration/env/base/manager/preloaded-vars.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ USER_ENABLE_OPENSCAP="y"
USER_WHITE_LIST="n"
USER_ENABLE_SYSLOG="y"
USER_ENABLE_AUTHD="y"
USER_ENABLE_UPDATE_CHECK="n"
USER_AUTO_START="n"

11 changes: 11 additions & 0 deletions api/test/integration/env/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,14 @@ services:
- wazuh-master
- wazuh-worker1
- wazuh-worker2

cti:
profiles:
- standalone
- cluster
build:
context: ./base/cti
image: integration_test_cti
restart: always
environment:
- PORT=4041
80 changes: 40 additions & 40 deletions api/test/integration/test_manager_endpoints.tavern.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,45 @@ stages:
save:
json:
wazuh_version: data.api_version

- name: Enable update check
request:
verify: False
url: "{protocol:s}://{host:s}:{port:d}/manager/configuration"
method: PUT
data: "{valid_ossec_conf_with_update_check_enabled:s}"
headers:
Authorization: "Bearer {test_login_token}"
content-type: application/octet-stream
response:
status_code: 200
json:
data:
affected_items:
- 'manager'
failed_items: []
total_affected_items: 1
total_failed_items: 0
error: 0

- name: Restart manager to apply the configuration
request:
verify: False
url: "{protocol:s}://{host:s}:{port:d}/manager/restart"
method: PUT
headers:
Authorization: "Bearer {test_login_token}"
response:
status_code: 200
json:
error: 0
data:
affected_items:
- !anystr
failed_items: []
total_affected_items: 1
total_failed_items: 0
delay_after: 50

- name: Get available updates
request:
Expand Down Expand Up @@ -1300,7 +1339,7 @@ stages:
verify: False
url: "{protocol:s}://{host:s}:{port:d}/manager/configuration"
method: PUT
data: "{valid_ossec_conf_with_update_check_disabled:s}"
data: "{valid_ossec_conf:s}"
headers:
Authorization: "Bearer {test_login_token}"
content-type: application/octet-stream
Expand Down Expand Up @@ -1366,45 +1405,6 @@ stages:
current_version: "v{wazuh_version:s}"
update_check: false

- name: Enable the update check
request:
verify: False
url: "{protocol:s}://{host:s}:{port:d}/manager/configuration"
method: PUT
data: "{valid_ossec_conf:s}"
headers:
Authorization: "Bearer {test_login_token}"
content-type: application/octet-stream
response:
status_code: 200
json:
data:
affected_items:
- 'manager'
failed_items: []
total_affected_items: 1
total_failed_items: 0
error: 0

- name: Restart manager to apply the configuration
request:
verify: False
url: "{protocol:s}://{host:s}:{port:d}/manager/restart"
method: PUT
headers:
Authorization: "Bearer {test_login_token}"
response:
status_code: 200
json:
error: 0
data:
affected_items:
- !anystr
failed_items: []
total_affected_items: 1
total_failed_items: 0
delay_after: 50

---
test_name: GET /manager/version/check with update check service error

Expand Down