mirror of https://github.com/ansible/ansible.git
FortiOS modules for 2.9 - 1 (#60469)
* FortiOS modules for 2.9 - 1 * Fix empty choices and avoid E337,E338 warnings * Ansible comments on version_added and ignore.txt only on this PR files * Add version_added also for state attribute * Avoid null choices on dlp_sensor * Change required flag according to argspecpull/60490/head
parent
5923a64b20
commit
4cae96109b
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,151 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_antivirus_heuristic
|
||||||
|
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_antivirus_heuristic.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_antivirus_heuristic_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',
|
||||||
|
'antivirus_heuristic': {
|
||||||
|
'mode': 'pass'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_heuristic.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'mode': 'pass'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', 'heuristic', 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_antivirus_heuristic_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',
|
||||||
|
'antivirus_heuristic': {
|
||||||
|
'mode': 'pass'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_heuristic.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'mode': 'pass'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', 'heuristic', 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_antivirus_heuristic_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',
|
||||||
|
'antivirus_heuristic': {
|
||||||
|
'mode': 'pass'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_heuristic.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'mode': 'pass'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', 'heuristic', 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_antivirus_heuristic_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',
|
||||||
|
'antivirus_heuristic': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'mode': 'pass'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_heuristic.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'mode': 'pass'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', 'heuristic', 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,339 @@
|
|||||||
|
# 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_antivirus_profile
|
||||||
|
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_antivirus_profile.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_antivirus_profile_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',
|
||||||
|
'antivirus_profile': {
|
||||||
|
'analytics_bl_filetype': '3',
|
||||||
|
'analytics_db': 'disable',
|
||||||
|
'analytics_max_upload': '5',
|
||||||
|
'analytics_wl_filetype': '6',
|
||||||
|
'av_block_log': 'enable',
|
||||||
|
'av_virus_log': 'enable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'ftgd_analytics': 'disable',
|
||||||
|
'inspection_mode': 'proxy',
|
||||||
|
'mobile_malware_db': 'disable',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'replacemsg_group': 'test_value_15',
|
||||||
|
'scan_mode': 'quick',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_profile.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'analytics-bl-filetype': '3',
|
||||||
|
'analytics-db': 'disable',
|
||||||
|
'analytics-max-upload': '5',
|
||||||
|
'analytics-wl-filetype': '6',
|
||||||
|
'av-block-log': 'enable',
|
||||||
|
'av-virus-log': 'enable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'ftgd-analytics': 'disable',
|
||||||
|
'inspection-mode': 'proxy',
|
||||||
|
'mobile-malware-db': 'disable',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'replacemsg-group': 'test_value_15',
|
||||||
|
'scan-mode': 'quick',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', 'profile', 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_antivirus_profile_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',
|
||||||
|
'antivirus_profile': {
|
||||||
|
'analytics_bl_filetype': '3',
|
||||||
|
'analytics_db': 'disable',
|
||||||
|
'analytics_max_upload': '5',
|
||||||
|
'analytics_wl_filetype': '6',
|
||||||
|
'av_block_log': 'enable',
|
||||||
|
'av_virus_log': 'enable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'ftgd_analytics': 'disable',
|
||||||
|
'inspection_mode': 'proxy',
|
||||||
|
'mobile_malware_db': 'disable',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'replacemsg_group': 'test_value_15',
|
||||||
|
'scan_mode': 'quick',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_profile.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'analytics-bl-filetype': '3',
|
||||||
|
'analytics-db': 'disable',
|
||||||
|
'analytics-max-upload': '5',
|
||||||
|
'analytics-wl-filetype': '6',
|
||||||
|
'av-block-log': 'enable',
|
||||||
|
'av-virus-log': 'enable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'ftgd-analytics': 'disable',
|
||||||
|
'inspection-mode': 'proxy',
|
||||||
|
'mobile-malware-db': 'disable',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'replacemsg-group': 'test_value_15',
|
||||||
|
'scan-mode': 'quick',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', 'profile', 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_antivirus_profile_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',
|
||||||
|
'antivirus_profile': {
|
||||||
|
'analytics_bl_filetype': '3',
|
||||||
|
'analytics_db': 'disable',
|
||||||
|
'analytics_max_upload': '5',
|
||||||
|
'analytics_wl_filetype': '6',
|
||||||
|
'av_block_log': 'enable',
|
||||||
|
'av_virus_log': 'enable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'ftgd_analytics': 'disable',
|
||||||
|
'inspection_mode': 'proxy',
|
||||||
|
'mobile_malware_db': 'disable',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'replacemsg_group': 'test_value_15',
|
||||||
|
'scan_mode': 'quick',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_profile.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('antivirus', 'profile', 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_antivirus_profile_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',
|
||||||
|
'antivirus_profile': {
|
||||||
|
'analytics_bl_filetype': '3',
|
||||||
|
'analytics_db': 'disable',
|
||||||
|
'analytics_max_upload': '5',
|
||||||
|
'analytics_wl_filetype': '6',
|
||||||
|
'av_block_log': 'enable',
|
||||||
|
'av_virus_log': 'enable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'ftgd_analytics': 'disable',
|
||||||
|
'inspection_mode': 'proxy',
|
||||||
|
'mobile_malware_db': 'disable',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'replacemsg_group': 'test_value_15',
|
||||||
|
'scan_mode': 'quick',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_profile.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('antivirus', 'profile', 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_antivirus_profile_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',
|
||||||
|
'antivirus_profile': {
|
||||||
|
'analytics_bl_filetype': '3',
|
||||||
|
'analytics_db': 'disable',
|
||||||
|
'analytics_max_upload': '5',
|
||||||
|
'analytics_wl_filetype': '6',
|
||||||
|
'av_block_log': 'enable',
|
||||||
|
'av_virus_log': 'enable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'ftgd_analytics': 'disable',
|
||||||
|
'inspection_mode': 'proxy',
|
||||||
|
'mobile_malware_db': 'disable',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'replacemsg_group': 'test_value_15',
|
||||||
|
'scan_mode': 'quick',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_profile.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'analytics-bl-filetype': '3',
|
||||||
|
'analytics-db': 'disable',
|
||||||
|
'analytics-max-upload': '5',
|
||||||
|
'analytics-wl-filetype': '6',
|
||||||
|
'av-block-log': 'enable',
|
||||||
|
'av-virus-log': 'enable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'ftgd-analytics': 'disable',
|
||||||
|
'inspection-mode': 'proxy',
|
||||||
|
'mobile-malware-db': 'disable',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'replacemsg-group': 'test_value_15',
|
||||||
|
'scan-mode': 'quick',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', 'profile', 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_antivirus_profile_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',
|
||||||
|
'antivirus_profile': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'analytics_bl_filetype': '3',
|
||||||
|
'analytics_db': 'disable',
|
||||||
|
'analytics_max_upload': '5',
|
||||||
|
'analytics_wl_filetype': '6',
|
||||||
|
'av_block_log': 'enable',
|
||||||
|
'av_virus_log': 'enable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'ftgd_analytics': 'disable',
|
||||||
|
'inspection_mode': 'proxy',
|
||||||
|
'mobile_malware_db': 'disable',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'replacemsg_group': 'test_value_15',
|
||||||
|
'scan_mode': 'quick',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_profile.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'analytics-bl-filetype': '3',
|
||||||
|
'analytics-db': 'disable',
|
||||||
|
'analytics-max-upload': '5',
|
||||||
|
'analytics-wl-filetype': '6',
|
||||||
|
'av-block-log': 'enable',
|
||||||
|
'av-virus-log': 'enable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'ftgd-analytics': 'disable',
|
||||||
|
'inspection-mode': 'proxy',
|
||||||
|
'mobile-malware-db': 'disable',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'replacemsg-group': 'test_value_15',
|
||||||
|
'scan-mode': 'quick',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', 'profile', 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_antivirus_quarantine
|
||||||
|
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_antivirus_quarantine.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_antivirus_quarantine_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',
|
||||||
|
'antivirus_quarantine': {
|
||||||
|
'agelimit': '3',
|
||||||
|
'destination': 'NULL',
|
||||||
|
'drop_blocked': 'imap',
|
||||||
|
'drop_heuristic': 'imap',
|
||||||
|
'drop_infected': 'imap',
|
||||||
|
'lowspace': 'drop-new',
|
||||||
|
'maxfilesize': '9',
|
||||||
|
'quarantine_quota': '10',
|
||||||
|
'store_blocked': 'imap',
|
||||||
|
'store_heuristic': 'imap',
|
||||||
|
'store_infected': 'imap'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_quarantine.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'agelimit': '3',
|
||||||
|
'destination': 'NULL',
|
||||||
|
'drop-blocked': 'imap',
|
||||||
|
'drop-heuristic': 'imap',
|
||||||
|
'drop-infected': 'imap',
|
||||||
|
'lowspace': 'drop-new',
|
||||||
|
'maxfilesize': '9',
|
||||||
|
'quarantine-quota': '10',
|
||||||
|
'store-blocked': 'imap',
|
||||||
|
'store-heuristic': 'imap',
|
||||||
|
'store-infected': 'imap'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', 'quarantine', 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_antivirus_quarantine_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',
|
||||||
|
'antivirus_quarantine': {
|
||||||
|
'agelimit': '3',
|
||||||
|
'destination': 'NULL',
|
||||||
|
'drop_blocked': 'imap',
|
||||||
|
'drop_heuristic': 'imap',
|
||||||
|
'drop_infected': 'imap',
|
||||||
|
'lowspace': 'drop-new',
|
||||||
|
'maxfilesize': '9',
|
||||||
|
'quarantine_quota': '10',
|
||||||
|
'store_blocked': 'imap',
|
||||||
|
'store_heuristic': 'imap',
|
||||||
|
'store_infected': 'imap'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_quarantine.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'agelimit': '3',
|
||||||
|
'destination': 'NULL',
|
||||||
|
'drop-blocked': 'imap',
|
||||||
|
'drop-heuristic': 'imap',
|
||||||
|
'drop-infected': 'imap',
|
||||||
|
'lowspace': 'drop-new',
|
||||||
|
'maxfilesize': '9',
|
||||||
|
'quarantine-quota': '10',
|
||||||
|
'store-blocked': 'imap',
|
||||||
|
'store-heuristic': 'imap',
|
||||||
|
'store-infected': 'imap'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', 'quarantine', 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_antivirus_quarantine_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',
|
||||||
|
'antivirus_quarantine': {
|
||||||
|
'agelimit': '3',
|
||||||
|
'destination': 'NULL',
|
||||||
|
'drop_blocked': 'imap',
|
||||||
|
'drop_heuristic': 'imap',
|
||||||
|
'drop_infected': 'imap',
|
||||||
|
'lowspace': 'drop-new',
|
||||||
|
'maxfilesize': '9',
|
||||||
|
'quarantine_quota': '10',
|
||||||
|
'store_blocked': 'imap',
|
||||||
|
'store_heuristic': 'imap',
|
||||||
|
'store_infected': 'imap'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_quarantine.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'agelimit': '3',
|
||||||
|
'destination': 'NULL',
|
||||||
|
'drop-blocked': 'imap',
|
||||||
|
'drop-heuristic': 'imap',
|
||||||
|
'drop-infected': 'imap',
|
||||||
|
'lowspace': 'drop-new',
|
||||||
|
'maxfilesize': '9',
|
||||||
|
'quarantine-quota': '10',
|
||||||
|
'store-blocked': 'imap',
|
||||||
|
'store-heuristic': 'imap',
|
||||||
|
'store-infected': 'imap'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', 'quarantine', 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_antivirus_quarantine_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',
|
||||||
|
'antivirus_quarantine': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'agelimit': '3',
|
||||||
|
'destination': 'NULL',
|
||||||
|
'drop_blocked': 'imap',
|
||||||
|
'drop_heuristic': 'imap',
|
||||||
|
'drop_infected': 'imap',
|
||||||
|
'lowspace': 'drop-new',
|
||||||
|
'maxfilesize': '9',
|
||||||
|
'quarantine_quota': '10',
|
||||||
|
'store_blocked': 'imap',
|
||||||
|
'store_heuristic': 'imap',
|
||||||
|
'store_infected': 'imap'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_quarantine.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'agelimit': '3',
|
||||||
|
'destination': 'NULL',
|
||||||
|
'drop-blocked': 'imap',
|
||||||
|
'drop-heuristic': 'imap',
|
||||||
|
'drop-infected': 'imap',
|
||||||
|
'lowspace': 'drop-new',
|
||||||
|
'maxfilesize': '9',
|
||||||
|
'quarantine-quota': '10',
|
||||||
|
'store-blocked': 'imap',
|
||||||
|
'store-heuristic': 'imap',
|
||||||
|
'store-infected': 'imap'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', 'quarantine', 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_antivirus_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_antivirus_settings.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_antivirus_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',
|
||||||
|
'antivirus_settings': {
|
||||||
|
'default_db': 'normal',
|
||||||
|
'grayware': 'enable',
|
||||||
|
'override_timeout': '5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_settings.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'default-db': 'normal',
|
||||||
|
'grayware': 'enable',
|
||||||
|
'override-timeout': '5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', '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_antivirus_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',
|
||||||
|
'antivirus_settings': {
|
||||||
|
'default_db': 'normal',
|
||||||
|
'grayware': 'enable',
|
||||||
|
'override_timeout': '5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_settings.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'default-db': 'normal',
|
||||||
|
'grayware': 'enable',
|
||||||
|
'override-timeout': '5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', '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_antivirus_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',
|
||||||
|
'antivirus_settings': {
|
||||||
|
'default_db': 'normal',
|
||||||
|
'grayware': 'enable',
|
||||||
|
'override_timeout': '5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_settings.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'default-db': 'normal',
|
||||||
|
'grayware': 'enable',
|
||||||
|
'override-timeout': '5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', '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_antivirus_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',
|
||||||
|
'antivirus_settings': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'default_db': 'normal',
|
||||||
|
'grayware': 'enable',
|
||||||
|
'override_timeout': '5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_antivirus_settings.fortios_antivirus(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'default-db': 'normal',
|
||||||
|
'grayware': 'enable',
|
||||||
|
'override-timeout': '5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('antivirus', '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,289 @@
|
|||||||
|
# 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_application_custom
|
||||||
|
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_application_custom.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_application_custom_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',
|
||||||
|
'application_custom': {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'id': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'protocol': 'test_value_8',
|
||||||
|
'signature': 'test_value_9',
|
||||||
|
'tag': 'test_value_10',
|
||||||
|
'technology': 'test_value_11',
|
||||||
|
'vendor': 'test_value_12'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_custom.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'id': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'protocol': 'test_value_8',
|
||||||
|
'signature': 'test_value_9',
|
||||||
|
'tag': 'test_value_10',
|
||||||
|
'technology': 'test_value_11',
|
||||||
|
'vendor': 'test_value_12'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'custom', 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_application_custom_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',
|
||||||
|
'application_custom': {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'id': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'protocol': 'test_value_8',
|
||||||
|
'signature': 'test_value_9',
|
||||||
|
'tag': 'test_value_10',
|
||||||
|
'technology': 'test_value_11',
|
||||||
|
'vendor': 'test_value_12'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_custom.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'id': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'protocol': 'test_value_8',
|
||||||
|
'signature': 'test_value_9',
|
||||||
|
'tag': 'test_value_10',
|
||||||
|
'technology': 'test_value_11',
|
||||||
|
'vendor': 'test_value_12'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'custom', 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_application_custom_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',
|
||||||
|
'application_custom': {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'id': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'protocol': 'test_value_8',
|
||||||
|
'signature': 'test_value_9',
|
||||||
|
'tag': 'test_value_10',
|
||||||
|
'technology': 'test_value_11',
|
||||||
|
'vendor': 'test_value_12'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_custom.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('application', 'custom', 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_application_custom_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',
|
||||||
|
'application_custom': {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'id': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'protocol': 'test_value_8',
|
||||||
|
'signature': 'test_value_9',
|
||||||
|
'tag': 'test_value_10',
|
||||||
|
'technology': 'test_value_11',
|
||||||
|
'vendor': 'test_value_12'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_custom.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('application', 'custom', 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_application_custom_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',
|
||||||
|
'application_custom': {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'id': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'protocol': 'test_value_8',
|
||||||
|
'signature': 'test_value_9',
|
||||||
|
'tag': 'test_value_10',
|
||||||
|
'technology': 'test_value_11',
|
||||||
|
'vendor': 'test_value_12'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_custom.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'id': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'protocol': 'test_value_8',
|
||||||
|
'signature': 'test_value_9',
|
||||||
|
'tag': 'test_value_10',
|
||||||
|
'technology': 'test_value_11',
|
||||||
|
'vendor': 'test_value_12'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'custom', 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_application_custom_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',
|
||||||
|
'application_custom': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'id': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'protocol': 'test_value_8',
|
||||||
|
'signature': 'test_value_9',
|
||||||
|
'tag': 'test_value_10',
|
||||||
|
'technology': 'test_value_11',
|
||||||
|
'vendor': 'test_value_12'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_custom.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'id': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'protocol': 'test_value_8',
|
||||||
|
'signature': 'test_value_9',
|
||||||
|
'tag': 'test_value_10',
|
||||||
|
'technology': 'test_value_11',
|
||||||
|
'vendor': 'test_value_12'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'custom', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,209 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_application_group
|
||||||
|
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_application_group.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_application_group_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',
|
||||||
|
'application_group': {'comment': 'Comment',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'type': 'application'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_group.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'comment': 'Comment',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'type': 'application'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'group', 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_application_group_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',
|
||||||
|
'application_group': {'comment': 'Comment',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'type': 'application'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_group.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'comment': 'Comment',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'type': 'application'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'group', 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_application_group_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',
|
||||||
|
'application_group': {'comment': 'Comment',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'type': 'application'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_group.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('application', 'group', 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_application_group_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',
|
||||||
|
'application_group': {'comment': 'Comment',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'type': 'application'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_group.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('application', 'group', 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_application_group_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',
|
||||||
|
'application_group': {'comment': 'Comment',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'type': 'application'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_group.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'comment': 'Comment',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'type': 'application'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'group', 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_application_group_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',
|
||||||
|
'application_group': {
|
||||||
|
'random_attribute_not_valid': 'tag', 'comment': 'Comment',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'type': 'application'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_group.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'comment': 'Comment',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'type': 'application'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'group', 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,309 @@
|
|||||||
|
# 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_application_list
|
||||||
|
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_application_list.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_application_list_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',
|
||||||
|
'application_list': {
|
||||||
|
'app_replacemsg': 'disable',
|
||||||
|
'comment': 'comments',
|
||||||
|
'deep_app_inspection': 'disable',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'options': 'allow-dns',
|
||||||
|
'other_application_action': 'pass',
|
||||||
|
'other_application_log': 'disable',
|
||||||
|
'p2p_black_list': 'skype',
|
||||||
|
'replacemsg_group': 'test_value_12',
|
||||||
|
'unknown_application_action': 'pass',
|
||||||
|
'unknown_application_log': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_list.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'app-replacemsg': 'disable',
|
||||||
|
'comment': 'comments',
|
||||||
|
'deep-app-inspection': 'disable',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'options': 'allow-dns',
|
||||||
|
'other-application-action': 'pass',
|
||||||
|
'other-application-log': 'disable',
|
||||||
|
'p2p-black-list': 'skype',
|
||||||
|
'replacemsg-group': 'test_value_12',
|
||||||
|
'unknown-application-action': 'pass',
|
||||||
|
'unknown-application-log': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'list', 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_application_list_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',
|
||||||
|
'application_list': {
|
||||||
|
'app_replacemsg': 'disable',
|
||||||
|
'comment': 'comments',
|
||||||
|
'deep_app_inspection': 'disable',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'options': 'allow-dns',
|
||||||
|
'other_application_action': 'pass',
|
||||||
|
'other_application_log': 'disable',
|
||||||
|
'p2p_black_list': 'skype',
|
||||||
|
'replacemsg_group': 'test_value_12',
|
||||||
|
'unknown_application_action': 'pass',
|
||||||
|
'unknown_application_log': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_list.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'app-replacemsg': 'disable',
|
||||||
|
'comment': 'comments',
|
||||||
|
'deep-app-inspection': 'disable',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'options': 'allow-dns',
|
||||||
|
'other-application-action': 'pass',
|
||||||
|
'other-application-log': 'disable',
|
||||||
|
'p2p-black-list': 'skype',
|
||||||
|
'replacemsg-group': 'test_value_12',
|
||||||
|
'unknown-application-action': 'pass',
|
||||||
|
'unknown-application-log': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'list', 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_application_list_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',
|
||||||
|
'application_list': {
|
||||||
|
'app_replacemsg': 'disable',
|
||||||
|
'comment': 'comments',
|
||||||
|
'deep_app_inspection': 'disable',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'options': 'allow-dns',
|
||||||
|
'other_application_action': 'pass',
|
||||||
|
'other_application_log': 'disable',
|
||||||
|
'p2p_black_list': 'skype',
|
||||||
|
'replacemsg_group': 'test_value_12',
|
||||||
|
'unknown_application_action': 'pass',
|
||||||
|
'unknown_application_log': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_list.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('application', 'list', 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_application_list_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',
|
||||||
|
'application_list': {
|
||||||
|
'app_replacemsg': 'disable',
|
||||||
|
'comment': 'comments',
|
||||||
|
'deep_app_inspection': 'disable',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'options': 'allow-dns',
|
||||||
|
'other_application_action': 'pass',
|
||||||
|
'other_application_log': 'disable',
|
||||||
|
'p2p_black_list': 'skype',
|
||||||
|
'replacemsg_group': 'test_value_12',
|
||||||
|
'unknown_application_action': 'pass',
|
||||||
|
'unknown_application_log': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_list.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('application', 'list', 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_application_list_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',
|
||||||
|
'application_list': {
|
||||||
|
'app_replacemsg': 'disable',
|
||||||
|
'comment': 'comments',
|
||||||
|
'deep_app_inspection': 'disable',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'options': 'allow-dns',
|
||||||
|
'other_application_action': 'pass',
|
||||||
|
'other_application_log': 'disable',
|
||||||
|
'p2p_black_list': 'skype',
|
||||||
|
'replacemsg_group': 'test_value_12',
|
||||||
|
'unknown_application_action': 'pass',
|
||||||
|
'unknown_application_log': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_list.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'app-replacemsg': 'disable',
|
||||||
|
'comment': 'comments',
|
||||||
|
'deep-app-inspection': 'disable',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'options': 'allow-dns',
|
||||||
|
'other-application-action': 'pass',
|
||||||
|
'other-application-log': 'disable',
|
||||||
|
'p2p-black-list': 'skype',
|
||||||
|
'replacemsg-group': 'test_value_12',
|
||||||
|
'unknown-application-action': 'pass',
|
||||||
|
'unknown-application-log': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'list', 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_application_list_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',
|
||||||
|
'application_list': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'app_replacemsg': 'disable',
|
||||||
|
'comment': 'comments',
|
||||||
|
'deep_app_inspection': 'disable',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'options': 'allow-dns',
|
||||||
|
'other_application_action': 'pass',
|
||||||
|
'other_application_log': 'disable',
|
||||||
|
'p2p_black_list': 'skype',
|
||||||
|
'replacemsg_group': 'test_value_12',
|
||||||
|
'unknown_application_action': 'pass',
|
||||||
|
'unknown_application_log': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_list.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'app-replacemsg': 'disable',
|
||||||
|
'comment': 'comments',
|
||||||
|
'deep-app-inspection': 'disable',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'options': 'allow-dns',
|
||||||
|
'other-application-action': 'pass',
|
||||||
|
'other-application-log': 'disable',
|
||||||
|
'p2p-black-list': 'skype',
|
||||||
|
'replacemsg-group': 'test_value_12',
|
||||||
|
'unknown-application-action': 'pass',
|
||||||
|
'unknown-application-log': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'list', 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,309 @@
|
|||||||
|
# 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_application_name
|
||||||
|
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_application_name.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_application_name_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',
|
||||||
|
'application_name': {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'id': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'parameter': 'test_value_7',
|
||||||
|
'popularity': '8',
|
||||||
|
'protocol': 'test_value_9',
|
||||||
|
'risk': '10',
|
||||||
|
'sub_category': '11',
|
||||||
|
'technology': 'test_value_12',
|
||||||
|
'vendor': 'test_value_13',
|
||||||
|
'weight': '14'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_name.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'id': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'parameter': 'test_value_7',
|
||||||
|
'popularity': '8',
|
||||||
|
'protocol': 'test_value_9',
|
||||||
|
'risk': '10',
|
||||||
|
'sub-category': '11',
|
||||||
|
'technology': 'test_value_12',
|
||||||
|
'vendor': 'test_value_13',
|
||||||
|
'weight': '14'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'name', 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_application_name_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',
|
||||||
|
'application_name': {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'id': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'parameter': 'test_value_7',
|
||||||
|
'popularity': '8',
|
||||||
|
'protocol': 'test_value_9',
|
||||||
|
'risk': '10',
|
||||||
|
'sub_category': '11',
|
||||||
|
'technology': 'test_value_12',
|
||||||
|
'vendor': 'test_value_13',
|
||||||
|
'weight': '14'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_name.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'id': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'parameter': 'test_value_7',
|
||||||
|
'popularity': '8',
|
||||||
|
'protocol': 'test_value_9',
|
||||||
|
'risk': '10',
|
||||||
|
'sub-category': '11',
|
||||||
|
'technology': 'test_value_12',
|
||||||
|
'vendor': 'test_value_13',
|
||||||
|
'weight': '14'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'name', 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_application_name_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',
|
||||||
|
'application_name': {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'id': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'parameter': 'test_value_7',
|
||||||
|
'popularity': '8',
|
||||||
|
'protocol': 'test_value_9',
|
||||||
|
'risk': '10',
|
||||||
|
'sub_category': '11',
|
||||||
|
'technology': 'test_value_12',
|
||||||
|
'vendor': 'test_value_13',
|
||||||
|
'weight': '14'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_name.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('application', 'name', 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_application_name_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',
|
||||||
|
'application_name': {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'id': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'parameter': 'test_value_7',
|
||||||
|
'popularity': '8',
|
||||||
|
'protocol': 'test_value_9',
|
||||||
|
'risk': '10',
|
||||||
|
'sub_category': '11',
|
||||||
|
'technology': 'test_value_12',
|
||||||
|
'vendor': 'test_value_13',
|
||||||
|
'weight': '14'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_name.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('application', 'name', 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_application_name_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',
|
||||||
|
'application_name': {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'id': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'parameter': 'test_value_7',
|
||||||
|
'popularity': '8',
|
||||||
|
'protocol': 'test_value_9',
|
||||||
|
'risk': '10',
|
||||||
|
'sub_category': '11',
|
||||||
|
'technology': 'test_value_12',
|
||||||
|
'vendor': 'test_value_13',
|
||||||
|
'weight': '14'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_name.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'id': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'parameter': 'test_value_7',
|
||||||
|
'popularity': '8',
|
||||||
|
'protocol': 'test_value_9',
|
||||||
|
'risk': '10',
|
||||||
|
'sub-category': '11',
|
||||||
|
'technology': 'test_value_12',
|
||||||
|
'vendor': 'test_value_13',
|
||||||
|
'weight': '14'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'name', 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_application_name_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',
|
||||||
|
'application_name': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'id': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'parameter': 'test_value_7',
|
||||||
|
'popularity': '8',
|
||||||
|
'protocol': 'test_value_9',
|
||||||
|
'risk': '10',
|
||||||
|
'sub_category': '11',
|
||||||
|
'technology': 'test_value_12',
|
||||||
|
'vendor': 'test_value_13',
|
||||||
|
'weight': '14'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_name.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'behavior': 'test_value_3',
|
||||||
|
'category': '4',
|
||||||
|
'id': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'parameter': 'test_value_7',
|
||||||
|
'popularity': '8',
|
||||||
|
'protocol': 'test_value_9',
|
||||||
|
'risk': '10',
|
||||||
|
'sub-category': '11',
|
||||||
|
'technology': 'test_value_12',
|
||||||
|
'vendor': 'test_value_13',
|
||||||
|
'weight': '14'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'name', 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,199 @@
|
|||||||
|
# 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_application_rule_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_application_rule_settings.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_application_rule_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',
|
||||||
|
'application_rule_settings': {
|
||||||
|
'id': '3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_rule_settings.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'id': '3'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'rule-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_application_rule_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',
|
||||||
|
'application_rule_settings': {
|
||||||
|
'id': '3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_rule_settings.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'id': '3'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'rule-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_application_rule_settings_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',
|
||||||
|
'application_rule_settings': {
|
||||||
|
'id': '3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_rule_settings.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('application', 'rule-settings', 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_application_rule_settings_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',
|
||||||
|
'application_rule_settings': {
|
||||||
|
'id': '3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_rule_settings.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('application', 'rule-settings', 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_application_rule_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',
|
||||||
|
'application_rule_settings': {
|
||||||
|
'id': '3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_rule_settings.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'id': '3'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'rule-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_application_rule_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',
|
||||||
|
'application_rule_settings': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'id': '3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_application_rule_settings.fortios_application(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'id': '3'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('application', 'rule-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,279 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_authentication_rule
|
||||||
|
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_authentication_rule.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_authentication_rule_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',
|
||||||
|
'authentication_rule': {
|
||||||
|
'active_auth_method': 'test_value_3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'ip_based': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'protocol': 'http',
|
||||||
|
'sso_auth_method': 'test_value_8',
|
||||||
|
'status': 'enable',
|
||||||
|
'transaction_based': 'enable',
|
||||||
|
'web_auth_cookie': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_rule.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'active-auth-method': 'test_value_3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'ip-based': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'protocol': 'http',
|
||||||
|
'sso-auth-method': 'test_value_8',
|
||||||
|
'status': 'enable',
|
||||||
|
'transaction-based': 'enable',
|
||||||
|
'web-auth-cookie': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('authentication', 'rule', 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_authentication_rule_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',
|
||||||
|
'authentication_rule': {
|
||||||
|
'active_auth_method': 'test_value_3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'ip_based': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'protocol': 'http',
|
||||||
|
'sso_auth_method': 'test_value_8',
|
||||||
|
'status': 'enable',
|
||||||
|
'transaction_based': 'enable',
|
||||||
|
'web_auth_cookie': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_rule.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'active-auth-method': 'test_value_3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'ip-based': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'protocol': 'http',
|
||||||
|
'sso-auth-method': 'test_value_8',
|
||||||
|
'status': 'enable',
|
||||||
|
'transaction-based': 'enable',
|
||||||
|
'web-auth-cookie': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('authentication', 'rule', 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_authentication_rule_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',
|
||||||
|
'authentication_rule': {
|
||||||
|
'active_auth_method': 'test_value_3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'ip_based': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'protocol': 'http',
|
||||||
|
'sso_auth_method': 'test_value_8',
|
||||||
|
'status': 'enable',
|
||||||
|
'transaction_based': 'enable',
|
||||||
|
'web_auth_cookie': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_rule.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('authentication', 'rule', 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_authentication_rule_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',
|
||||||
|
'authentication_rule': {
|
||||||
|
'active_auth_method': 'test_value_3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'ip_based': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'protocol': 'http',
|
||||||
|
'sso_auth_method': 'test_value_8',
|
||||||
|
'status': 'enable',
|
||||||
|
'transaction_based': 'enable',
|
||||||
|
'web_auth_cookie': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_rule.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('authentication', 'rule', 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_authentication_rule_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',
|
||||||
|
'authentication_rule': {
|
||||||
|
'active_auth_method': 'test_value_3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'ip_based': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'protocol': 'http',
|
||||||
|
'sso_auth_method': 'test_value_8',
|
||||||
|
'status': 'enable',
|
||||||
|
'transaction_based': 'enable',
|
||||||
|
'web_auth_cookie': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_rule.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'active-auth-method': 'test_value_3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'ip-based': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'protocol': 'http',
|
||||||
|
'sso-auth-method': 'test_value_8',
|
||||||
|
'status': 'enable',
|
||||||
|
'transaction-based': 'enable',
|
||||||
|
'web-auth-cookie': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('authentication', 'rule', 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_authentication_rule_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',
|
||||||
|
'authentication_rule': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'active_auth_method': 'test_value_3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'ip_based': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'protocol': 'http',
|
||||||
|
'sso_auth_method': 'test_value_8',
|
||||||
|
'status': 'enable',
|
||||||
|
'transaction_based': 'enable',
|
||||||
|
'web_auth_cookie': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_rule.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'active-auth-method': 'test_value_3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'ip-based': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'protocol': 'http',
|
||||||
|
'sso-auth-method': 'test_value_8',
|
||||||
|
'status': 'enable',
|
||||||
|
'transaction-based': 'enable',
|
||||||
|
'web-auth-cookie': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('authentication', 'rule', 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,289 @@
|
|||||||
|
# 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_authentication_scheme
|
||||||
|
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_authentication_scheme.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_authentication_scheme_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',
|
||||||
|
'authentication_scheme': {
|
||||||
|
'domain_controller': 'test_value_3',
|
||||||
|
'fsso_agent_for_ntlm': 'test_value_4',
|
||||||
|
'fsso_guest': 'enable',
|
||||||
|
'kerberos_keytab': 'test_value_6',
|
||||||
|
'method': 'ntlm',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'negotiate_ntlm': 'enable',
|
||||||
|
'require_tfa': 'enable',
|
||||||
|
'ssh_ca': 'test_value_11',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_scheme.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'domain-controller': 'test_value_3',
|
||||||
|
'fsso-agent-for-ntlm': 'test_value_4',
|
||||||
|
'fsso-guest': 'enable',
|
||||||
|
'kerberos-keytab': 'test_value_6',
|
||||||
|
'method': 'ntlm',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'negotiate-ntlm': 'enable',
|
||||||
|
'require-tfa': 'enable',
|
||||||
|
'ssh-ca': 'test_value_11',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('authentication', 'scheme', 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_authentication_scheme_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',
|
||||||
|
'authentication_scheme': {
|
||||||
|
'domain_controller': 'test_value_3',
|
||||||
|
'fsso_agent_for_ntlm': 'test_value_4',
|
||||||
|
'fsso_guest': 'enable',
|
||||||
|
'kerberos_keytab': 'test_value_6',
|
||||||
|
'method': 'ntlm',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'negotiate_ntlm': 'enable',
|
||||||
|
'require_tfa': 'enable',
|
||||||
|
'ssh_ca': 'test_value_11',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_scheme.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'domain-controller': 'test_value_3',
|
||||||
|
'fsso-agent-for-ntlm': 'test_value_4',
|
||||||
|
'fsso-guest': 'enable',
|
||||||
|
'kerberos-keytab': 'test_value_6',
|
||||||
|
'method': 'ntlm',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'negotiate-ntlm': 'enable',
|
||||||
|
'require-tfa': 'enable',
|
||||||
|
'ssh-ca': 'test_value_11',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('authentication', 'scheme', 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_authentication_scheme_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',
|
||||||
|
'authentication_scheme': {
|
||||||
|
'domain_controller': 'test_value_3',
|
||||||
|
'fsso_agent_for_ntlm': 'test_value_4',
|
||||||
|
'fsso_guest': 'enable',
|
||||||
|
'kerberos_keytab': 'test_value_6',
|
||||||
|
'method': 'ntlm',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'negotiate_ntlm': 'enable',
|
||||||
|
'require_tfa': 'enable',
|
||||||
|
'ssh_ca': 'test_value_11',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_scheme.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('authentication', 'scheme', 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_authentication_scheme_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',
|
||||||
|
'authentication_scheme': {
|
||||||
|
'domain_controller': 'test_value_3',
|
||||||
|
'fsso_agent_for_ntlm': 'test_value_4',
|
||||||
|
'fsso_guest': 'enable',
|
||||||
|
'kerberos_keytab': 'test_value_6',
|
||||||
|
'method': 'ntlm',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'negotiate_ntlm': 'enable',
|
||||||
|
'require_tfa': 'enable',
|
||||||
|
'ssh_ca': 'test_value_11',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_scheme.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('authentication', 'scheme', 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_authentication_scheme_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',
|
||||||
|
'authentication_scheme': {
|
||||||
|
'domain_controller': 'test_value_3',
|
||||||
|
'fsso_agent_for_ntlm': 'test_value_4',
|
||||||
|
'fsso_guest': 'enable',
|
||||||
|
'kerberos_keytab': 'test_value_6',
|
||||||
|
'method': 'ntlm',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'negotiate_ntlm': 'enable',
|
||||||
|
'require_tfa': 'enable',
|
||||||
|
'ssh_ca': 'test_value_11',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_scheme.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'domain-controller': 'test_value_3',
|
||||||
|
'fsso-agent-for-ntlm': 'test_value_4',
|
||||||
|
'fsso-guest': 'enable',
|
||||||
|
'kerberos-keytab': 'test_value_6',
|
||||||
|
'method': 'ntlm',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'negotiate-ntlm': 'enable',
|
||||||
|
'require-tfa': 'enable',
|
||||||
|
'ssh-ca': 'test_value_11',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('authentication', 'scheme', 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_authentication_scheme_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',
|
||||||
|
'authentication_scheme': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'domain_controller': 'test_value_3',
|
||||||
|
'fsso_agent_for_ntlm': 'test_value_4',
|
||||||
|
'fsso_guest': 'enable',
|
||||||
|
'kerberos_keytab': 'test_value_6',
|
||||||
|
'method': 'ntlm',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'negotiate_ntlm': 'enable',
|
||||||
|
'require_tfa': 'enable',
|
||||||
|
'ssh_ca': 'test_value_11',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_scheme.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'domain-controller': 'test_value_3',
|
||||||
|
'fsso-agent-for-ntlm': 'test_value_4',
|
||||||
|
'fsso-guest': 'enable',
|
||||||
|
'kerberos-keytab': 'test_value_6',
|
||||||
|
'method': 'ntlm',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'negotiate-ntlm': 'enable',
|
||||||
|
'require-tfa': 'enable',
|
||||||
|
'ssh-ca': 'test_value_11',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('authentication', 'scheme', 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_authentication_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_authentication_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_authentication_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',
|
||||||
|
'authentication_setting': {
|
||||||
|
'active_auth_scheme': 'test_value_3',
|
||||||
|
'captive_portal': 'test_value_4',
|
||||||
|
'captive_portal_ip': 'test_value_5',
|
||||||
|
'captive_portal_ip6': 'test_value_6',
|
||||||
|
'captive_portal_port': '7',
|
||||||
|
'captive_portal_type': 'fqdn',
|
||||||
|
'captive_portal6': 'test_value_9',
|
||||||
|
'sso_auth_scheme': 'test_value_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_setting.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'active-auth-scheme': 'test_value_3',
|
||||||
|
'captive-portal': 'test_value_4',
|
||||||
|
'captive-portal-ip': 'test_value_5',
|
||||||
|
'captive-portal-ip6': 'test_value_6',
|
||||||
|
'captive-portal-port': '7',
|
||||||
|
'captive-portal-type': 'fqdn',
|
||||||
|
'captive-portal6': 'test_value_9',
|
||||||
|
'sso-auth-scheme': 'test_value_10'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('authentication', '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_authentication_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',
|
||||||
|
'authentication_setting': {
|
||||||
|
'active_auth_scheme': 'test_value_3',
|
||||||
|
'captive_portal': 'test_value_4',
|
||||||
|
'captive_portal_ip': 'test_value_5',
|
||||||
|
'captive_portal_ip6': 'test_value_6',
|
||||||
|
'captive_portal_port': '7',
|
||||||
|
'captive_portal_type': 'fqdn',
|
||||||
|
'captive_portal6': 'test_value_9',
|
||||||
|
'sso_auth_scheme': 'test_value_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_setting.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'active-auth-scheme': 'test_value_3',
|
||||||
|
'captive-portal': 'test_value_4',
|
||||||
|
'captive-portal-ip': 'test_value_5',
|
||||||
|
'captive-portal-ip6': 'test_value_6',
|
||||||
|
'captive-portal-port': '7',
|
||||||
|
'captive-portal-type': 'fqdn',
|
||||||
|
'captive-portal6': 'test_value_9',
|
||||||
|
'sso-auth-scheme': 'test_value_10'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('authentication', '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_authentication_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',
|
||||||
|
'authentication_setting': {
|
||||||
|
'active_auth_scheme': 'test_value_3',
|
||||||
|
'captive_portal': 'test_value_4',
|
||||||
|
'captive_portal_ip': 'test_value_5',
|
||||||
|
'captive_portal_ip6': 'test_value_6',
|
||||||
|
'captive_portal_port': '7',
|
||||||
|
'captive_portal_type': 'fqdn',
|
||||||
|
'captive_portal6': 'test_value_9',
|
||||||
|
'sso_auth_scheme': 'test_value_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_setting.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'active-auth-scheme': 'test_value_3',
|
||||||
|
'captive-portal': 'test_value_4',
|
||||||
|
'captive-portal-ip': 'test_value_5',
|
||||||
|
'captive-portal-ip6': 'test_value_6',
|
||||||
|
'captive-portal-port': '7',
|
||||||
|
'captive-portal-type': 'fqdn',
|
||||||
|
'captive-portal6': 'test_value_9',
|
||||||
|
'sso-auth-scheme': 'test_value_10'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('authentication', '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_authentication_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',
|
||||||
|
'authentication_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'active_auth_scheme': 'test_value_3',
|
||||||
|
'captive_portal': 'test_value_4',
|
||||||
|
'captive_portal_ip': 'test_value_5',
|
||||||
|
'captive_portal_ip6': 'test_value_6',
|
||||||
|
'captive_portal_port': '7',
|
||||||
|
'captive_portal_type': 'fqdn',
|
||||||
|
'captive_portal6': 'test_value_9',
|
||||||
|
'sso_auth_scheme': 'test_value_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_authentication_setting.fortios_authentication(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'active-auth-scheme': 'test_value_3',
|
||||||
|
'captive-portal': 'test_value_4',
|
||||||
|
'captive-portal-ip': 'test_value_5',
|
||||||
|
'captive-portal-ip6': 'test_value_6',
|
||||||
|
'captive-portal-port': '7',
|
||||||
|
'captive-portal-type': 'fqdn',
|
||||||
|
'captive-portal6': 'test_value_9',
|
||||||
|
'sso-auth-scheme': 'test_value_10'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('authentication', '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,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_dlp_filepattern
|
||||||
|
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_dlp_filepattern.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dlp_filepattern_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',
|
||||||
|
'dlp_filepattern': {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_filepattern.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', 'filepattern', 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_dlp_filepattern_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',
|
||||||
|
'dlp_filepattern': {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_filepattern.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', 'filepattern', 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_dlp_filepattern_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',
|
||||||
|
'dlp_filepattern': {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_filepattern.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('dlp', 'filepattern', 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_dlp_filepattern_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',
|
||||||
|
'dlp_filepattern': {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_filepattern.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('dlp', 'filepattern', 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_dlp_filepattern_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',
|
||||||
|
'dlp_filepattern': {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_filepattern.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', 'filepattern', 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_dlp_filepattern_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',
|
||||||
|
'dlp_filepattern': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_filepattern.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', 'filepattern', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,369 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_dlp_fp_doc_source
|
||||||
|
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_dlp_fp_doc_source.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dlp_fp_doc_source_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',
|
||||||
|
'dlp_fp_doc_source': {
|
||||||
|
'date': '3',
|
||||||
|
'file_path': 'test_value_4',
|
||||||
|
'file_pattern': 'test_value_5',
|
||||||
|
'keep_modified': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'password': 'test_value_8',
|
||||||
|
'period': 'none',
|
||||||
|
'remove_deleted': 'enable',
|
||||||
|
'scan_on_creation': 'enable',
|
||||||
|
'scan_subdirectories': 'enable',
|
||||||
|
'sensitivity': 'test_value_13',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'server_type': 'samba',
|
||||||
|
'tod_hour': '16',
|
||||||
|
'tod_min': '17',
|
||||||
|
'username': 'test_value_18',
|
||||||
|
'vdom': 'mgmt',
|
||||||
|
'weekday': 'sunday'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_fp_doc_source.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'date': '3',
|
||||||
|
'file-path': 'test_value_4',
|
||||||
|
'file-pattern': 'test_value_5',
|
||||||
|
'keep-modified': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'password': 'test_value_8',
|
||||||
|
'period': 'none',
|
||||||
|
'remove-deleted': 'enable',
|
||||||
|
'scan-on-creation': 'enable',
|
||||||
|
'scan-subdirectories': 'enable',
|
||||||
|
'sensitivity': 'test_value_13',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'server-type': 'samba',
|
||||||
|
'tod-hour': '16',
|
||||||
|
'tod-min': '17',
|
||||||
|
'username': 'test_value_18',
|
||||||
|
'vdom': 'mgmt',
|
||||||
|
'weekday': 'sunday'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', 'fp-doc-source', 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_dlp_fp_doc_source_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',
|
||||||
|
'dlp_fp_doc_source': {
|
||||||
|
'date': '3',
|
||||||
|
'file_path': 'test_value_4',
|
||||||
|
'file_pattern': 'test_value_5',
|
||||||
|
'keep_modified': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'password': 'test_value_8',
|
||||||
|
'period': 'none',
|
||||||
|
'remove_deleted': 'enable',
|
||||||
|
'scan_on_creation': 'enable',
|
||||||
|
'scan_subdirectories': 'enable',
|
||||||
|
'sensitivity': 'test_value_13',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'server_type': 'samba',
|
||||||
|
'tod_hour': '16',
|
||||||
|
'tod_min': '17',
|
||||||
|
'username': 'test_value_18',
|
||||||
|
'vdom': 'mgmt',
|
||||||
|
'weekday': 'sunday'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_fp_doc_source.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'date': '3',
|
||||||
|
'file-path': 'test_value_4',
|
||||||
|
'file-pattern': 'test_value_5',
|
||||||
|
'keep-modified': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'password': 'test_value_8',
|
||||||
|
'period': 'none',
|
||||||
|
'remove-deleted': 'enable',
|
||||||
|
'scan-on-creation': 'enable',
|
||||||
|
'scan-subdirectories': 'enable',
|
||||||
|
'sensitivity': 'test_value_13',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'server-type': 'samba',
|
||||||
|
'tod-hour': '16',
|
||||||
|
'tod-min': '17',
|
||||||
|
'username': 'test_value_18',
|
||||||
|
'vdom': 'mgmt',
|
||||||
|
'weekday': 'sunday'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', 'fp-doc-source', 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_dlp_fp_doc_source_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',
|
||||||
|
'dlp_fp_doc_source': {
|
||||||
|
'date': '3',
|
||||||
|
'file_path': 'test_value_4',
|
||||||
|
'file_pattern': 'test_value_5',
|
||||||
|
'keep_modified': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'password': 'test_value_8',
|
||||||
|
'period': 'none',
|
||||||
|
'remove_deleted': 'enable',
|
||||||
|
'scan_on_creation': 'enable',
|
||||||
|
'scan_subdirectories': 'enable',
|
||||||
|
'sensitivity': 'test_value_13',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'server_type': 'samba',
|
||||||
|
'tod_hour': '16',
|
||||||
|
'tod_min': '17',
|
||||||
|
'username': 'test_value_18',
|
||||||
|
'vdom': 'mgmt',
|
||||||
|
'weekday': 'sunday'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_fp_doc_source.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('dlp', 'fp-doc-source', 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_dlp_fp_doc_source_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',
|
||||||
|
'dlp_fp_doc_source': {
|
||||||
|
'date': '3',
|
||||||
|
'file_path': 'test_value_4',
|
||||||
|
'file_pattern': 'test_value_5',
|
||||||
|
'keep_modified': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'password': 'test_value_8',
|
||||||
|
'period': 'none',
|
||||||
|
'remove_deleted': 'enable',
|
||||||
|
'scan_on_creation': 'enable',
|
||||||
|
'scan_subdirectories': 'enable',
|
||||||
|
'sensitivity': 'test_value_13',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'server_type': 'samba',
|
||||||
|
'tod_hour': '16',
|
||||||
|
'tod_min': '17',
|
||||||
|
'username': 'test_value_18',
|
||||||
|
'vdom': 'mgmt',
|
||||||
|
'weekday': 'sunday'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_fp_doc_source.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('dlp', 'fp-doc-source', 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_dlp_fp_doc_source_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',
|
||||||
|
'dlp_fp_doc_source': {
|
||||||
|
'date': '3',
|
||||||
|
'file_path': 'test_value_4',
|
||||||
|
'file_pattern': 'test_value_5',
|
||||||
|
'keep_modified': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'password': 'test_value_8',
|
||||||
|
'period': 'none',
|
||||||
|
'remove_deleted': 'enable',
|
||||||
|
'scan_on_creation': 'enable',
|
||||||
|
'scan_subdirectories': 'enable',
|
||||||
|
'sensitivity': 'test_value_13',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'server_type': 'samba',
|
||||||
|
'tod_hour': '16',
|
||||||
|
'tod_min': '17',
|
||||||
|
'username': 'test_value_18',
|
||||||
|
'vdom': 'mgmt',
|
||||||
|
'weekday': 'sunday'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_fp_doc_source.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'date': '3',
|
||||||
|
'file-path': 'test_value_4',
|
||||||
|
'file-pattern': 'test_value_5',
|
||||||
|
'keep-modified': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'password': 'test_value_8',
|
||||||
|
'period': 'none',
|
||||||
|
'remove-deleted': 'enable',
|
||||||
|
'scan-on-creation': 'enable',
|
||||||
|
'scan-subdirectories': 'enable',
|
||||||
|
'sensitivity': 'test_value_13',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'server-type': 'samba',
|
||||||
|
'tod-hour': '16',
|
||||||
|
'tod-min': '17',
|
||||||
|
'username': 'test_value_18',
|
||||||
|
'vdom': 'mgmt',
|
||||||
|
'weekday': 'sunday'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', 'fp-doc-source', 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_dlp_fp_doc_source_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',
|
||||||
|
'dlp_fp_doc_source': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'date': '3',
|
||||||
|
'file_path': 'test_value_4',
|
||||||
|
'file_pattern': 'test_value_5',
|
||||||
|
'keep_modified': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'password': 'test_value_8',
|
||||||
|
'period': 'none',
|
||||||
|
'remove_deleted': 'enable',
|
||||||
|
'scan_on_creation': 'enable',
|
||||||
|
'scan_subdirectories': 'enable',
|
||||||
|
'sensitivity': 'test_value_13',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'server_type': 'samba',
|
||||||
|
'tod_hour': '16',
|
||||||
|
'tod_min': '17',
|
||||||
|
'username': 'test_value_18',
|
||||||
|
'vdom': 'mgmt',
|
||||||
|
'weekday': 'sunday'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_fp_doc_source.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'date': '3',
|
||||||
|
'file-path': 'test_value_4',
|
||||||
|
'file-pattern': 'test_value_5',
|
||||||
|
'keep-modified': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'password': 'test_value_8',
|
||||||
|
'period': 'none',
|
||||||
|
'remove-deleted': 'enable',
|
||||||
|
'scan-on-creation': 'enable',
|
||||||
|
'scan-subdirectories': 'enable',
|
||||||
|
'sensitivity': 'test_value_13',
|
||||||
|
'server': '192.168.100.14',
|
||||||
|
'server-type': 'samba',
|
||||||
|
'tod-hour': '16',
|
||||||
|
'tod-min': '17',
|
||||||
|
'username': 'test_value_18',
|
||||||
|
'vdom': 'mgmt',
|
||||||
|
'weekday': 'sunday'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', 'fp-doc-source', 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,199 @@
|
|||||||
|
# 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_dlp_fp_sensitivity
|
||||||
|
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_dlp_fp_sensitivity.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dlp_fp_sensitivity_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',
|
||||||
|
'dlp_fp_sensitivity': {
|
||||||
|
'name': 'default_name_3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_fp_sensitivity.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', 'fp-sensitivity', 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_dlp_fp_sensitivity_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',
|
||||||
|
'dlp_fp_sensitivity': {
|
||||||
|
'name': 'default_name_3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_fp_sensitivity.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', 'fp-sensitivity', 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_dlp_fp_sensitivity_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',
|
||||||
|
'dlp_fp_sensitivity': {
|
||||||
|
'name': 'default_name_3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_fp_sensitivity.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('dlp', 'fp-sensitivity', 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_dlp_fp_sensitivity_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',
|
||||||
|
'dlp_fp_sensitivity': {
|
||||||
|
'name': 'default_name_3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_fp_sensitivity.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('dlp', 'fp-sensitivity', 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_dlp_fp_sensitivity_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',
|
||||||
|
'dlp_fp_sensitivity': {
|
||||||
|
'name': 'default_name_3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_fp_sensitivity.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', 'fp-sensitivity', 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_dlp_fp_sensitivity_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',
|
||||||
|
'dlp_fp_sensitivity': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'name': 'default_name_3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_fp_sensitivity.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', 'fp-sensitivity', 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,289 @@
|
|||||||
|
# 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_dlp_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_dlp_sensor.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dlp_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',
|
||||||
|
'dlp_sensor': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dlp_log': 'enable',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'flow_based': 'enable',
|
||||||
|
'full_archive_proto': 'smtp',
|
||||||
|
'nac_quar_log': 'enable',
|
||||||
|
'name': 'default_name_9',
|
||||||
|
'options': 'test_value_10,',
|
||||||
|
'replacemsg_group': 'test_value_11',
|
||||||
|
'summary_proto': 'smtp'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_sensor.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dlp-log': 'enable',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'flow-based': 'enable',
|
||||||
|
'full-archive-proto': 'smtp',
|
||||||
|
'nac-quar-log': 'enable',
|
||||||
|
'name': 'default_name_9',
|
||||||
|
'options': 'test_value_10,',
|
||||||
|
'replacemsg-group': 'test_value_11',
|
||||||
|
'summary-proto': 'smtp'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', '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_dlp_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',
|
||||||
|
'dlp_sensor': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dlp_log': 'enable',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'flow_based': 'enable',
|
||||||
|
'full_archive_proto': 'smtp',
|
||||||
|
'nac_quar_log': 'enable',
|
||||||
|
'name': 'default_name_9',
|
||||||
|
'options': 'test_value_10,',
|
||||||
|
'replacemsg_group': 'test_value_11',
|
||||||
|
'summary_proto': 'smtp'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_sensor.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dlp-log': 'enable',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'flow-based': 'enable',
|
||||||
|
'full-archive-proto': 'smtp',
|
||||||
|
'nac-quar-log': 'enable',
|
||||||
|
'name': 'default_name_9',
|
||||||
|
'options': 'test_value_10,',
|
||||||
|
'replacemsg-group': 'test_value_11',
|
||||||
|
'summary-proto': 'smtp'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', '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_dlp_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',
|
||||||
|
'dlp_sensor': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dlp_log': 'enable',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'flow_based': 'enable',
|
||||||
|
'full_archive_proto': 'smtp',
|
||||||
|
'nac_quar_log': 'enable',
|
||||||
|
'name': 'default_name_9',
|
||||||
|
'options': 'test_value_10,',
|
||||||
|
'replacemsg_group': 'test_value_11',
|
||||||
|
'summary_proto': 'smtp'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_sensor.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('dlp', '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_dlp_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',
|
||||||
|
'dlp_sensor': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dlp_log': 'enable',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'flow_based': 'enable',
|
||||||
|
'full_archive_proto': 'smtp',
|
||||||
|
'nac_quar_log': 'enable',
|
||||||
|
'name': 'default_name_9',
|
||||||
|
'options': 'test_value_10,',
|
||||||
|
'replacemsg_group': 'test_value_11',
|
||||||
|
'summary_proto': 'smtp'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_sensor.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('dlp', '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_dlp_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',
|
||||||
|
'dlp_sensor': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dlp_log': 'enable',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'flow_based': 'enable',
|
||||||
|
'full_archive_proto': 'smtp',
|
||||||
|
'nac_quar_log': 'enable',
|
||||||
|
'name': 'default_name_9',
|
||||||
|
'options': 'test_value_10,',
|
||||||
|
'replacemsg_group': 'test_value_11',
|
||||||
|
'summary_proto': 'smtp'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_sensor.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dlp-log': 'enable',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'flow-based': 'enable',
|
||||||
|
'full-archive-proto': 'smtp',
|
||||||
|
'nac-quar-log': 'enable',
|
||||||
|
'name': 'default_name_9',
|
||||||
|
'options': 'test_value_10,',
|
||||||
|
'replacemsg-group': 'test_value_11',
|
||||||
|
'summary-proto': 'smtp'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', '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_dlp_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',
|
||||||
|
'dlp_sensor': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dlp_log': 'enable',
|
||||||
|
'extended_log': 'enable',
|
||||||
|
'flow_based': 'enable',
|
||||||
|
'full_archive_proto': 'smtp',
|
||||||
|
'nac_quar_log': 'enable',
|
||||||
|
'name': 'default_name_9',
|
||||||
|
'options': 'test_value_10,',
|
||||||
|
'replacemsg_group': 'test_value_11',
|
||||||
|
'summary_proto': 'smtp'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_sensor.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dlp-log': 'enable',
|
||||||
|
'extended-log': 'enable',
|
||||||
|
'flow-based': 'enable',
|
||||||
|
'full-archive-proto': 'smtp',
|
||||||
|
'nac-quar-log': 'enable',
|
||||||
|
'name': 'default_name_9',
|
||||||
|
'options': 'test_value_10,',
|
||||||
|
'replacemsg-group': 'test_value_11',
|
||||||
|
'summary-proto': 'smtp'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', '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,183 @@
|
|||||||
|
# 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_dlp_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_dlp_settings.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dlp_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',
|
||||||
|
'dlp_settings': {
|
||||||
|
'cache_mem_percent': '3',
|
||||||
|
'chunk_size': '4',
|
||||||
|
'db_mode': 'stop-adding',
|
||||||
|
'size': '6',
|
||||||
|
'storage_device': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_settings.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'cache-mem-percent': '3',
|
||||||
|
'chunk-size': '4',
|
||||||
|
'db-mode': 'stop-adding',
|
||||||
|
'size': '6',
|
||||||
|
'storage-device': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', '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_dlp_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',
|
||||||
|
'dlp_settings': {
|
||||||
|
'cache_mem_percent': '3',
|
||||||
|
'chunk_size': '4',
|
||||||
|
'db_mode': 'stop-adding',
|
||||||
|
'size': '6',
|
||||||
|
'storage_device': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_settings.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'cache-mem-percent': '3',
|
||||||
|
'chunk-size': '4',
|
||||||
|
'db-mode': 'stop-adding',
|
||||||
|
'size': '6',
|
||||||
|
'storage-device': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', '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_dlp_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',
|
||||||
|
'dlp_settings': {
|
||||||
|
'cache_mem_percent': '3',
|
||||||
|
'chunk_size': '4',
|
||||||
|
'db_mode': 'stop-adding',
|
||||||
|
'size': '6',
|
||||||
|
'storage_device': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_settings.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'cache-mem-percent': '3',
|
||||||
|
'chunk-size': '4',
|
||||||
|
'db-mode': 'stop-adding',
|
||||||
|
'size': '6',
|
||||||
|
'storage-device': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', '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_dlp_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',
|
||||||
|
'dlp_settings': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'cache_mem_percent': '3',
|
||||||
|
'chunk_size': '4',
|
||||||
|
'db_mode': 'stop-adding',
|
||||||
|
'size': '6',
|
||||||
|
'storage_device': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dlp_settings.fortios_dlp(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'cache-mem-percent': '3',
|
||||||
|
'chunk-size': '4',
|
||||||
|
'db-mode': 'stop-adding',
|
||||||
|
'size': '6',
|
||||||
|
'storage-device': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dlp', '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_dnsfilter_domain_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_dnsfilter_domain_filter.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dnsfilter_domain_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',
|
||||||
|
'dnsfilter_domain_filter': {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dnsfilter_domain_filter.fortios_dnsfilter(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dnsfilter', 'domain-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_dnsfilter_domain_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',
|
||||||
|
'dnsfilter_domain_filter': {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dnsfilter_domain_filter.fortios_dnsfilter(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dnsfilter', 'domain-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_dnsfilter_domain_filter_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',
|
||||||
|
'dnsfilter_domain_filter': {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dnsfilter_domain_filter.fortios_dnsfilter(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('dnsfilter', 'domain-filter', 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_dnsfilter_domain_filter_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',
|
||||||
|
'dnsfilter_domain_filter': {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dnsfilter_domain_filter.fortios_dnsfilter(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('dnsfilter', 'domain-filter', 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_dnsfilter_domain_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',
|
||||||
|
'dnsfilter_domain_filter': {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dnsfilter_domain_filter.fortios_dnsfilter(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dnsfilter', 'domain-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_dnsfilter_domain_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',
|
||||||
|
'dnsfilter_domain_filter': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dnsfilter_domain_filter.fortios_dnsfilter(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'id': '4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dnsfilter', 'domain-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,289 @@
|
|||||||
|
# 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_dnsfilter_profile
|
||||||
|
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_dnsfilter_profile.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dnsfilter_profile_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',
|
||||||
|
'dnsfilter_profile': {
|
||||||
|
'block_action': 'block',
|
||||||
|
'block_botnet': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'log_all_domain': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'redirect_portal': 'test_value_8',
|
||||||
|
'safe_search': 'disable',
|
||||||
|
'sdns_domain_log': 'enable',
|
||||||
|
'sdns_ftgd_err_log': 'enable',
|
||||||
|
'youtube_restrict': 'strict'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dnsfilter_profile.fortios_dnsfilter(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'block-action': 'block',
|
||||||
|
'block-botnet': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'log-all-domain': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'redirect-portal': 'test_value_8',
|
||||||
|
'safe-search': 'disable',
|
||||||
|
'sdns-domain-log': 'enable',
|
||||||
|
'sdns-ftgd-err-log': 'enable',
|
||||||
|
'youtube-restrict': 'strict'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dnsfilter', 'profile', 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_dnsfilter_profile_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',
|
||||||
|
'dnsfilter_profile': {
|
||||||
|
'block_action': 'block',
|
||||||
|
'block_botnet': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'log_all_domain': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'redirect_portal': 'test_value_8',
|
||||||
|
'safe_search': 'disable',
|
||||||
|
'sdns_domain_log': 'enable',
|
||||||
|
'sdns_ftgd_err_log': 'enable',
|
||||||
|
'youtube_restrict': 'strict'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dnsfilter_profile.fortios_dnsfilter(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'block-action': 'block',
|
||||||
|
'block-botnet': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'log-all-domain': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'redirect-portal': 'test_value_8',
|
||||||
|
'safe-search': 'disable',
|
||||||
|
'sdns-domain-log': 'enable',
|
||||||
|
'sdns-ftgd-err-log': 'enable',
|
||||||
|
'youtube-restrict': 'strict'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dnsfilter', 'profile', 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_dnsfilter_profile_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',
|
||||||
|
'dnsfilter_profile': {
|
||||||
|
'block_action': 'block',
|
||||||
|
'block_botnet': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'log_all_domain': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'redirect_portal': 'test_value_8',
|
||||||
|
'safe_search': 'disable',
|
||||||
|
'sdns_domain_log': 'enable',
|
||||||
|
'sdns_ftgd_err_log': 'enable',
|
||||||
|
'youtube_restrict': 'strict'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dnsfilter_profile.fortios_dnsfilter(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('dnsfilter', 'profile', 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_dnsfilter_profile_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',
|
||||||
|
'dnsfilter_profile': {
|
||||||
|
'block_action': 'block',
|
||||||
|
'block_botnet': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'log_all_domain': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'redirect_portal': 'test_value_8',
|
||||||
|
'safe_search': 'disable',
|
||||||
|
'sdns_domain_log': 'enable',
|
||||||
|
'sdns_ftgd_err_log': 'enable',
|
||||||
|
'youtube_restrict': 'strict'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dnsfilter_profile.fortios_dnsfilter(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('dnsfilter', 'profile', 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_dnsfilter_profile_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',
|
||||||
|
'dnsfilter_profile': {
|
||||||
|
'block_action': 'block',
|
||||||
|
'block_botnet': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'log_all_domain': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'redirect_portal': 'test_value_8',
|
||||||
|
'safe_search': 'disable',
|
||||||
|
'sdns_domain_log': 'enable',
|
||||||
|
'sdns_ftgd_err_log': 'enable',
|
||||||
|
'youtube_restrict': 'strict'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dnsfilter_profile.fortios_dnsfilter(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'block-action': 'block',
|
||||||
|
'block-botnet': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'log-all-domain': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'redirect-portal': 'test_value_8',
|
||||||
|
'safe-search': 'disable',
|
||||||
|
'sdns-domain-log': 'enable',
|
||||||
|
'sdns-ftgd-err-log': 'enable',
|
||||||
|
'youtube-restrict': 'strict'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dnsfilter', 'profile', 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_dnsfilter_profile_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',
|
||||||
|
'dnsfilter_profile': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'block_action': 'block',
|
||||||
|
'block_botnet': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'log_all_domain': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'redirect_portal': 'test_value_8',
|
||||||
|
'safe_search': 'disable',
|
||||||
|
'sdns_domain_log': 'enable',
|
||||||
|
'sdns_ftgd_err_log': 'enable',
|
||||||
|
'youtube_restrict': 'strict'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_dnsfilter_profile.fortios_dnsfilter(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'block-action': 'block',
|
||||||
|
'block-botnet': 'disable',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'log-all-domain': 'enable',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'redirect-portal': 'test_value_8',
|
||||||
|
'safe-search': 'disable',
|
||||||
|
'sdns-domain-log': 'enable',
|
||||||
|
'sdns-ftgd-err-log': 'enable',
|
||||||
|
'youtube-restrict': 'strict'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('dnsfilter', 'profile', 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,249 @@
|
|||||||
|
# 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_endpoint_control_client
|
||||||
|
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_endpoint_control_client.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_endpoint_control_client_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',
|
||||||
|
'endpoint_control_client': {
|
||||||
|
'ad_groups': 'test_value_3',
|
||||||
|
'ftcl_uid': 'test_value_4',
|
||||||
|
'id': '5',
|
||||||
|
'info': 'test_value_6',
|
||||||
|
'src_ip': 'test_value_7',
|
||||||
|
'src_mac': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_endpoint_control_client.fortios_endpoint_control(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'ad-groups': 'test_value_3',
|
||||||
|
'ftcl-uid': 'test_value_4',
|
||||||
|
'id': '5',
|
||||||
|
'info': 'test_value_6',
|
||||||
|
'src-ip': 'test_value_7',
|
||||||
|
'src-mac': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('endpoint-control', 'client', 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_endpoint_control_client_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',
|
||||||
|
'endpoint_control_client': {
|
||||||
|
'ad_groups': 'test_value_3',
|
||||||
|
'ftcl_uid': 'test_value_4',
|
||||||
|
'id': '5',
|
||||||
|
'info': 'test_value_6',
|
||||||
|
'src_ip': 'test_value_7',
|
||||||
|
'src_mac': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_endpoint_control_client.fortios_endpoint_control(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'ad-groups': 'test_value_3',
|
||||||
|
'ftcl-uid': 'test_value_4',
|
||||||
|
'id': '5',
|
||||||
|
'info': 'test_value_6',
|
||||||
|
'src-ip': 'test_value_7',
|
||||||
|
'src-mac': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('endpoint-control', 'client', 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_endpoint_control_client_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',
|
||||||
|
'endpoint_control_client': {
|
||||||
|
'ad_groups': 'test_value_3',
|
||||||
|
'ftcl_uid': 'test_value_4',
|
||||||
|
'id': '5',
|
||||||
|
'info': 'test_value_6',
|
||||||
|
'src_ip': 'test_value_7',
|
||||||
|
'src_mac': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_endpoint_control_client.fortios_endpoint_control(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('endpoint-control', 'client', 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_endpoint_control_client_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',
|
||||||
|
'endpoint_control_client': {
|
||||||
|
'ad_groups': 'test_value_3',
|
||||||
|
'ftcl_uid': 'test_value_4',
|
||||||
|
'id': '5',
|
||||||
|
'info': 'test_value_6',
|
||||||
|
'src_ip': 'test_value_7',
|
||||||
|
'src_mac': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_endpoint_control_client.fortios_endpoint_control(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('endpoint-control', 'client', 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_endpoint_control_client_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',
|
||||||
|
'endpoint_control_client': {
|
||||||
|
'ad_groups': 'test_value_3',
|
||||||
|
'ftcl_uid': 'test_value_4',
|
||||||
|
'id': '5',
|
||||||
|
'info': 'test_value_6',
|
||||||
|
'src_ip': 'test_value_7',
|
||||||
|
'src_mac': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_endpoint_control_client.fortios_endpoint_control(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'ad-groups': 'test_value_3',
|
||||||
|
'ftcl-uid': 'test_value_4',
|
||||||
|
'id': '5',
|
||||||
|
'info': 'test_value_6',
|
||||||
|
'src-ip': 'test_value_7',
|
||||||
|
'src-mac': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('endpoint-control', 'client', 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_endpoint_control_client_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',
|
||||||
|
'endpoint_control_client': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'ad_groups': 'test_value_3',
|
||||||
|
'ftcl_uid': 'test_value_4',
|
||||||
|
'id': '5',
|
||||||
|
'info': 'test_value_6',
|
||||||
|
'src_ip': 'test_value_7',
|
||||||
|
'src_mac': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_endpoint_control_client.fortios_endpoint_control(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'ad-groups': 'test_value_3',
|
||||||
|
'ftcl-uid': 'test_value_4',
|
||||||
|
'id': '5',
|
||||||
|
'info': 'test_value_6',
|
||||||
|
'src-ip': 'test_value_7',
|
||||||
|
'src-mac': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('endpoint-control', 'client', 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