def change_conf(report_value): """" Returns a new ossec configuration with a changed report_value""" conf_params, conf_metadata = generate_params( { 'REPORT_CHANGES': { 'report_changes': report_value }, 'TEST_DIRECTORIES': directory_str, 'NODIFF_FILE': nodiff_file, 'MODULE_NAME': __name__ }, { 'report_changes': report_value, 'test_directories': directory_str, 'nodiff_file': nodiff_file, 'module_name': __name__ }) return load_wazuh_configurations(configurations_path, __name__, params=conf_params, metadata=conf_metadata)
conf_params, conf_metadata = generate_params( { 'REPORT_CHANGES': { 'report_changes': 'yes' }, 'TEST_DIRECTORIES': directory_str, 'NODIFF_FILE': nodiff_file, 'MODULE_NAME': __name__ }, { 'report_changes': 'yes', 'test_directories': directory_str, 'nodiff_file': nodiff_file, 'module_name': __name__ }) configurations = load_wazuh_configurations(configurations_path, __name__, params=conf_params, metadata=conf_metadata) # fixtures @pytest.fixture(scope='module', params=configurations) def get_configuration(request): """Get configurations from the module.""" return request.param # tests @pytest.mark.parametrize('tags_to_apply', [{'ossec_conf_report'}]) @pytest.mark.parametrize('folder, checkers', [(testdir_reports, options), (testdir_nodiff, options)])
pytestmark = pytest.mark.linux # Variables test_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data') configurations_path = os.path.join(test_data_path, 'wazuh_conf.yaml') test_directories = [os.path.join('/', 'testdir1'), os.path.join('/', 'testdir2'), os.path.join('/', 'testdir3')] testdir1, testdir2, testdir3 = test_directories wazuh_log_monitor = FileMonitor(LOG_FILE_PATH) # Configurations configurations = load_wazuh_configurations(configurations_path, __name__) # Fixtures @pytest.fixture(scope='module', params=configurations) def get_configuration(request): """Get configurations from the module.""" return request.param # Test @pytest.mark.parametrize('tags_to_apply, folder', [ ({'config1'}, testdir1), ({'config1'}, testdir2),
# Extra functions def extra_configuration_before_yield(): # Create files before starting the service create_file(REGULAR, testdir1, 'regular0', content='') create_file(REGULAR, testdir1, 'regular1', content='') create_file(REGULAR, testdir1, 'regular2', content='') # Configurations conf_params = {'TEST_DIRECTORIES': directory_str, 'MODULE_NAME': __name__} conf_metadata = {'test_directories': directory_str, 'module_name': __name__} p, m = generate_params(conf_params, conf_metadata) configurations = load_wazuh_configurations(configurations_path, __name__, params=p, metadata=m) # Fixtures @pytest.fixture(scope='module', params=configurations) def get_configuration(request): """Get configurations from the module.""" return request.param # Tests @pytest.mark.parametrize('filename', [ 'regular0', 'regular1',
configurations = load_wazuh_configurations(configurations_path, __name__, params=[ { 'SCAN_DAY': scan_days[0], 'SCAN_TIME': scan_times[0], 'TEST_DIRECTORIES': directory_str }, { 'SCAN_DAY': scan_days[1], 'SCAN_TIME': scan_times[1], 'TEST_DIRECTORIES': directory_str }, ], metadata=[ { 'scan_day': scan_days[0], 'scan_time': scan_times[0], 'test_directories': directory_str }, { 'scan_day': scan_days[1], 'scan_time': scan_times[1], 'test_directories': directory_str }, ])
os.path.join(PREFIX, 'testdir1'), os.path.join(PREFIX, 'testdir2') ] directory_str = ','.join(test_directories) force_restart_after_restoring = True wazuh_log_monitor = FileMonitor(LOG_FILE_PATH) # configurations configurations = load_wazuh_configurations(configurations_path, __name__, params=[{ 'TEST_DIRECTORIES': directory_str }], metadata=[{ 'test_directories': directory_str }]) # fixtures @pytest.fixture(scope='module', params=configurations) def get_configuration(request): """Get configurations from the module.""" return request.param # tests