-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathconftest.py
54 lines (43 loc) · 1.82 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import platform
import pytest
import wazuh_testing.execd as execd
from wazuh_testing.tools import WAZUH_PATH, get_version
@pytest.fixture(scope="session")
def set_ar_conf_mode():
"""Configure Active Responses used in tests."""
folder = 'shared' if platform.system() == 'Windows' else 'etc/shared'
local_int_conf_path = os.path.join(WAZUH_PATH, folder, 'ar.conf')
debug_line = "restart-wazuh0 - restart-wazuh - 0\nrestart-wazuh0 - restart-wazuh.exe - 0\n" \
"firewall-drop0 - firewall-drop - 0\nfirewall-drop5 - firewall-drop - 5\n"
with open(local_int_conf_path, 'w') as local_file_write:
local_file_write.write('\n'+debug_line)
with open(local_int_conf_path, 'r') as local_file_read:
lines = local_file_read.readlines()
for line in lines:
if line == debug_line:
return
@pytest.fixture(scope="session")
def set_debug_mode():
"""Set execd daemon in debug mode."""
folder = '' if platform.system() == 'Windows' else 'etc'
local_int_conf_path = os.path.join(WAZUH_PATH, folder, 'local_internal_options.conf')
debug_line = 'windows.debug=2\n' if platform.system() == 'Windows' else 'execd.debug=2\n'
with open(local_int_conf_path) as local_file_read:
lines = local_file_read.readlines()
for line in lines:
if line == debug_line:
return
with open(local_int_conf_path, 'a') as local_file_write:
local_file_write.write('\n'+debug_line)
@pytest.fixture(scope="session")
def test_version():
"""Validate Wazuh version."""
if get_version() < "v4.2.0":
raise AssertionError("The version of the agent is < 4.2.0")
@pytest.fixture
def truncate_ar_log():
"""Truncate the logs related with Active Response."""
execd.clean_logs()
yield
execd.clean_logs()