mirror of https://github.com/ansible/ansible.git
FortiOS modules for 2.9 - 6 (#61170)
* FortiOS modules for 2.9 - 5 * Update fortios_firewall_vip.py * Update fortios_firewall_vip6.pypull/61217/head
parent
2ce3ce8477
commit
a6837609e2
@ -0,0 +1,239 @@
|
|||||||
|
# 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_ips_sensor
|
||||||
|
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_ips_sensor.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_sensor_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',
|
||||||
|
'ips_sensor': {
|
||||||
|
'block_malicious_url': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'replacemsg_group': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_sensor.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'block-malicious-url': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'replacemsg-group': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'sensor', 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_ips_sensor_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',
|
||||||
|
'ips_sensor': {
|
||||||
|
'block_malicious_url': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'replacemsg_group': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_sensor.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'block-malicious-url': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'replacemsg-group': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'sensor', 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_ips_sensor_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',
|
||||||
|
'ips_sensor': {
|
||||||
|
'block_malicious_url': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'replacemsg_group': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_sensor.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('ips', 'sensor', 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_ips_sensor_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',
|
||||||
|
'ips_sensor': {
|
||||||
|
'block_malicious_url': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'replacemsg_group': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_sensor.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('ips', 'sensor', 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_ips_sensor_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',
|
||||||
|
'ips_sensor': {
|
||||||
|
'block_malicious_url': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'replacemsg_group': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_sensor.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'block-malicious-url': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'replacemsg-group': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'sensor', 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_ips_sensor_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',
|
||||||
|
'ips_sensor': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'block_malicious_url': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'replacemsg_group': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_sensor.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'block-malicious-url': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'replacemsg-group': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'sensor', 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_ips_settings
|
||||||
|
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_ips_settings.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_settings_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',
|
||||||
|
'ips_settings': {
|
||||||
|
'ips_packet_quota': '3',
|
||||||
|
'packet_log_history': '4',
|
||||||
|
'packet_log_memory': '5',
|
||||||
|
'packet_log_post_attack': '6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_settings.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'ips-packet-quota': '3',
|
||||||
|
'packet-log-history': '4',
|
||||||
|
'packet-log-memory': '5',
|
||||||
|
'packet-log-post-attack': '6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'settings', 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_ips_settings_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',
|
||||||
|
'ips_settings': {
|
||||||
|
'ips_packet_quota': '3',
|
||||||
|
'packet_log_history': '4',
|
||||||
|
'packet_log_memory': '5',
|
||||||
|
'packet_log_post_attack': '6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_settings.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'ips-packet-quota': '3',
|
||||||
|
'packet-log-history': '4',
|
||||||
|
'packet-log-memory': '5',
|
||||||
|
'packet-log-post-attack': '6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'settings', 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_ips_settings_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',
|
||||||
|
'ips_settings': {
|
||||||
|
'ips_packet_quota': '3',
|
||||||
|
'packet_log_history': '4',
|
||||||
|
'packet_log_memory': '5',
|
||||||
|
'packet_log_post_attack': '6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_settings.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'ips-packet-quota': '3',
|
||||||
|
'packet-log-history': '4',
|
||||||
|
'packet-log-memory': '5',
|
||||||
|
'packet-log-post-attack': '6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'settings', 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_ips_settings_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',
|
||||||
|
'ips_settings': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'ips_packet_quota': '3',
|
||||||
|
'packet_log_history': '4',
|
||||||
|
'packet_log_memory': '5',
|
||||||
|
'packet_log_post_attack': '6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_settings.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'ips-packet-quota': '3',
|
||||||
|
'packet-log-history': '4',
|
||||||
|
'packet-log-memory': '5',
|
||||||
|
'packet-log-post-attack': '6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'settings', 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,219 @@
|
|||||||
|
# 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_custom_field
|
||||||
|
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_custom_field.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_custom_field_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_custom_field': {
|
||||||
|
'id': '3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'value': 'test_value_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_custom_field.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'id': '3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'value': 'test_value_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'custom-field', 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_custom_field_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_custom_field': {
|
||||||
|
'id': '3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'value': 'test_value_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_custom_field.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'id': '3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'value': 'test_value_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'custom-field', 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_custom_field_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',
|
||||||
|
'log_custom_field': {
|
||||||
|
'id': '3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'value': 'test_value_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_custom_field.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('log', 'custom-field', 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_log_custom_field_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',
|
||||||
|
'log_custom_field': {
|
||||||
|
'id': '3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'value': 'test_value_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_custom_field.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('log', 'custom-field', 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_log_custom_field_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_custom_field': {
|
||||||
|
'id': '3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'value': 'test_value_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_custom_field.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'id': '3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'value': 'test_value_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'custom-field', 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_custom_field_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_custom_field': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'id': '3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'value': 'test_value_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_custom_field.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'id': '3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'value': 'test_value_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'custom-field', 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,407 @@
|
|||||||
|
# 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_disk_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_disk_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_disk_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_disk_filter': {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu_memory_usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_11',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb_monitor': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_20,',
|
||||||
|
'netscan_vulnerability': 'test_value_21,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn_log_adm': 'enable',
|
||||||
|
'sslvpn_log_auth': 'enable',
|
||||||
|
'sslvpn_log_session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip_ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan_opt': 'enable',
|
||||||
|
'wireless_activity': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_disk_filter.fortios_log_disk(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu-memory-usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_11',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb-monitor': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_20,',
|
||||||
|
'netscan-vulnerability': 'test_value_21,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn-log-adm': 'enable',
|
||||||
|
'sslvpn-log-auth': 'enable',
|
||||||
|
'sslvpn-log-session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip-ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan-opt': 'enable',
|
||||||
|
'wireless-activity': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.disk', '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_disk_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_disk_filter': {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu_memory_usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_11',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb_monitor': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_20,',
|
||||||
|
'netscan_vulnerability': 'test_value_21,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn_log_adm': 'enable',
|
||||||
|
'sslvpn_log_auth': 'enable',
|
||||||
|
'sslvpn_log_session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip_ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan_opt': 'enable',
|
||||||
|
'wireless_activity': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_disk_filter.fortios_log_disk(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu-memory-usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_11',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb-monitor': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_20,',
|
||||||
|
'netscan-vulnerability': 'test_value_21,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn-log-adm': 'enable',
|
||||||
|
'sslvpn-log-auth': 'enable',
|
||||||
|
'sslvpn-log-session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip-ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan-opt': 'enable',
|
||||||
|
'wireless-activity': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.disk', '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_disk_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_disk_filter': {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu_memory_usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_11',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb_monitor': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_20,',
|
||||||
|
'netscan_vulnerability': 'test_value_21,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn_log_adm': 'enable',
|
||||||
|
'sslvpn_log_auth': 'enable',
|
||||||
|
'sslvpn_log_session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip_ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan_opt': 'enable',
|
||||||
|
'wireless_activity': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_disk_filter.fortios_log_disk(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu-memory-usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_11',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb-monitor': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_20,',
|
||||||
|
'netscan-vulnerability': 'test_value_21,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn-log-adm': 'enable',
|
||||||
|
'sslvpn-log-auth': 'enable',
|
||||||
|
'sslvpn-log-session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip-ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan-opt': 'enable',
|
||||||
|
'wireless-activity': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.disk', '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_disk_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_disk_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu_memory_usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_11',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb_monitor': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_20,',
|
||||||
|
'netscan_vulnerability': 'test_value_21,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn_log_adm': 'enable',
|
||||||
|
'sslvpn_log_auth': 'enable',
|
||||||
|
'sslvpn_log_session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip_ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan_opt': 'enable',
|
||||||
|
'wireless_activity': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_disk_filter.fortios_log_disk(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu-memory-usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_11',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb-monitor': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_20,',
|
||||||
|
'netscan-vulnerability': 'test_value_21,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn-log-adm': 'enable',
|
||||||
|
'sslvpn-log-auth': 'enable',
|
||||||
|
'sslvpn-log-session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip-ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan-opt': 'enable',
|
||||||
|
'wireless-activity': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.disk', '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,367 @@
|
|||||||
|
# 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_disk_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_disk_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_disk_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_disk_setting': {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'dlp_archive_quota': '4',
|
||||||
|
'full_final_warning_threshold': '5',
|
||||||
|
'full_first_warning_threshold': '6',
|
||||||
|
'full_second_warning_threshold': '7',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'log_quota': '9',
|
||||||
|
'max_log_file_size': '10',
|
||||||
|
'max_policy_packet_capture_size': '11',
|
||||||
|
'maximum_log_age': '12',
|
||||||
|
'report_quota': '13',
|
||||||
|
'roll_day': 'sunday',
|
||||||
|
'roll_schedule': 'daily',
|
||||||
|
'roll_time': 'test_value_16',
|
||||||
|
'source_ip': '84.230.14.17',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload': 'enable',
|
||||||
|
'upload_delete_files': 'enable',
|
||||||
|
'upload_destination': 'ftp-server',
|
||||||
|
'upload_ssl_conn': 'default',
|
||||||
|
'uploaddir': 'test_value_23',
|
||||||
|
'uploadip': 'test_value_24',
|
||||||
|
'uploadpass': 'test_value_25',
|
||||||
|
'uploadport': '26',
|
||||||
|
'uploadsched': 'disable',
|
||||||
|
'uploadtime': 'test_value_28',
|
||||||
|
'uploadtype': 'traffic',
|
||||||
|
'uploaduser': 'test_value_30'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_disk_setting.fortios_log_disk(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'dlp-archive-quota': '4',
|
||||||
|
'full-final-warning-threshold': '5',
|
||||||
|
'full-first-warning-threshold': '6',
|
||||||
|
'full-second-warning-threshold': '7',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'log-quota': '9',
|
||||||
|
'max-log-file-size': '10',
|
||||||
|
'max-policy-packet-capture-size': '11',
|
||||||
|
'maximum-log-age': '12',
|
||||||
|
'report-quota': '13',
|
||||||
|
'roll-day': 'sunday',
|
||||||
|
'roll-schedule': 'daily',
|
||||||
|
'roll-time': 'test_value_16',
|
||||||
|
'source-ip': '84.230.14.17',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload': 'enable',
|
||||||
|
'upload-delete-files': 'enable',
|
||||||
|
'upload-destination': 'ftp-server',
|
||||||
|
'upload-ssl-conn': 'default',
|
||||||
|
'uploaddir': 'test_value_23',
|
||||||
|
'uploadip': 'test_value_24',
|
||||||
|
'uploadpass': 'test_value_25',
|
||||||
|
'uploadport': '26',
|
||||||
|
'uploadsched': 'disable',
|
||||||
|
'uploadtime': 'test_value_28',
|
||||||
|
'uploadtype': 'traffic',
|
||||||
|
'uploaduser': 'test_value_30'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.disk', '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_disk_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_disk_setting': {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'dlp_archive_quota': '4',
|
||||||
|
'full_final_warning_threshold': '5',
|
||||||
|
'full_first_warning_threshold': '6',
|
||||||
|
'full_second_warning_threshold': '7',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'log_quota': '9',
|
||||||
|
'max_log_file_size': '10',
|
||||||
|
'max_policy_packet_capture_size': '11',
|
||||||
|
'maximum_log_age': '12',
|
||||||
|
'report_quota': '13',
|
||||||
|
'roll_day': 'sunday',
|
||||||
|
'roll_schedule': 'daily',
|
||||||
|
'roll_time': 'test_value_16',
|
||||||
|
'source_ip': '84.230.14.17',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload': 'enable',
|
||||||
|
'upload_delete_files': 'enable',
|
||||||
|
'upload_destination': 'ftp-server',
|
||||||
|
'upload_ssl_conn': 'default',
|
||||||
|
'uploaddir': 'test_value_23',
|
||||||
|
'uploadip': 'test_value_24',
|
||||||
|
'uploadpass': 'test_value_25',
|
||||||
|
'uploadport': '26',
|
||||||
|
'uploadsched': 'disable',
|
||||||
|
'uploadtime': 'test_value_28',
|
||||||
|
'uploadtype': 'traffic',
|
||||||
|
'uploaduser': 'test_value_30'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_disk_setting.fortios_log_disk(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'dlp-archive-quota': '4',
|
||||||
|
'full-final-warning-threshold': '5',
|
||||||
|
'full-first-warning-threshold': '6',
|
||||||
|
'full-second-warning-threshold': '7',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'log-quota': '9',
|
||||||
|
'max-log-file-size': '10',
|
||||||
|
'max-policy-packet-capture-size': '11',
|
||||||
|
'maximum-log-age': '12',
|
||||||
|
'report-quota': '13',
|
||||||
|
'roll-day': 'sunday',
|
||||||
|
'roll-schedule': 'daily',
|
||||||
|
'roll-time': 'test_value_16',
|
||||||
|
'source-ip': '84.230.14.17',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload': 'enable',
|
||||||
|
'upload-delete-files': 'enable',
|
||||||
|
'upload-destination': 'ftp-server',
|
||||||
|
'upload-ssl-conn': 'default',
|
||||||
|
'uploaddir': 'test_value_23',
|
||||||
|
'uploadip': 'test_value_24',
|
||||||
|
'uploadpass': 'test_value_25',
|
||||||
|
'uploadport': '26',
|
||||||
|
'uploadsched': 'disable',
|
||||||
|
'uploadtime': 'test_value_28',
|
||||||
|
'uploadtype': 'traffic',
|
||||||
|
'uploaduser': 'test_value_30'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.disk', '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_disk_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_disk_setting': {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'dlp_archive_quota': '4',
|
||||||
|
'full_final_warning_threshold': '5',
|
||||||
|
'full_first_warning_threshold': '6',
|
||||||
|
'full_second_warning_threshold': '7',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'log_quota': '9',
|
||||||
|
'max_log_file_size': '10',
|
||||||
|
'max_policy_packet_capture_size': '11',
|
||||||
|
'maximum_log_age': '12',
|
||||||
|
'report_quota': '13',
|
||||||
|
'roll_day': 'sunday',
|
||||||
|
'roll_schedule': 'daily',
|
||||||
|
'roll_time': 'test_value_16',
|
||||||
|
'source_ip': '84.230.14.17',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload': 'enable',
|
||||||
|
'upload_delete_files': 'enable',
|
||||||
|
'upload_destination': 'ftp-server',
|
||||||
|
'upload_ssl_conn': 'default',
|
||||||
|
'uploaddir': 'test_value_23',
|
||||||
|
'uploadip': 'test_value_24',
|
||||||
|
'uploadpass': 'test_value_25',
|
||||||
|
'uploadport': '26',
|
||||||
|
'uploadsched': 'disable',
|
||||||
|
'uploadtime': 'test_value_28',
|
||||||
|
'uploadtype': 'traffic',
|
||||||
|
'uploaduser': 'test_value_30'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_disk_setting.fortios_log_disk(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'dlp-archive-quota': '4',
|
||||||
|
'full-final-warning-threshold': '5',
|
||||||
|
'full-first-warning-threshold': '6',
|
||||||
|
'full-second-warning-threshold': '7',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'log-quota': '9',
|
||||||
|
'max-log-file-size': '10',
|
||||||
|
'max-policy-packet-capture-size': '11',
|
||||||
|
'maximum-log-age': '12',
|
||||||
|
'report-quota': '13',
|
||||||
|
'roll-day': 'sunday',
|
||||||
|
'roll-schedule': 'daily',
|
||||||
|
'roll-time': 'test_value_16',
|
||||||
|
'source-ip': '84.230.14.17',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload': 'enable',
|
||||||
|
'upload-delete-files': 'enable',
|
||||||
|
'upload-destination': 'ftp-server',
|
||||||
|
'upload-ssl-conn': 'default',
|
||||||
|
'uploaddir': 'test_value_23',
|
||||||
|
'uploadip': 'test_value_24',
|
||||||
|
'uploadpass': 'test_value_25',
|
||||||
|
'uploadport': '26',
|
||||||
|
'uploadsched': 'disable',
|
||||||
|
'uploadtime': 'test_value_28',
|
||||||
|
'uploadtype': 'traffic',
|
||||||
|
'uploaduser': 'test_value_30'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.disk', '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_disk_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_disk_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'dlp_archive_quota': '4',
|
||||||
|
'full_final_warning_threshold': '5',
|
||||||
|
'full_first_warning_threshold': '6',
|
||||||
|
'full_second_warning_threshold': '7',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'log_quota': '9',
|
||||||
|
'max_log_file_size': '10',
|
||||||
|
'max_policy_packet_capture_size': '11',
|
||||||
|
'maximum_log_age': '12',
|
||||||
|
'report_quota': '13',
|
||||||
|
'roll_day': 'sunday',
|
||||||
|
'roll_schedule': 'daily',
|
||||||
|
'roll_time': 'test_value_16',
|
||||||
|
'source_ip': '84.230.14.17',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload': 'enable',
|
||||||
|
'upload_delete_files': 'enable',
|
||||||
|
'upload_destination': 'ftp-server',
|
||||||
|
'upload_ssl_conn': 'default',
|
||||||
|
'uploaddir': 'test_value_23',
|
||||||
|
'uploadip': 'test_value_24',
|
||||||
|
'uploadpass': 'test_value_25',
|
||||||
|
'uploadport': '26',
|
||||||
|
'uploadsched': 'disable',
|
||||||
|
'uploadtime': 'test_value_28',
|
||||||
|
'uploadtype': 'traffic',
|
||||||
|
'uploaduser': 'test_value_30'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_disk_setting.fortios_log_disk(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'diskfull': 'overwrite',
|
||||||
|
'dlp-archive-quota': '4',
|
||||||
|
'full-final-warning-threshold': '5',
|
||||||
|
'full-first-warning-threshold': '6',
|
||||||
|
'full-second-warning-threshold': '7',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'log-quota': '9',
|
||||||
|
'max-log-file-size': '10',
|
||||||
|
'max-policy-packet-capture-size': '11',
|
||||||
|
'maximum-log-age': '12',
|
||||||
|
'report-quota': '13',
|
||||||
|
'roll-day': 'sunday',
|
||||||
|
'roll-schedule': 'daily',
|
||||||
|
'roll-time': 'test_value_16',
|
||||||
|
'source-ip': '84.230.14.17',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload': 'enable',
|
||||||
|
'upload-delete-files': 'enable',
|
||||||
|
'upload-destination': 'ftp-server',
|
||||||
|
'upload-ssl-conn': 'default',
|
||||||
|
'uploaddir': 'test_value_23',
|
||||||
|
'uploadip': 'test_value_24',
|
||||||
|
'uploadpass': 'test_value_25',
|
||||||
|
'uploadport': '26',
|
||||||
|
'uploadsched': 'disable',
|
||||||
|
'uploadtime': 'test_value_28',
|
||||||
|
'uploadtype': 'traffic',
|
||||||
|
'uploaduser': 'test_value_30'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.disk', '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,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_eventfilter
|
||||||
|
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_eventfilter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_eventfilter_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_eventfilter': {
|
||||||
|
'compliance_check': 'enable',
|
||||||
|
'endpoint': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'router': 'enable',
|
||||||
|
'security_rating': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'user': 'enable',
|
||||||
|
'vpn': 'enable',
|
||||||
|
'wan_opt': 'enable',
|
||||||
|
'wireless_activity': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_eventfilter.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'compliance-check': 'enable',
|
||||||
|
'endpoint': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'router': 'enable',
|
||||||
|
'security-rating': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'user': 'enable',
|
||||||
|
'vpn': 'enable',
|
||||||
|
'wan-opt': 'enable',
|
||||||
|
'wireless-activity': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'eventfilter', 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_eventfilter_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_eventfilter': {
|
||||||
|
'compliance_check': 'enable',
|
||||||
|
'endpoint': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'router': 'enable',
|
||||||
|
'security_rating': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'user': 'enable',
|
||||||
|
'vpn': 'enable',
|
||||||
|
'wan_opt': 'enable',
|
||||||
|
'wireless_activity': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_eventfilter.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'compliance-check': 'enable',
|
||||||
|
'endpoint': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'router': 'enable',
|
||||||
|
'security-rating': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'user': 'enable',
|
||||||
|
'vpn': 'enable',
|
||||||
|
'wan-opt': 'enable',
|
||||||
|
'wireless-activity': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'eventfilter', 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_eventfilter_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_eventfilter': {
|
||||||
|
'compliance_check': 'enable',
|
||||||
|
'endpoint': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'router': 'enable',
|
||||||
|
'security_rating': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'user': 'enable',
|
||||||
|
'vpn': 'enable',
|
||||||
|
'wan_opt': 'enable',
|
||||||
|
'wireless_activity': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_eventfilter.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'compliance-check': 'enable',
|
||||||
|
'endpoint': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'router': 'enable',
|
||||||
|
'security-rating': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'user': 'enable',
|
||||||
|
'vpn': 'enable',
|
||||||
|
'wan-opt': 'enable',
|
||||||
|
'wireless-activity': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'eventfilter', 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_eventfilter_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_eventfilter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'compliance_check': 'enable',
|
||||||
|
'endpoint': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'router': 'enable',
|
||||||
|
'security_rating': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'user': 'enable',
|
||||||
|
'vpn': 'enable',
|
||||||
|
'wan_opt': 'enable',
|
||||||
|
'wireless_activity': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_eventfilter.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'compliance-check': 'enable',
|
||||||
|
'endpoint': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'router': 'enable',
|
||||||
|
'security-rating': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'user': 'enable',
|
||||||
|
'vpn': 'enable',
|
||||||
|
'wan-opt': 'enable',
|
||||||
|
'wireless-activity': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'eventfilter', 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,263 @@
|
|||||||
|
# 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_fortianalyzer2_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_fortianalyzer2_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_fortianalyzer2_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_fortianalyzer2_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer2_filter.fortios_log_fortianalyzer2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer2', '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_fortianalyzer2_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_fortianalyzer2_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer2_filter.fortios_log_fortianalyzer2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer2', '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_fortianalyzer2_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_fortianalyzer2_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer2_filter.fortios_log_fortianalyzer2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer2', '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_fortianalyzer2_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_fortianalyzer2_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer2_filter.fortios_log_fortianalyzer2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer2', '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,295 @@
|
|||||||
|
# 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_fortianalyzer2_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_fortianalyzer2_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_fortianalyzer2_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_fortianalyzer2_setting': {
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source_ip': '84.230.14.15',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_18',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer2_setting.fortios_log_fortianalyzer2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source-ip': '84.230.14.15',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_18',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer2', '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_fortianalyzer2_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_fortianalyzer2_setting': {
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source_ip': '84.230.14.15',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_18',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer2_setting.fortios_log_fortianalyzer2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source-ip': '84.230.14.15',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_18',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer2', '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_fortianalyzer2_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_fortianalyzer2_setting': {
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source_ip': '84.230.14.15',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_18',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer2_setting.fortios_log_fortianalyzer2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source-ip': '84.230.14.15',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_18',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer2', '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_fortianalyzer2_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_fortianalyzer2_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source_ip': '84.230.14.15',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_18',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer2_setting.fortios_log_fortianalyzer2(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source-ip': '84.230.14.15',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_18',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer2', '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,263 @@
|
|||||||
|
# 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_fortianalyzer3_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_fortianalyzer3_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_fortianalyzer3_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_fortianalyzer3_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer3_filter.fortios_log_fortianalyzer3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer3', '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_fortianalyzer3_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_fortianalyzer3_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer3_filter.fortios_log_fortianalyzer3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer3', '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_fortianalyzer3_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_fortianalyzer3_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer3_filter.fortios_log_fortianalyzer3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer3', '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_fortianalyzer3_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_fortianalyzer3_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer3_filter.fortios_log_fortianalyzer3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer3', '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,295 @@
|
|||||||
|
# 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_fortianalyzer3_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_fortianalyzer3_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_fortianalyzer3_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_fortianalyzer3_setting': {
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source_ip': '84.230.14.15',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_18',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer3_setting.fortios_log_fortianalyzer3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source-ip': '84.230.14.15',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_18',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer3', '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_fortianalyzer3_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_fortianalyzer3_setting': {
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source_ip': '84.230.14.15',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_18',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer3_setting.fortios_log_fortianalyzer3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source-ip': '84.230.14.15',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_18',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer3', '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_fortianalyzer3_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_fortianalyzer3_setting': {
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source_ip': '84.230.14.15',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_18',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer3_setting.fortios_log_fortianalyzer3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source-ip': '84.230.14.15',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_18',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer3', '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_fortianalyzer3_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_fortianalyzer3_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source_ip': '84.230.14.15',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_18',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer3_setting.fortios_log_fortianalyzer3(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source-ip': '84.230.14.15',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_18',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer3', '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,263 @@
|
|||||||
|
# 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_fortianalyzer_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_fortianalyzer_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_fortianalyzer_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_fortianalyzer_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_filter.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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_fortianalyzer_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_fortianalyzer_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_filter.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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_fortianalyzer_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_fortianalyzer_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_filter.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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_fortianalyzer_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_fortianalyzer_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_filter.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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,263 @@
|
|||||||
|
# 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_fortianalyzer_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_fortianalyzer_override_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_fortianalyzer_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_fortianalyzer_override_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_override_filter.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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_fortianalyzer_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_fortianalyzer_override_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_override_filter.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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_fortianalyzer_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_fortianalyzer_override_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_override_filter.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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_fortianalyzer_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_fortianalyzer_override_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_override_filter.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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,311 @@
|
|||||||
|
# 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_fortianalyzer_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_fortianalyzer_override_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_fortianalyzer_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_fortianalyzer_override_setting': {
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'override': 'enable',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.15',
|
||||||
|
'source_ip': '84.230.14.16',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_19',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_22',
|
||||||
|
'use_management_vdom': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_override_setting.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'override': 'enable',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.15',
|
||||||
|
'source-ip': '84.230.14.16',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_19',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_22',
|
||||||
|
'use-management-vdom': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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_fortianalyzer_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_fortianalyzer_override_setting': {
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'override': 'enable',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.15',
|
||||||
|
'source_ip': '84.230.14.16',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_19',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_22',
|
||||||
|
'use_management_vdom': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_override_setting.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'override': 'enable',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.15',
|
||||||
|
'source-ip': '84.230.14.16',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_19',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_22',
|
||||||
|
'use-management-vdom': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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_fortianalyzer_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_fortianalyzer_override_setting': {
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'override': 'enable',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.15',
|
||||||
|
'source_ip': '84.230.14.16',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_19',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_22',
|
||||||
|
'use_management_vdom': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_override_setting.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'override': 'enable',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.15',
|
||||||
|
'source-ip': '84.230.14.16',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_19',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_22',
|
||||||
|
'use-management-vdom': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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_fortianalyzer_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_fortianalyzer_override_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'override': 'enable',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.15',
|
||||||
|
'source_ip': '84.230.14.16',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_19',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_22',
|
||||||
|
'use_management_vdom': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_override_setting.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'override': 'enable',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.15',
|
||||||
|
'source-ip': '84.230.14.16',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_19',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_22',
|
||||||
|
'use-management-vdom': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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,295 @@
|
|||||||
|
# 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_fortianalyzer_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_fortianalyzer_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_fortianalyzer_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_fortianalyzer_setting': {
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source_ip': '84.230.14.15',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_18',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_setting.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source-ip': '84.230.14.15',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_18',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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_fortianalyzer_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_fortianalyzer_setting': {
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source_ip': '84.230.14.15',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_18',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_setting.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source-ip': '84.230.14.15',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_18',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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_fortianalyzer_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_fortianalyzer_setting': {
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source_ip': '84.230.14.15',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_18',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_setting.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source-ip': '84.230.14.15',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_18',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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_fortianalyzer_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_fortianalyzer_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'__change_ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn_timeout': '5',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'faz_type': '7',
|
||||||
|
'hmac_algorithm': 'sha256',
|
||||||
|
'ips_archive': 'enable',
|
||||||
|
'mgmt_name': 'test_value_10',
|
||||||
|
'monitor_failure_retry_period': '11',
|
||||||
|
'monitor_keepalive_period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source_ip': '84.230.14.15',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_18',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortianalyzer_setting.fortios_log_fortianalyzer(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'--change-ip': '3',
|
||||||
|
'certificate': 'test_value_4',
|
||||||
|
'conn-timeout': '5',
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'faz-type': '7',
|
||||||
|
'hmac-algorithm': 'sha256',
|
||||||
|
'ips-archive': 'enable',
|
||||||
|
'mgmt-name': 'test_value_10',
|
||||||
|
'monitor-failure-retry-period': '11',
|
||||||
|
'monitor-keepalive-period': '12',
|
||||||
|
'reliable': 'enable',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'source-ip': '84.230.14.15',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_18',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortianalyzer', '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,263 @@
|
|||||||
|
# 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_fortiguard_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_fortiguard_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_fortiguard_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_fortiguard_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_filter.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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_fortiguard_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_fortiguard_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_filter.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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_fortiguard_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_fortiguard_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_filter.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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_fortiguard_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_fortiguard_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_filter.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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,263 @@
|
|||||||
|
# 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_fortiguard_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_fortiguard_override_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_fortiguard_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_fortiguard_override_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_override_filter.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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_fortiguard_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_fortiguard_override_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_override_filter.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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_fortiguard_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_fortiguard_override_filter': {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_override_filter.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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_fortiguard_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_fortiguard_override_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp_archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_12,',
|
||||||
|
'netscan_vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_override_filter.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'dlp-archive': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'filter': 'test_value_6',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_12,',
|
||||||
|
'netscan-vulnerability': 'test_value_13,',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'voip': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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,191 @@
|
|||||||
|
# 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_fortiguard_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_fortiguard_override_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_fortiguard_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_fortiguard_override_setting': {
|
||||||
|
'override': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_5',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_override_setting.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'override': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_5',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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_fortiguard_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_fortiguard_override_setting': {
|
||||||
|
'override': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_5',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_override_setting.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'override': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_5',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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_fortiguard_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_fortiguard_override_setting': {
|
||||||
|
'override': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_5',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_override_setting.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'override': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_5',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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_fortiguard_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_fortiguard_override_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'override': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_5',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_override_setting.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'override': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_5',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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,207 @@
|
|||||||
|
# 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_fortiguard_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_fortiguard_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_fortiguard_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_fortiguard_setting': {
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'source_ip': '84.230.14.4',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_7',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_setting.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'source-ip': '84.230.14.4',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_7',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_10'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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_fortiguard_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_fortiguard_setting': {
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'source_ip': '84.230.14.4',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_7',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_setting.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'source-ip': '84.230.14.4',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_7',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_10'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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_fortiguard_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_fortiguard_setting': {
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'source_ip': '84.230.14.4',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_7',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_setting.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'source-ip': '84.230.14.4',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_7',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_10'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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_fortiguard_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_fortiguard_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'enc_algorithm': 'high-medium',
|
||||||
|
'source_ip': '84.230.14.4',
|
||||||
|
'ssl_min_proto_version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload_day': 'test_value_7',
|
||||||
|
'upload_interval': 'daily',
|
||||||
|
'upload_option': 'store-and-upload',
|
||||||
|
'upload_time': 'test_value_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_fortiguard_setting.fortios_log_fortiguard(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'enc-algorithm': 'high-medium',
|
||||||
|
'source-ip': '84.230.14.4',
|
||||||
|
'ssl-min-proto-version': 'default',
|
||||||
|
'status': 'enable',
|
||||||
|
'upload-day': 'test_value_7',
|
||||||
|
'upload-interval': 'daily',
|
||||||
|
'upload-option': 'store-and-upload',
|
||||||
|
'upload-time': 'test_value_10'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.fortiguard', '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,167 @@
|
|||||||
|
# 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_gui_display
|
||||||
|
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_gui_display.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_gui_display_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_gui_display': {
|
||||||
|
'fortiview_unscanned_apps': 'enable',
|
||||||
|
'resolve_apps': 'enable',
|
||||||
|
'resolve_hosts': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_gui_display.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'fortiview-unscanned-apps': 'enable',
|
||||||
|
'resolve-apps': 'enable',
|
||||||
|
'resolve-hosts': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'gui-display', 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_gui_display_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_gui_display': {
|
||||||
|
'fortiview_unscanned_apps': 'enable',
|
||||||
|
'resolve_apps': 'enable',
|
||||||
|
'resolve_hosts': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_gui_display.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'fortiview-unscanned-apps': 'enable',
|
||||||
|
'resolve-apps': 'enable',
|
||||||
|
'resolve-hosts': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'gui-display', 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_gui_display_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_gui_display': {
|
||||||
|
'fortiview_unscanned_apps': 'enable',
|
||||||
|
'resolve_apps': 'enable',
|
||||||
|
'resolve_hosts': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_gui_display.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'fortiview-unscanned-apps': 'enable',
|
||||||
|
'resolve-apps': 'enable',
|
||||||
|
'resolve-hosts': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'gui-display', 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_gui_display_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_gui_display': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'fortiview_unscanned_apps': 'enable',
|
||||||
|
'resolve_apps': 'enable',
|
||||||
|
'resolve_hosts': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_gui_display.fortios_log(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'fortiview-unscanned-apps': 'enable',
|
||||||
|
'resolve-apps': 'enable',
|
||||||
|
'resolve-hosts': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log', 'gui-display', 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,399 @@
|
|||||||
|
# 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_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_memory_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_memory_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_memory_filter': {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu_memory_usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_10',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb_monitor': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_19,',
|
||||||
|
'netscan_vulnerability': 'test_value_20,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn_log_adm': 'enable',
|
||||||
|
'sslvpn_log_auth': 'enable',
|
||||||
|
'sslvpn_log_session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip_ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan_opt': 'enable',
|
||||||
|
'wireless_activity': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_memory_filter.fortios_log_memory(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu-memory-usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_10',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb-monitor': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_19,',
|
||||||
|
'netscan-vulnerability': 'test_value_20,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn-log-adm': 'enable',
|
||||||
|
'sslvpn-log-auth': 'enable',
|
||||||
|
'sslvpn-log-session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip-ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan-opt': 'enable',
|
||||||
|
'wireless-activity': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.memory', '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_memory_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_memory_filter': {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu_memory_usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_10',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb_monitor': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_19,',
|
||||||
|
'netscan_vulnerability': 'test_value_20,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn_log_adm': 'enable',
|
||||||
|
'sslvpn_log_auth': 'enable',
|
||||||
|
'sslvpn_log_session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip_ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan_opt': 'enable',
|
||||||
|
'wireless_activity': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_memory_filter.fortios_log_memory(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu-memory-usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_10',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb-monitor': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_19,',
|
||||||
|
'netscan-vulnerability': 'test_value_20,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn-log-adm': 'enable',
|
||||||
|
'sslvpn-log-auth': 'enable',
|
||||||
|
'sslvpn-log-session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip-ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan-opt': 'enable',
|
||||||
|
'wireless-activity': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.memory', '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_memory_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_memory_filter': {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu_memory_usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_10',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb_monitor': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_19,',
|
||||||
|
'netscan_vulnerability': 'test_value_20,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn_log_adm': 'enable',
|
||||||
|
'sslvpn_log_auth': 'enable',
|
||||||
|
'sslvpn_log_session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip_ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan_opt': 'enable',
|
||||||
|
'wireless_activity': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_memory_filter.fortios_log_memory(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu-memory-usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_10',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb-monitor': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_19,',
|
||||||
|
'netscan-vulnerability': 'test_value_20,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn-log-adm': 'enable',
|
||||||
|
'sslvpn-log-auth': 'enable',
|
||||||
|
'sslvpn-log-session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip-ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan-opt': 'enable',
|
||||||
|
'wireless-activity': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.memory', '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_memory_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_memory_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu_memory_usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_10',
|
||||||
|
'filter_type': 'include',
|
||||||
|
'forward_traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb_monitor': 'enable',
|
||||||
|
'local_traffic': 'enable',
|
||||||
|
'multicast_traffic': 'enable',
|
||||||
|
'netscan_discovery': 'test_value_19,',
|
||||||
|
'netscan_vulnerability': 'test_value_20,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer_traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn_log_adm': 'enable',
|
||||||
|
'sslvpn_log_auth': 'enable',
|
||||||
|
'sslvpn_log_session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip_ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan_opt': 'enable',
|
||||||
|
'wireless_activity': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_log_memory_filter.fortios_log_memory(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'admin': 'enable',
|
||||||
|
'anomaly': 'enable',
|
||||||
|
'auth': 'enable',
|
||||||
|
'cpu-memory-usage': 'enable',
|
||||||
|
'dhcp': 'enable',
|
||||||
|
'dns': 'enable',
|
||||||
|
'event': 'enable',
|
||||||
|
'filter': 'test_value_10',
|
||||||
|
'filter-type': 'include',
|
||||||
|
'forward-traffic': 'enable',
|
||||||
|
'gtp': 'enable',
|
||||||
|
'ha': 'enable',
|
||||||
|
'ipsec': 'enable',
|
||||||
|
'ldb-monitor': 'enable',
|
||||||
|
'local-traffic': 'enable',
|
||||||
|
'multicast-traffic': 'enable',
|
||||||
|
'netscan-discovery': 'test_value_19,',
|
||||||
|
'netscan-vulnerability': 'test_value_20,',
|
||||||
|
'pattern': 'enable',
|
||||||
|
'ppp': 'enable',
|
||||||
|
'radius': 'enable',
|
||||||
|
'severity': 'emergency',
|
||||||
|
'sniffer-traffic': 'enable',
|
||||||
|
'ssh': 'enable',
|
||||||
|
'sslvpn-log-adm': 'enable',
|
||||||
|
'sslvpn-log-auth': 'enable',
|
||||||
|
'sslvpn-log-session': 'enable',
|
||||||
|
'system': 'enable',
|
||||||
|
'vip-ssl': 'enable',
|
||||||
|
'voip': 'enable',
|
||||||
|
'wan-opt': 'enable',
|
||||||
|
'wireless-activity': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('log.memory', '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
|
Loading…
Reference in New Issue