mirror of https://github.com/ansible/ansible.git
FortiOS modules for 2.9 - 7 (#61217)
parent
9d4dcc7506
commit
a6b124cccc
@ -0,0 +1,175 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_memory_global_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_memory_global_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_memory_global_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_memory_global_setting': {
|
||||||
|
'full_final_warning_threshold': '3',
|
||||||
|
'full_first_warning_threshold': '4',
|
||||||
|
'full_second_warning_threshold': '5',
|
||||||
|
'max_size': '6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_memory_global_setting.fortios_log_memory(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'full-final-warning-threshold': '3',
|
||||||
|
'full-first-warning-threshold': '4',
|
||||||
|
'full-second-warning-threshold': '5',
|
||||||
|
'max-size': '6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.memory', 'global-setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_memory_global_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_memory_global_setting': {
|
||||||
|
'full_final_warning_threshold': '3',
|
||||||
|
'full_first_warning_threshold': '4',
|
||||||
|
'full_second_warning_threshold': '5',
|
||||||
|
'max_size': '6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_memory_global_setting.fortios_log_memory(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'full-final-warning-threshold': '3',
|
||||||
|
'full-first-warning-threshold': '4',
|
||||||
|
'full-second-warning-threshold': '5',
|
||||||
|
'max-size': '6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.memory', 'global-setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_memory_global_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_memory_global_setting': {
|
||||||
|
'full_final_warning_threshold': '3',
|
||||||
|
'full_first_warning_threshold': '4',
|
||||||
|
'full_second_warning_threshold': '5',
|
||||||
|
'max_size': '6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_memory_global_setting.fortios_log_memory(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'full-final-warning-threshold': '3',
|
||||||
|
'full-first-warning-threshold': '4',
|
||||||
|
'full-second-warning-threshold': '5',
|
||||||
|
'max-size': '6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.memory', 'global-setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_memory_global_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_memory_global_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'full_final_warning_threshold': '3',
|
||||||
|
'full_first_warning_threshold': '4',
|
||||||
|
'full_second_warning_threshold': '5',
|
||||||
|
'max_size': '6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_memory_global_setting.fortios_log_memory(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'full-final-warning-threshold': '3',
|
||||||
|
'full-first-warning-threshold': '4',
|
||||||
|
'full-second-warning-threshold': '5',
|
||||||
|
'max-size': '6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.memory', 'global-setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,159 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_memory_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_memory_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_memory_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_memory_setting': {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_memory_setting.fortios_log_memory(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.memory', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_memory_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_memory_setting': {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_memory_setting.fortios_log_memory(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.memory', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_memory_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_memory_setting': {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_memory_setting.fortios_log_memory(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.memory', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_memory_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_memory_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_memory_setting.fortios_log_memory(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.memory', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,255 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_null_device_filter
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_null_device_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_null_device_filter_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_null_device_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_null_device_filter.fortios_log_null_device(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.null-device', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_null_device_filter_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_null_device_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_null_device_filter.fortios_log_null_device(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.null-device', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_null_device_filter_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_null_device_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_null_device_filter.fortios_log_null_device(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.null-device', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_null_device_filter_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_null_device_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_null_device_filter.fortios_log_null_device(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.null-device', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,151 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_null_device_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_null_device_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_null_device_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_null_device_setting': {
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_null_device_setting.fortios_log_null_device(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.null-device', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_null_device_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_null_device_setting': {
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_null_device_setting.fortios_log_null_device(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.null-device', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_null_device_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_null_device_setting': {
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_null_device_setting.fortios_log_null_device(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.null-device', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_null_device_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_null_device_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_null_device_setting.fortios_log_null_device(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.null-device', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,279 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_setting': {
|
||||||
|
'brief_traffic_format': 'enable',
|
||||||
|
'daemon_log': 'enable',
|
||||||
|
'expolicy_implicit_log': 'enable',
|
||||||
|
'fwpolicy_implicit_log': 'enable',
|
||||||
|
'fwpolicy6_implicit_log': 'enable',
|
||||||
|
'local_in_allow': 'enable',
|
||||||
|
'local_in_deny_broadcast': 'enable',
|
||||||
|
'local_in_deny_unicast': 'enable',
|
||||||
|
'local_out': 'enable',
|
||||||
|
'log_invalid_packet': 'enable',
|
||||||
|
'log_policy_comment': 'enable',
|
||||||
|
'log_policy_name': 'enable',
|
||||||
|
'log_user_in_upper': 'enable',
|
||||||
|
'neighbor_event': 'enable',
|
||||||
|
'resolve_ip': 'enable',
|
||||||
|
'resolve_port': 'enable',
|
||||||
|
'user_anonymize': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_setting.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'brief-traffic-format': 'enable',
|
||||||
|
'daemon-log': 'enable',
|
||||||
|
'expolicy-implicit-log': 'enable',
|
||||||
|
'fwpolicy-implicit-log': 'enable',
|
||||||
|
'fwpolicy6-implicit-log': 'enable',
|
||||||
|
'local-in-allow': 'enable',
|
||||||
|
'local-in-deny-broadcast': 'enable',
|
||||||
|
'local-in-deny-unicast': 'enable',
|
||||||
|
'local-out': 'enable',
|
||||||
|
'log-invalid-packet': 'enable',
|
||||||
|
'log-policy-comment': 'enable',
|
||||||
|
'log-policy-name': 'enable',
|
||||||
|
'log-user-in-upper': 'enable',
|
||||||
|
'neighbor-event': 'enable',
|
||||||
|
'resolve-ip': 'enable',
|
||||||
|
'resolve-port': 'enable',
|
||||||
|
'user-anonymize': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_setting': {
|
||||||
|
'brief_traffic_format': 'enable',
|
||||||
|
'daemon_log': 'enable',
|
||||||
|
'expolicy_implicit_log': 'enable',
|
||||||
|
'fwpolicy_implicit_log': 'enable',
|
||||||
|
'fwpolicy6_implicit_log': 'enable',
|
||||||
|
'local_in_allow': 'enable',
|
||||||
|
'local_in_deny_broadcast': 'enable',
|
||||||
|
'local_in_deny_unicast': 'enable',
|
||||||
|
'local_out': 'enable',
|
||||||
|
'log_invalid_packet': 'enable',
|
||||||
|
'log_policy_comment': 'enable',
|
||||||
|
'log_policy_name': 'enable',
|
||||||
|
'log_user_in_upper': 'enable',
|
||||||
|
'neighbor_event': 'enable',
|
||||||
|
'resolve_ip': 'enable',
|
||||||
|
'resolve_port': 'enable',
|
||||||
|
'user_anonymize': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_setting.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'brief-traffic-format': 'enable',
|
||||||
|
'daemon-log': 'enable',
|
||||||
|
'expolicy-implicit-log': 'enable',
|
||||||
|
'fwpolicy-implicit-log': 'enable',
|
||||||
|
'fwpolicy6-implicit-log': 'enable',
|
||||||
|
'local-in-allow': 'enable',
|
||||||
|
'local-in-deny-broadcast': 'enable',
|
||||||
|
'local-in-deny-unicast': 'enable',
|
||||||
|
'local-out': 'enable',
|
||||||
|
'log-invalid-packet': 'enable',
|
||||||
|
'log-policy-comment': 'enable',
|
||||||
|
'log-policy-name': 'enable',
|
||||||
|
'log-user-in-upper': 'enable',
|
||||||
|
'neighbor-event': 'enable',
|
||||||
|
'resolve-ip': 'enable',
|
||||||
|
'resolve-port': 'enable',
|
||||||
|
'user-anonymize': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_setting': {
|
||||||
|
'brief_traffic_format': 'enable',
|
||||||
|
'daemon_log': 'enable',
|
||||||
|
'expolicy_implicit_log': 'enable',
|
||||||
|
'fwpolicy_implicit_log': 'enable',
|
||||||
|
'fwpolicy6_implicit_log': 'enable',
|
||||||
|
'local_in_allow': 'enable',
|
||||||
|
'local_in_deny_broadcast': 'enable',
|
||||||
|
'local_in_deny_unicast': 'enable',
|
||||||
|
'local_out': 'enable',
|
||||||
|
'log_invalid_packet': 'enable',
|
||||||
|
'log_policy_comment': 'enable',
|
||||||
|
'log_policy_name': 'enable',
|
||||||
|
'log_user_in_upper': 'enable',
|
||||||
|
'neighbor_event': 'enable',
|
||||||
|
'resolve_ip': 'enable',
|
||||||
|
'resolve_port': 'enable',
|
||||||
|
'user_anonymize': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_setting.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'brief-traffic-format': 'enable',
|
||||||
|
'daemon-log': 'enable',
|
||||||
|
'expolicy-implicit-log': 'enable',
|
||||||
|
'fwpolicy-implicit-log': 'enable',
|
||||||
|
'fwpolicy6-implicit-log': 'enable',
|
||||||
|
'local-in-allow': 'enable',
|
||||||
|
'local-in-deny-broadcast': 'enable',
|
||||||
|
'local-in-deny-unicast': 'enable',
|
||||||
|
'local-out': 'enable',
|
||||||
|
'log-invalid-packet': 'enable',
|
||||||
|
'log-policy-comment': 'enable',
|
||||||
|
'log-policy-name': 'enable',
|
||||||
|
'log-user-in-upper': 'enable',
|
||||||
|
'neighbor-event': 'enable',
|
||||||
|
'resolve-ip': 'enable',
|
||||||
|
'resolve-port': 'enable',
|
||||||
|
'user-anonymize': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'brief_traffic_format': 'enable',
|
||||||
|
'daemon_log': 'enable',
|
||||||
|
'expolicy_implicit_log': 'enable',
|
||||||
|
'fwpolicy_implicit_log': 'enable',
|
||||||
|
'fwpolicy6_implicit_log': 'enable',
|
||||||
|
'local_in_allow': 'enable',
|
||||||
|
'local_in_deny_broadcast': 'enable',
|
||||||
|
'local_in_deny_unicast': 'enable',
|
||||||
|
'local_out': 'enable',
|
||||||
|
'log_invalid_packet': 'enable',
|
||||||
|
'log_policy_comment': 'enable',
|
||||||
|
'log_policy_name': 'enable',
|
||||||
|
'log_user_in_upper': 'enable',
|
||||||
|
'neighbor_event': 'enable',
|
||||||
|
'resolve_ip': 'enable',
|
||||||
|
'resolve_port': 'enable',
|
||||||
|
'user_anonymize': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_setting.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'brief-traffic-format': 'enable',
|
||||||
|
'daemon-log': 'enable',
|
||||||
|
'expolicy-implicit-log': 'enable',
|
||||||
|
'fwpolicy-implicit-log': 'enable',
|
||||||
|
'fwpolicy6-implicit-log': 'enable',
|
||||||
|
'local-in-allow': 'enable',
|
||||||
|
'local-in-deny-broadcast': 'enable',
|
||||||
|
'local-in-deny-unicast': 'enable',
|
||||||
|
'local-out': 'enable',
|
||||||
|
'log-invalid-packet': 'enable',
|
||||||
|
'log-policy-comment': 'enable',
|
||||||
|
'log-policy-name': 'enable',
|
||||||
|
'log-user-in-upper': 'enable',
|
||||||
|
'neighbor-event': 'enable',
|
||||||
|
'resolve-ip': 'enable',
|
||||||
|
'resolve-port': 'enable',
|
||||||
|
'user-anonymize': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,255 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_syslogd2_filter
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_syslogd2_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd2_filter_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd2_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd2_filter.fortios_log_syslogd2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd2', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd2_filter_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd2_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd2_filter.fortios_log_syslogd2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd2', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd2_filter_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd2_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd2_filter.fortios_log_syslogd2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd2', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd2_filter_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd2_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd2_filter.fortios_log_syslogd2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd2', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,223 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_syslogd2_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_syslogd2_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd2_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd2_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd2_setting.fortios_log_syslogd2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd2', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd2_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd2_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd2_setting.fortios_log_syslogd2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd2', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd2_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd2_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd2_setting.fortios_log_syslogd2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd2', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd2_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd2_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd2_setting.fortios_log_syslogd2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd2', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,255 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_syslogd3_filter
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_syslogd3_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd3_filter_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd3_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd3_filter.fortios_log_syslogd3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd3', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd3_filter_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd3_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd3_filter.fortios_log_syslogd3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd3', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd3_filter_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd3_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd3_filter.fortios_log_syslogd3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd3', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd3_filter_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd3_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd3_filter.fortios_log_syslogd3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd3', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,223 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_syslogd3_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_syslogd3_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd3_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd3_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd3_setting.fortios_log_syslogd3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd3', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd3_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd3_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd3_setting.fortios_log_syslogd3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd3', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd3_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd3_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd3_setting.fortios_log_syslogd3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd3', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd3_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd3_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd3_setting.fortios_log_syslogd3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd3', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,255 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_syslogd4_filter
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_syslogd4_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd4_filter_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd4_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd4_filter.fortios_log_syslogd4(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd4', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd4_filter_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd4_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd4_filter.fortios_log_syslogd4(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd4', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd4_filter_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd4_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd4_filter.fortios_log_syslogd4(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd4', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd4_filter_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd4_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd4_filter.fortios_log_syslogd4(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd4', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,223 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_syslogd4_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_syslogd4_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd4_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd4_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd4_setting.fortios_log_syslogd4(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd4', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd4_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd4_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd4_setting.fortios_log_syslogd4(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd4', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd4_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd4_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd4_setting.fortios_log_syslogd4(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd4', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd4_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd4_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd4_setting.fortios_log_syslogd4(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd4', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,255 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_syslogd_filter
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_syslogd_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_filter_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_filter.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_filter_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_filter.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_filter_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_filter.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_filter_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_filter.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,255 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_syslogd_override_filter
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_syslogd_override_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_override_filter_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_override_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_override_filter.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'override-filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_override_filter_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_override_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_override_filter.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'override-filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_override_filter_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_override_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_override_filter.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'override-filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_override_filter_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_override_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_override_filter.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'override-filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,231 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_syslogd_override_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_syslogd_override_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_override_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_override_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'override': 'enable',
|
||||||
|
'port': '9',
|
||||||
|
'server': '192.168.100.10',
|
||||||
|
'source_ip': '84.230.14.11',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_override_setting.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'override': 'enable',
|
||||||
|
'port': '9',
|
||||||
|
'server': '192.168.100.10',
|
||||||
|
'source-ip': '84.230.14.11',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'override-setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_override_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_override_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'override': 'enable',
|
||||||
|
'port': '9',
|
||||||
|
'server': '192.168.100.10',
|
||||||
|
'source_ip': '84.230.14.11',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_override_setting.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'override': 'enable',
|
||||||
|
'port': '9',
|
||||||
|
'server': '192.168.100.10',
|
||||||
|
'source-ip': '84.230.14.11',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'override-setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_override_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_override_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'override': 'enable',
|
||||||
|
'port': '9',
|
||||||
|
'server': '192.168.100.10',
|
||||||
|
'source_ip': '84.230.14.11',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_override_setting.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'override': 'enable',
|
||||||
|
'port': '9',
|
||||||
|
'server': '192.168.100.10',
|
||||||
|
'source-ip': '84.230.14.11',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'override-setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_override_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_override_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'override': 'enable',
|
||||||
|
'port': '9',
|
||||||
|
'server': '192.168.100.10',
|
||||||
|
'source_ip': '84.230.14.11',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_override_setting.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'override': 'enable',
|
||||||
|
'port': '9',
|
||||||
|
'server': '192.168.100.10',
|
||||||
|
'source-ip': '84.230.14.11',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'override-setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,223 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_syslogd_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_syslogd_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_setting.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_setting.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_setting': {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_setting.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_syslogd_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_syslogd_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source_ip': '84.230.14.10',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_syslogd_setting.fortios_log_syslogd(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'certificate': 'test_value_3',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'facility': 'kernel',
|
||||||
|
'format': 'default',
|
||||||
|
'mode': 'udp',
|
||||||
|
'port': '8',
|
||||||
|
'server': '192.168.100.9',
|
||||||
|
'source-ip': '84.230.14.10',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.syslogd', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,175 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_threat_weight
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_threat_weight.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_threat_weight_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_threat_weight': {'blocked_connection': 'disable',
|
||||||
|
'failed_connection': 'disable',
|
||||||
|
'status': 'enable',
|
||||||
|
'url_block_detected': 'disable',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_threat_weight.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'blocked-connection': 'disable',
|
||||||
|
'failed-connection': 'disable',
|
||||||
|
'status': 'enable',
|
||||||
|
'url-block-detected': 'disable',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'threat-weight', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_threat_weight_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_threat_weight': {'blocked_connection': 'disable',
|
||||||
|
'failed_connection': 'disable',
|
||||||
|
'status': 'enable',
|
||||||
|
'url_block_detected': 'disable',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_threat_weight.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'blocked-connection': 'disable',
|
||||||
|
'failed-connection': 'disable',
|
||||||
|
'status': 'enable',
|
||||||
|
'url-block-detected': 'disable',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'threat-weight', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_threat_weight_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_threat_weight': {'blocked_connection': 'disable',
|
||||||
|
'failed_connection': 'disable',
|
||||||
|
'status': 'enable',
|
||||||
|
'url_block_detected': 'disable',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_threat_weight.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'blocked-connection': 'disable',
|
||||||
|
'failed-connection': 'disable',
|
||||||
|
'status': 'enable',
|
||||||
|
'url-block-detected': 'disable',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'threat-weight', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_threat_weight_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_threat_weight': {
|
||||||
|
'random_attribute_not_valid': 'tag', 'blocked_connection': 'disable',
|
||||||
|
'failed_connection': 'disable',
|
||||||
|
'status': 'enable',
|
||||||
|
'url_block_detected': 'disable',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_threat_weight.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'blocked-connection': 'disable',
|
||||||
|
'failed-connection': 'disable',
|
||||||
|
'status': 'enable',
|
||||||
|
'url-block-detected': 'disable',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'threat-weight', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,255 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_webtrends_filter
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_webtrends_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_webtrends_filter_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_webtrends_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_webtrends_filter.fortios_log_webtrends(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.webtrends', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_webtrends_filter_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_webtrends_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_webtrends_filter.fortios_log_webtrends(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.webtrends', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_webtrends_filter_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_webtrends_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_webtrends_filter.fortios_log_webtrends(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.webtrends', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_webtrends_filter_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_webtrends_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_11,',
|
||||||
|
'netscan_vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_webtrends_filter.fortios_log_webtrends(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_5',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_11,',
|
||||||
|
'netscan-vulnerability': 'test_value_12,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.webtrends', 'filter', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,159 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_log_webtrends_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_log_webtrends_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_webtrends_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_webtrends_setting': {
|
||||||
|
'server': '192.168.100.3',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_webtrends_setting.fortios_log_webtrends(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'server': '192.168.100.3',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.webtrends', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_webtrends_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_webtrends_setting': {
|
||||||
|
'server': '192.168.100.3',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_webtrends_setting.fortios_log_webtrends(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'server': '192.168.100.3',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.webtrends', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_webtrends_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_webtrends_setting': {
|
||||||
|
'server': '192.168.100.3',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_webtrends_setting.fortios_log_webtrends(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'server': '192.168.100.3',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.webtrends', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_webtrends_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'log_webtrends_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'server': '192.168.100.3',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_webtrends_setting.fortios_log_webtrends(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'server': '192.168.100.3',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.webtrends', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,369 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_report_chart
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_report_chart.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_chart_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_chart': {
|
||||||
|
'background': 'test_value_3',
|
||||||
|
'category': 'misc',
|
||||||
|
'color_palette': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'dataset': 'test_value_7',
|
||||||
|
'dimension': '2D',
|
||||||
|
'favorite': 'no',
|
||||||
|
'graph_type': 'none',
|
||||||
|
'legend': 'enable',
|
||||||
|
'legend_font_size': '12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'period': 'last24h',
|
||||||
|
'policy': '15',
|
||||||
|
'style': 'auto',
|
||||||
|
'title': 'test_value_17',
|
||||||
|
'title_font_size': '18',
|
||||||
|
'type': 'graph',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_chart.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'background': 'test_value_3',
|
||||||
|
'category': 'misc',
|
||||||
|
'color-palette': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'dataset': 'test_value_7',
|
||||||
|
'dimension': '2D',
|
||||||
|
'favorite': 'no',
|
||||||
|
'graph-type': 'none',
|
||||||
|
'legend': 'enable',
|
||||||
|
'legend-font-size': '12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'period': 'last24h',
|
||||||
|
'policy': '15',
|
||||||
|
'style': 'auto',
|
||||||
|
'title': 'test_value_17',
|
||||||
|
'title-font-size': '18',
|
||||||
|
'type': 'graph',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'chart', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_chart_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_chart': {
|
||||||
|
'background': 'test_value_3',
|
||||||
|
'category': 'misc',
|
||||||
|
'color_palette': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'dataset': 'test_value_7',
|
||||||
|
'dimension': '2D',
|
||||||
|
'favorite': 'no',
|
||||||
|
'graph_type': 'none',
|
||||||
|
'legend': 'enable',
|
||||||
|
'legend_font_size': '12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'period': 'last24h',
|
||||||
|
'policy': '15',
|
||||||
|
'style': 'auto',
|
||||||
|
'title': 'test_value_17',
|
||||||
|
'title_font_size': '18',
|
||||||
|
'type': 'graph',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_chart.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'background': 'test_value_3',
|
||||||
|
'category': 'misc',
|
||||||
|
'color-palette': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'dataset': 'test_value_7',
|
||||||
|
'dimension': '2D',
|
||||||
|
'favorite': 'no',
|
||||||
|
'graph-type': 'none',
|
||||||
|
'legend': 'enable',
|
||||||
|
'legend-font-size': '12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'period': 'last24h',
|
||||||
|
'policy': '15',
|
||||||
|
'style': 'auto',
|
||||||
|
'title': 'test_value_17',
|
||||||
|
'title-font-size': '18',
|
||||||
|
'type': 'graph',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'chart', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_chart_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'report_chart': {
|
||||||
|
'background': 'test_value_3',
|
||||||
|
'category': 'misc',
|
||||||
|
'color_palette': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'dataset': 'test_value_7',
|
||||||
|
'dimension': '2D',
|
||||||
|
'favorite': 'no',
|
||||||
|
'graph_type': 'none',
|
||||||
|
'legend': 'enable',
|
||||||
|
'legend_font_size': '12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'period': 'last24h',
|
||||||
|
'policy': '15',
|
||||||
|
'style': 'auto',
|
||||||
|
'title': 'test_value_17',
|
||||||
|
'title_font_size': '18',
|
||||||
|
'type': 'graph',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_chart.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('report', 'chart', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_chart_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'report_chart': {
|
||||||
|
'background': 'test_value_3',
|
||||||
|
'category': 'misc',
|
||||||
|
'color_palette': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'dataset': 'test_value_7',
|
||||||
|
'dimension': '2D',
|
||||||
|
'favorite': 'no',
|
||||||
|
'graph_type': 'none',
|
||||||
|
'legend': 'enable',
|
||||||
|
'legend_font_size': '12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'period': 'last24h',
|
||||||
|
'policy': '15',
|
||||||
|
'style': 'auto',
|
||||||
|
'title': 'test_value_17',
|
||||||
|
'title_font_size': '18',
|
||||||
|
'type': 'graph',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_chart.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('report', 'chart', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_chart_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_chart': {
|
||||||
|
'background': 'test_value_3',
|
||||||
|
'category': 'misc',
|
||||||
|
'color_palette': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'dataset': 'test_value_7',
|
||||||
|
'dimension': '2D',
|
||||||
|
'favorite': 'no',
|
||||||
|
'graph_type': 'none',
|
||||||
|
'legend': 'enable',
|
||||||
|
'legend_font_size': '12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'period': 'last24h',
|
||||||
|
'policy': '15',
|
||||||
|
'style': 'auto',
|
||||||
|
'title': 'test_value_17',
|
||||||
|
'title_font_size': '18',
|
||||||
|
'type': 'graph',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_chart.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'background': 'test_value_3',
|
||||||
|
'category': 'misc',
|
||||||
|
'color-palette': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'dataset': 'test_value_7',
|
||||||
|
'dimension': '2D',
|
||||||
|
'favorite': 'no',
|
||||||
|
'graph-type': 'none',
|
||||||
|
'legend': 'enable',
|
||||||
|
'legend-font-size': '12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'period': 'last24h',
|
||||||
|
'policy': '15',
|
||||||
|
'style': 'auto',
|
||||||
|
'title': 'test_value_17',
|
||||||
|
'title-font-size': '18',
|
||||||
|
'type': 'graph',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'chart', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_chart_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_chart': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'background': 'test_value_3',
|
||||||
|
'category': 'misc',
|
||||||
|
'color_palette': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'dataset': 'test_value_7',
|
||||||
|
'dimension': '2D',
|
||||||
|
'favorite': 'no',
|
||||||
|
'graph_type': 'none',
|
||||||
|
'legend': 'enable',
|
||||||
|
'legend_font_size': '12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'period': 'last24h',
|
||||||
|
'policy': '15',
|
||||||
|
'style': 'auto',
|
||||||
|
'title': 'test_value_17',
|
||||||
|
'title_font_size': '18',
|
||||||
|
'type': 'graph',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_chart.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'background': 'test_value_3',
|
||||||
|
'category': 'misc',
|
||||||
|
'color-palette': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'dataset': 'test_value_7',
|
||||||
|
'dimension': '2D',
|
||||||
|
'favorite': 'no',
|
||||||
|
'graph-type': 'none',
|
||||||
|
'legend': 'enable',
|
||||||
|
'legend-font-size': '12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'period': 'last24h',
|
||||||
|
'policy': '15',
|
||||||
|
'style': 'auto',
|
||||||
|
'title': 'test_value_17',
|
||||||
|
'title-font-size': '18',
|
||||||
|
'type': 'graph',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'chart', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,209 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_report_dataset
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_report_dataset.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_dataset_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_dataset': {'name': 'default_name_3',
|
||||||
|
'policy': '4',
|
||||||
|
'query': 'test_value_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_dataset.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'name': 'default_name_3',
|
||||||
|
'policy': '4',
|
||||||
|
'query': 'test_value_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'dataset', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_dataset_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_dataset': {'name': 'default_name_3',
|
||||||
|
'policy': '4',
|
||||||
|
'query': 'test_value_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_dataset.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'name': 'default_name_3',
|
||||||
|
'policy': '4',
|
||||||
|
'query': 'test_value_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'dataset', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_dataset_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'report_dataset': {'name': 'default_name_3',
|
||||||
|
'policy': '4',
|
||||||
|
'query': 'test_value_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_dataset.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('report', 'dataset', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_dataset_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'report_dataset': {'name': 'default_name_3',
|
||||||
|
'policy': '4',
|
||||||
|
'query': 'test_value_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_dataset.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('report', 'dataset', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_dataset_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_dataset': {'name': 'default_name_3',
|
||||||
|
'policy': '4',
|
||||||
|
'query': 'test_value_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_dataset.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'name': 'default_name_3',
|
||||||
|
'policy': '4',
|
||||||
|
'query': 'test_value_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'dataset', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_dataset_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_dataset': {
|
||||||
|
'random_attribute_not_valid': 'tag', 'name': 'default_name_3',
|
||||||
|
'policy': '4',
|
||||||
|
'query': 'test_value_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_dataset.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'name': 'default_name_3',
|
||||||
|
'policy': '4',
|
||||||
|
'query': 'test_value_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'dataset', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
Loading…
Reference in New Issue