mirror of https://github.com/ansible/ansible.git
FortiOS modules for 2.9 - 11 (#61387)
parent
f5d829392a
commit
da762018e8
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,351 @@
|
||||
# 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_web_proxy_explicit
|
||||
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_web_proxy_explicit.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_web_proxy_explicit_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',
|
||||
'web_proxy_explicit': {
|
||||
'ftp_incoming_port': 'test_value_3',
|
||||
'ftp_over_http': 'enable',
|
||||
'http_incoming_port': 'test_value_5',
|
||||
'https_incoming_port': 'test_value_6',
|
||||
'https_replacement_message': 'enable',
|
||||
'incoming_ip': 'test_value_8',
|
||||
'incoming_ip6': 'test_value_9',
|
||||
'ipv6_status': 'enable',
|
||||
'message_upon_server_error': 'enable',
|
||||
'outgoing_ip': 'test_value_12',
|
||||
'outgoing_ip6': 'test_value_13',
|
||||
'pac_file_data': 'test_value_14',
|
||||
'pac_file_name': 'test_value_15',
|
||||
'pac_file_server_port': 'test_value_16',
|
||||
'pac_file_server_status': 'enable',
|
||||
'pac_file_url': 'test_value_18',
|
||||
'pref_dns_result': 'ipv4',
|
||||
'realm': 'test_value_20',
|
||||
'sec_default_action': 'accept',
|
||||
'socks': 'enable',
|
||||
'socks_incoming_port': 'test_value_23',
|
||||
'ssl_algorithm': 'low',
|
||||
'status': 'enable',
|
||||
'strict_guest': 'enable',
|
||||
'trace_auth_no_rsp': 'enable',
|
||||
'unknown_http_version': 'reject'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_explicit.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ftp-incoming-port': 'test_value_3',
|
||||
'ftp-over-http': 'enable',
|
||||
'http-incoming-port': 'test_value_5',
|
||||
'https-incoming-port': 'test_value_6',
|
||||
'https-replacement-message': 'enable',
|
||||
'incoming-ip': 'test_value_8',
|
||||
'incoming-ip6': 'test_value_9',
|
||||
'ipv6-status': 'enable',
|
||||
'message-upon-server-error': 'enable',
|
||||
'outgoing-ip': 'test_value_12',
|
||||
'outgoing-ip6': 'test_value_13',
|
||||
'pac-file-data': 'test_value_14',
|
||||
'pac-file-name': 'test_value_15',
|
||||
'pac-file-server-port': 'test_value_16',
|
||||
'pac-file-server-status': 'enable',
|
||||
'pac-file-url': 'test_value_18',
|
||||
'pref-dns-result': 'ipv4',
|
||||
'realm': 'test_value_20',
|
||||
'sec-default-action': 'accept',
|
||||
'socks': 'enable',
|
||||
'socks-incoming-port': 'test_value_23',
|
||||
'ssl-algorithm': 'low',
|
||||
'status': 'enable',
|
||||
'strict-guest': 'enable',
|
||||
'trace-auth-no-rsp': 'enable',
|
||||
'unknown-http-version': 'reject'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('web-proxy', 'explicit', 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_web_proxy_explicit_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',
|
||||
'web_proxy_explicit': {
|
||||
'ftp_incoming_port': 'test_value_3',
|
||||
'ftp_over_http': 'enable',
|
||||
'http_incoming_port': 'test_value_5',
|
||||
'https_incoming_port': 'test_value_6',
|
||||
'https_replacement_message': 'enable',
|
||||
'incoming_ip': 'test_value_8',
|
||||
'incoming_ip6': 'test_value_9',
|
||||
'ipv6_status': 'enable',
|
||||
'message_upon_server_error': 'enable',
|
||||
'outgoing_ip': 'test_value_12',
|
||||
'outgoing_ip6': 'test_value_13',
|
||||
'pac_file_data': 'test_value_14',
|
||||
'pac_file_name': 'test_value_15',
|
||||
'pac_file_server_port': 'test_value_16',
|
||||
'pac_file_server_status': 'enable',
|
||||
'pac_file_url': 'test_value_18',
|
||||
'pref_dns_result': 'ipv4',
|
||||
'realm': 'test_value_20',
|
||||
'sec_default_action': 'accept',
|
||||
'socks': 'enable',
|
||||
'socks_incoming_port': 'test_value_23',
|
||||
'ssl_algorithm': 'low',
|
||||
'status': 'enable',
|
||||
'strict_guest': 'enable',
|
||||
'trace_auth_no_rsp': 'enable',
|
||||
'unknown_http_version': 'reject'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_explicit.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ftp-incoming-port': 'test_value_3',
|
||||
'ftp-over-http': 'enable',
|
||||
'http-incoming-port': 'test_value_5',
|
||||
'https-incoming-port': 'test_value_6',
|
||||
'https-replacement-message': 'enable',
|
||||
'incoming-ip': 'test_value_8',
|
||||
'incoming-ip6': 'test_value_9',
|
||||
'ipv6-status': 'enable',
|
||||
'message-upon-server-error': 'enable',
|
||||
'outgoing-ip': 'test_value_12',
|
||||
'outgoing-ip6': 'test_value_13',
|
||||
'pac-file-data': 'test_value_14',
|
||||
'pac-file-name': 'test_value_15',
|
||||
'pac-file-server-port': 'test_value_16',
|
||||
'pac-file-server-status': 'enable',
|
||||
'pac-file-url': 'test_value_18',
|
||||
'pref-dns-result': 'ipv4',
|
||||
'realm': 'test_value_20',
|
||||
'sec-default-action': 'accept',
|
||||
'socks': 'enable',
|
||||
'socks-incoming-port': 'test_value_23',
|
||||
'ssl-algorithm': 'low',
|
||||
'status': 'enable',
|
||||
'strict-guest': 'enable',
|
||||
'trace-auth-no-rsp': 'enable',
|
||||
'unknown-http-version': 'reject'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('web-proxy', 'explicit', 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_web_proxy_explicit_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',
|
||||
'web_proxy_explicit': {
|
||||
'ftp_incoming_port': 'test_value_3',
|
||||
'ftp_over_http': 'enable',
|
||||
'http_incoming_port': 'test_value_5',
|
||||
'https_incoming_port': 'test_value_6',
|
||||
'https_replacement_message': 'enable',
|
||||
'incoming_ip': 'test_value_8',
|
||||
'incoming_ip6': 'test_value_9',
|
||||
'ipv6_status': 'enable',
|
||||
'message_upon_server_error': 'enable',
|
||||
'outgoing_ip': 'test_value_12',
|
||||
'outgoing_ip6': 'test_value_13',
|
||||
'pac_file_data': 'test_value_14',
|
||||
'pac_file_name': 'test_value_15',
|
||||
'pac_file_server_port': 'test_value_16',
|
||||
'pac_file_server_status': 'enable',
|
||||
'pac_file_url': 'test_value_18',
|
||||
'pref_dns_result': 'ipv4',
|
||||
'realm': 'test_value_20',
|
||||
'sec_default_action': 'accept',
|
||||
'socks': 'enable',
|
||||
'socks_incoming_port': 'test_value_23',
|
||||
'ssl_algorithm': 'low',
|
||||
'status': 'enable',
|
||||
'strict_guest': 'enable',
|
||||
'trace_auth_no_rsp': 'enable',
|
||||
'unknown_http_version': 'reject'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_explicit.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ftp-incoming-port': 'test_value_3',
|
||||
'ftp-over-http': 'enable',
|
||||
'http-incoming-port': 'test_value_5',
|
||||
'https-incoming-port': 'test_value_6',
|
||||
'https-replacement-message': 'enable',
|
||||
'incoming-ip': 'test_value_8',
|
||||
'incoming-ip6': 'test_value_9',
|
||||
'ipv6-status': 'enable',
|
||||
'message-upon-server-error': 'enable',
|
||||
'outgoing-ip': 'test_value_12',
|
||||
'outgoing-ip6': 'test_value_13',
|
||||
'pac-file-data': 'test_value_14',
|
||||
'pac-file-name': 'test_value_15',
|
||||
'pac-file-server-port': 'test_value_16',
|
||||
'pac-file-server-status': 'enable',
|
||||
'pac-file-url': 'test_value_18',
|
||||
'pref-dns-result': 'ipv4',
|
||||
'realm': 'test_value_20',
|
||||
'sec-default-action': 'accept',
|
||||
'socks': 'enable',
|
||||
'socks-incoming-port': 'test_value_23',
|
||||
'ssl-algorithm': 'low',
|
||||
'status': 'enable',
|
||||
'strict-guest': 'enable',
|
||||
'trace-auth-no-rsp': 'enable',
|
||||
'unknown-http-version': 'reject'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('web-proxy', 'explicit', 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_web_proxy_explicit_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',
|
||||
'web_proxy_explicit': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'ftp_incoming_port': 'test_value_3',
|
||||
'ftp_over_http': 'enable',
|
||||
'http_incoming_port': 'test_value_5',
|
||||
'https_incoming_port': 'test_value_6',
|
||||
'https_replacement_message': 'enable',
|
||||
'incoming_ip': 'test_value_8',
|
||||
'incoming_ip6': 'test_value_9',
|
||||
'ipv6_status': 'enable',
|
||||
'message_upon_server_error': 'enable',
|
||||
'outgoing_ip': 'test_value_12',
|
||||
'outgoing_ip6': 'test_value_13',
|
||||
'pac_file_data': 'test_value_14',
|
||||
'pac_file_name': 'test_value_15',
|
||||
'pac_file_server_port': 'test_value_16',
|
||||
'pac_file_server_status': 'enable',
|
||||
'pac_file_url': 'test_value_18',
|
||||
'pref_dns_result': 'ipv4',
|
||||
'realm': 'test_value_20',
|
||||
'sec_default_action': 'accept',
|
||||
'socks': 'enable',
|
||||
'socks_incoming_port': 'test_value_23',
|
||||
'ssl_algorithm': 'low',
|
||||
'status': 'enable',
|
||||
'strict_guest': 'enable',
|
||||
'trace_auth_no_rsp': 'enable',
|
||||
'unknown_http_version': 'reject'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_explicit.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ftp-incoming-port': 'test_value_3',
|
||||
'ftp-over-http': 'enable',
|
||||
'http-incoming-port': 'test_value_5',
|
||||
'https-incoming-port': 'test_value_6',
|
||||
'https-replacement-message': 'enable',
|
||||
'incoming-ip': 'test_value_8',
|
||||
'incoming-ip6': 'test_value_9',
|
||||
'ipv6-status': 'enable',
|
||||
'message-upon-server-error': 'enable',
|
||||
'outgoing-ip': 'test_value_12',
|
||||
'outgoing-ip6': 'test_value_13',
|
||||
'pac-file-data': 'test_value_14',
|
||||
'pac-file-name': 'test_value_15',
|
||||
'pac-file-server-port': 'test_value_16',
|
||||
'pac-file-server-status': 'enable',
|
||||
'pac-file-url': 'test_value_18',
|
||||
'pref-dns-result': 'ipv4',
|
||||
'realm': 'test_value_20',
|
||||
'sec-default-action': 'accept',
|
||||
'socks': 'enable',
|
||||
'socks-incoming-port': 'test_value_23',
|
||||
'ssl-algorithm': 'low',
|
||||
'status': 'enable',
|
||||
'strict-guest': 'enable',
|
||||
'trace-auth-no-rsp': 'enable',
|
||||
'unknown-http-version': 'reject'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('web-proxy', 'explicit', 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,247 @@
|
||||
# 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_web_proxy_global
|
||||
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_web_proxy_global.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_web_proxy_global_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',
|
||||
'web_proxy_global': {
|
||||
'fast_policy_match': 'enable',
|
||||
'forward_proxy_auth': 'enable',
|
||||
'forward_server_affinity_timeout': '5',
|
||||
'learn_client_ip': 'enable',
|
||||
'learn_client_ip_from_header': 'true-client-ip',
|
||||
'max_message_length': '8',
|
||||
'max_request_length': '9',
|
||||
'max_waf_body_cache_length': '10',
|
||||
'proxy_fqdn': 'test_value_11',
|
||||
'strict_web_check': 'enable',
|
||||
'tunnel_non_http': 'enable',
|
||||
'unknown_http_version': 'reject',
|
||||
'webproxy_profile': 'test_value_15'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_global.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'fast-policy-match': 'enable',
|
||||
'forward-proxy-auth': 'enable',
|
||||
'forward-server-affinity-timeout': '5',
|
||||
'learn-client-ip': 'enable',
|
||||
'learn-client-ip-from-header': 'true-client-ip',
|
||||
'max-message-length': '8',
|
||||
'max-request-length': '9',
|
||||
'max-waf-body-cache-length': '10',
|
||||
'proxy-fqdn': 'test_value_11',
|
||||
'strict-web-check': 'enable',
|
||||
'tunnel-non-http': 'enable',
|
||||
'unknown-http-version': 'reject',
|
||||
'webproxy-profile': 'test_value_15'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('web-proxy', 'global', 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_web_proxy_global_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',
|
||||
'web_proxy_global': {
|
||||
'fast_policy_match': 'enable',
|
||||
'forward_proxy_auth': 'enable',
|
||||
'forward_server_affinity_timeout': '5',
|
||||
'learn_client_ip': 'enable',
|
||||
'learn_client_ip_from_header': 'true-client-ip',
|
||||
'max_message_length': '8',
|
||||
'max_request_length': '9',
|
||||
'max_waf_body_cache_length': '10',
|
||||
'proxy_fqdn': 'test_value_11',
|
||||
'strict_web_check': 'enable',
|
||||
'tunnel_non_http': 'enable',
|
||||
'unknown_http_version': 'reject',
|
||||
'webproxy_profile': 'test_value_15'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_global.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'fast-policy-match': 'enable',
|
||||
'forward-proxy-auth': 'enable',
|
||||
'forward-server-affinity-timeout': '5',
|
||||
'learn-client-ip': 'enable',
|
||||
'learn-client-ip-from-header': 'true-client-ip',
|
||||
'max-message-length': '8',
|
||||
'max-request-length': '9',
|
||||
'max-waf-body-cache-length': '10',
|
||||
'proxy-fqdn': 'test_value_11',
|
||||
'strict-web-check': 'enable',
|
||||
'tunnel-non-http': 'enable',
|
||||
'unknown-http-version': 'reject',
|
||||
'webproxy-profile': 'test_value_15'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('web-proxy', 'global', 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_web_proxy_global_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',
|
||||
'web_proxy_global': {
|
||||
'fast_policy_match': 'enable',
|
||||
'forward_proxy_auth': 'enable',
|
||||
'forward_server_affinity_timeout': '5',
|
||||
'learn_client_ip': 'enable',
|
||||
'learn_client_ip_from_header': 'true-client-ip',
|
||||
'max_message_length': '8',
|
||||
'max_request_length': '9',
|
||||
'max_waf_body_cache_length': '10',
|
||||
'proxy_fqdn': 'test_value_11',
|
||||
'strict_web_check': 'enable',
|
||||
'tunnel_non_http': 'enable',
|
||||
'unknown_http_version': 'reject',
|
||||
'webproxy_profile': 'test_value_15'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_global.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'fast-policy-match': 'enable',
|
||||
'forward-proxy-auth': 'enable',
|
||||
'forward-server-affinity-timeout': '5',
|
||||
'learn-client-ip': 'enable',
|
||||
'learn-client-ip-from-header': 'true-client-ip',
|
||||
'max-message-length': '8',
|
||||
'max-request-length': '9',
|
||||
'max-waf-body-cache-length': '10',
|
||||
'proxy-fqdn': 'test_value_11',
|
||||
'strict-web-check': 'enable',
|
||||
'tunnel-non-http': 'enable',
|
||||
'unknown-http-version': 'reject',
|
||||
'webproxy-profile': 'test_value_15'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('web-proxy', 'global', 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_web_proxy_global_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',
|
||||
'web_proxy_global': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'fast_policy_match': 'enable',
|
||||
'forward_proxy_auth': 'enable',
|
||||
'forward_server_affinity_timeout': '5',
|
||||
'learn_client_ip': 'enable',
|
||||
'learn_client_ip_from_header': 'true-client-ip',
|
||||
'max_message_length': '8',
|
||||
'max_request_length': '9',
|
||||
'max_waf_body_cache_length': '10',
|
||||
'proxy_fqdn': 'test_value_11',
|
||||
'strict_web_check': 'enable',
|
||||
'tunnel_non_http': 'enable',
|
||||
'unknown_http_version': 'reject',
|
||||
'webproxy_profile': 'test_value_15'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_global.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'fast-policy-match': 'enable',
|
||||
'forward-proxy-auth': 'enable',
|
||||
'forward-server-affinity-timeout': '5',
|
||||
'learn-client-ip': 'enable',
|
||||
'learn-client-ip-from-header': 'true-client-ip',
|
||||
'max-message-length': '8',
|
||||
'max-request-length': '9',
|
||||
'max-waf-body-cache-length': '10',
|
||||
'proxy-fqdn': 'test_value_11',
|
||||
'strict-web-check': 'enable',
|
||||
'tunnel-non-http': 'enable',
|
||||
'unknown-http-version': 'reject',
|
||||
'webproxy-profile': 'test_value_15'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('web-proxy', 'global', 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_web_proxy_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_web_proxy_profile.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_web_proxy_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',
|
||||
'web_proxy_profile': {
|
||||
'header_client_ip': 'pass',
|
||||
'header_front_end_https': 'pass',
|
||||
'header_via_request': 'pass',
|
||||
'header_via_response': 'pass',
|
||||
'header_x_authenticated_groups': 'pass',
|
||||
'header_x_authenticated_user': 'pass',
|
||||
'header_x_forwarded_for': 'pass',
|
||||
'log_header_change': 'enable',
|
||||
'name': 'default_name_11',
|
||||
'strip_encoding': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_profile.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'header-client-ip': 'pass',
|
||||
'header-front-end-https': 'pass',
|
||||
'header-via-request': 'pass',
|
||||
'header-via-response': 'pass',
|
||||
'header-x-authenticated-groups': 'pass',
|
||||
'header-x-authenticated-user': 'pass',
|
||||
'header-x-forwarded-for': 'pass',
|
||||
'log-header-change': 'enable',
|
||||
'name': 'default_name_11',
|
||||
'strip-encoding': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('web-proxy', '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_web_proxy_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',
|
||||
'web_proxy_profile': {
|
||||
'header_client_ip': 'pass',
|
||||
'header_front_end_https': 'pass',
|
||||
'header_via_request': 'pass',
|
||||
'header_via_response': 'pass',
|
||||
'header_x_authenticated_groups': 'pass',
|
||||
'header_x_authenticated_user': 'pass',
|
||||
'header_x_forwarded_for': 'pass',
|
||||
'log_header_change': 'enable',
|
||||
'name': 'default_name_11',
|
||||
'strip_encoding': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_profile.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'header-client-ip': 'pass',
|
||||
'header-front-end-https': 'pass',
|
||||
'header-via-request': 'pass',
|
||||
'header-via-response': 'pass',
|
||||
'header-x-authenticated-groups': 'pass',
|
||||
'header-x-authenticated-user': 'pass',
|
||||
'header-x-forwarded-for': 'pass',
|
||||
'log-header-change': 'enable',
|
||||
'name': 'default_name_11',
|
||||
'strip-encoding': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('web-proxy', '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_web_proxy_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',
|
||||
'web_proxy_profile': {
|
||||
'header_client_ip': 'pass',
|
||||
'header_front_end_https': 'pass',
|
||||
'header_via_request': 'pass',
|
||||
'header_via_response': 'pass',
|
||||
'header_x_authenticated_groups': 'pass',
|
||||
'header_x_authenticated_user': 'pass',
|
||||
'header_x_forwarded_for': 'pass',
|
||||
'log_header_change': 'enable',
|
||||
'name': 'default_name_11',
|
||||
'strip_encoding': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_profile.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('web-proxy', '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_web_proxy_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',
|
||||
'web_proxy_profile': {
|
||||
'header_client_ip': 'pass',
|
||||
'header_front_end_https': 'pass',
|
||||
'header_via_request': 'pass',
|
||||
'header_via_response': 'pass',
|
||||
'header_x_authenticated_groups': 'pass',
|
||||
'header_x_authenticated_user': 'pass',
|
||||
'header_x_forwarded_for': 'pass',
|
||||
'log_header_change': 'enable',
|
||||
'name': 'default_name_11',
|
||||
'strip_encoding': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_profile.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('web-proxy', '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_web_proxy_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',
|
||||
'web_proxy_profile': {
|
||||
'header_client_ip': 'pass',
|
||||
'header_front_end_https': 'pass',
|
||||
'header_via_request': 'pass',
|
||||
'header_via_response': 'pass',
|
||||
'header_x_authenticated_groups': 'pass',
|
||||
'header_x_authenticated_user': 'pass',
|
||||
'header_x_forwarded_for': 'pass',
|
||||
'log_header_change': 'enable',
|
||||
'name': 'default_name_11',
|
||||
'strip_encoding': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_profile.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'header-client-ip': 'pass',
|
||||
'header-front-end-https': 'pass',
|
||||
'header-via-request': 'pass',
|
||||
'header-via-response': 'pass',
|
||||
'header-x-authenticated-groups': 'pass',
|
||||
'header-x-authenticated-user': 'pass',
|
||||
'header-x-forwarded-for': 'pass',
|
||||
'log-header-change': 'enable',
|
||||
'name': 'default_name_11',
|
||||
'strip-encoding': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('web-proxy', '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_web_proxy_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',
|
||||
'web_proxy_profile': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'header_client_ip': 'pass',
|
||||
'header_front_end_https': 'pass',
|
||||
'header_via_request': 'pass',
|
||||
'header_via_response': 'pass',
|
||||
'header_x_authenticated_groups': 'pass',
|
||||
'header_x_authenticated_user': 'pass',
|
||||
'header_x_forwarded_for': 'pass',
|
||||
'log_header_change': 'enable',
|
||||
'name': 'default_name_11',
|
||||
'strip_encoding': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_web_proxy_profile.fortios_web_proxy(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'header-client-ip': 'pass',
|
||||
'header-front-end-https': 'pass',
|
||||
'header-via-request': 'pass',
|
||||
'header-via-response': 'pass',
|
||||
'header-x-authenticated-groups': 'pass',
|
||||
'header-x-authenticated-user': 'pass',
|
||||
'header-x-forwarded-for': 'pass',
|
||||
'log-header-change': 'enable',
|
||||
'name': 'default_name_11',
|
||||
'strip-encoding': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('web-proxy', '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_webfilter_fortiguard
|
||||
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_webfilter_fortiguard.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_webfilter_fortiguard_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',
|
||||
'webfilter_fortiguard': {
|
||||
'cache_mem_percent': '3',
|
||||
'cache_mode': 'ttl',
|
||||
'cache_prefix_match': 'enable',
|
||||
'close_ports': 'enable',
|
||||
'ovrd_auth_https': 'enable',
|
||||
'ovrd_auth_port': '8',
|
||||
'ovrd_auth_port_http': '9',
|
||||
'ovrd_auth_port_https': '10',
|
||||
'ovrd_auth_port_warning': '11',
|
||||
'request_packet_size_limit': '12',
|
||||
'warn_auth_https': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_fortiguard.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'cache-mem-percent': '3',
|
||||
'cache-mode': 'ttl',
|
||||
'cache-prefix-match': 'enable',
|
||||
'close-ports': 'enable',
|
||||
'ovrd-auth-https': 'enable',
|
||||
'ovrd-auth-port': '8',
|
||||
'ovrd-auth-port-http': '9',
|
||||
'ovrd-auth-port-https': '10',
|
||||
'ovrd-auth-port-warning': '11',
|
||||
'request-packet-size-limit': '12',
|
||||
'warn-auth-https': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'fortiguard', 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_webfilter_fortiguard_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',
|
||||
'webfilter_fortiguard': {
|
||||
'cache_mem_percent': '3',
|
||||
'cache_mode': 'ttl',
|
||||
'cache_prefix_match': 'enable',
|
||||
'close_ports': 'enable',
|
||||
'ovrd_auth_https': 'enable',
|
||||
'ovrd_auth_port': '8',
|
||||
'ovrd_auth_port_http': '9',
|
||||
'ovrd_auth_port_https': '10',
|
||||
'ovrd_auth_port_warning': '11',
|
||||
'request_packet_size_limit': '12',
|
||||
'warn_auth_https': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_fortiguard.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'cache-mem-percent': '3',
|
||||
'cache-mode': 'ttl',
|
||||
'cache-prefix-match': 'enable',
|
||||
'close-ports': 'enable',
|
||||
'ovrd-auth-https': 'enable',
|
||||
'ovrd-auth-port': '8',
|
||||
'ovrd-auth-port-http': '9',
|
||||
'ovrd-auth-port-https': '10',
|
||||
'ovrd-auth-port-warning': '11',
|
||||
'request-packet-size-limit': '12',
|
||||
'warn-auth-https': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'fortiguard', 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_webfilter_fortiguard_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',
|
||||
'webfilter_fortiguard': {
|
||||
'cache_mem_percent': '3',
|
||||
'cache_mode': 'ttl',
|
||||
'cache_prefix_match': 'enable',
|
||||
'close_ports': 'enable',
|
||||
'ovrd_auth_https': 'enable',
|
||||
'ovrd_auth_port': '8',
|
||||
'ovrd_auth_port_http': '9',
|
||||
'ovrd_auth_port_https': '10',
|
||||
'ovrd_auth_port_warning': '11',
|
||||
'request_packet_size_limit': '12',
|
||||
'warn_auth_https': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_fortiguard.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'cache-mem-percent': '3',
|
||||
'cache-mode': 'ttl',
|
||||
'cache-prefix-match': 'enable',
|
||||
'close-ports': 'enable',
|
||||
'ovrd-auth-https': 'enable',
|
||||
'ovrd-auth-port': '8',
|
||||
'ovrd-auth-port-http': '9',
|
||||
'ovrd-auth-port-https': '10',
|
||||
'ovrd-auth-port-warning': '11',
|
||||
'request-packet-size-limit': '12',
|
||||
'warn-auth-https': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'fortiguard', 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_webfilter_fortiguard_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',
|
||||
'webfilter_fortiguard': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'cache_mem_percent': '3',
|
||||
'cache_mode': 'ttl',
|
||||
'cache_prefix_match': 'enable',
|
||||
'close_ports': 'enable',
|
||||
'ovrd_auth_https': 'enable',
|
||||
'ovrd_auth_port': '8',
|
||||
'ovrd_auth_port_http': '9',
|
||||
'ovrd_auth_port_https': '10',
|
||||
'ovrd_auth_port_warning': '11',
|
||||
'request_packet_size_limit': '12',
|
||||
'warn_auth_https': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_fortiguard.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'cache-mem-percent': '3',
|
||||
'cache-mode': 'ttl',
|
||||
'cache-prefix-match': 'enable',
|
||||
'close-ports': 'enable',
|
||||
'ovrd-auth-https': 'enable',
|
||||
'ovrd-auth-port': '8',
|
||||
'ovrd-auth-port-http': '9',
|
||||
'ovrd-auth-port-https': '10',
|
||||
'ovrd-auth-port-warning': '11',
|
||||
'request-packet-size-limit': '12',
|
||||
'warn-auth-https': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'fortiguard', 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_webfilter_ftgd_local_cat
|
||||
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_webfilter_ftgd_local_cat.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_webfilter_ftgd_local_cat_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',
|
||||
'webfilter_ftgd_local_cat': {
|
||||
'desc': 'test_value_3',
|
||||
'id': '4',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ftgd_local_cat.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'desc': 'test_value_3',
|
||||
'id': '4',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ftgd-local-cat', 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_webfilter_ftgd_local_cat_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',
|
||||
'webfilter_ftgd_local_cat': {
|
||||
'desc': 'test_value_3',
|
||||
'id': '4',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ftgd_local_cat.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'desc': 'test_value_3',
|
||||
'id': '4',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ftgd-local-cat', 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_webfilter_ftgd_local_cat_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',
|
||||
'webfilter_ftgd_local_cat': {
|
||||
'desc': 'test_value_3',
|
||||
'id': '4',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ftgd_local_cat.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('webfilter', 'ftgd-local-cat', 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_webfilter_ftgd_local_cat_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',
|
||||
'webfilter_ftgd_local_cat': {
|
||||
'desc': 'test_value_3',
|
||||
'id': '4',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ftgd_local_cat.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('webfilter', 'ftgd-local-cat', 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_webfilter_ftgd_local_cat_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',
|
||||
'webfilter_ftgd_local_cat': {
|
||||
'desc': 'test_value_3',
|
||||
'id': '4',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ftgd_local_cat.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'desc': 'test_value_3',
|
||||
'id': '4',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ftgd-local-cat', 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_webfilter_ftgd_local_cat_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',
|
||||
'webfilter_ftgd_local_cat': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'desc': 'test_value_3',
|
||||
'id': '4',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ftgd_local_cat.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'desc': 'test_value_3',
|
||||
'id': '4',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ftgd-local-cat', 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_webfilter_ftgd_local_rating
|
||||
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_webfilter_ftgd_local_rating.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_webfilter_ftgd_local_rating_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',
|
||||
'webfilter_ftgd_local_rating': {
|
||||
'rating': 'test_value_3',
|
||||
'status': 'enable',
|
||||
'url': 'myurl_5.com'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ftgd_local_rating.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'rating': 'test_value_3',
|
||||
'status': 'enable',
|
||||
'url': 'myurl_5.com'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ftgd-local-rating', 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_webfilter_ftgd_local_rating_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',
|
||||
'webfilter_ftgd_local_rating': {
|
||||
'rating': 'test_value_3',
|
||||
'status': 'enable',
|
||||
'url': 'myurl_5.com'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ftgd_local_rating.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'rating': 'test_value_3',
|
||||
'status': 'enable',
|
||||
'url': 'myurl_5.com'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ftgd-local-rating', 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_webfilter_ftgd_local_rating_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',
|
||||
'webfilter_ftgd_local_rating': {
|
||||
'rating': 'test_value_3',
|
||||
'status': 'enable',
|
||||
'url': 'myurl_5.com'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ftgd_local_rating.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('webfilter', 'ftgd-local-rating', 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_webfilter_ftgd_local_rating_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',
|
||||
'webfilter_ftgd_local_rating': {
|
||||
'rating': 'test_value_3',
|
||||
'status': 'enable',
|
||||
'url': 'myurl_5.com'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ftgd_local_rating.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('webfilter', 'ftgd-local-rating', 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_webfilter_ftgd_local_rating_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',
|
||||
'webfilter_ftgd_local_rating': {
|
||||
'rating': 'test_value_3',
|
||||
'status': 'enable',
|
||||
'url': 'myurl_5.com'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ftgd_local_rating.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'rating': 'test_value_3',
|
||||
'status': 'enable',
|
||||
'url': 'myurl_5.com'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ftgd-local-rating', 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_webfilter_ftgd_local_rating_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',
|
||||
'webfilter_ftgd_local_rating': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'rating': 'test_value_3',
|
||||
'status': 'enable',
|
||||
'url': 'myurl_5.com'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ftgd_local_rating.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'rating': 'test_value_3',
|
||||
'status': 'enable',
|
||||
'url': 'myurl_5.com'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ftgd-local-rating', data=expected_data, vdom='root')
|
||||
schema_method_mock.assert_not_called()
|
||||
assert not is_error
|
||||
assert changed
|
||||
assert response['status'] == 'success'
|
||||
assert response['http_status'] == 200
|
@ -0,0 +1,159 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_webfilter_ips_urlfilter_cache_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_webfilter_ips_urlfilter_cache_setting.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_webfilter_ips_urlfilter_cache_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',
|
||||
'webfilter_ips_urlfilter_cache_setting': {
|
||||
'dns_retry_interval': '3',
|
||||
'extended_ttl': '4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ips_urlfilter_cache_setting.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'dns-retry-interval': '3',
|
||||
'extended-ttl': '4'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ips-urlfilter-cache-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_webfilter_ips_urlfilter_cache_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',
|
||||
'webfilter_ips_urlfilter_cache_setting': {
|
||||
'dns_retry_interval': '3',
|
||||
'extended_ttl': '4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ips_urlfilter_cache_setting.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'dns-retry-interval': '3',
|
||||
'extended-ttl': '4'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ips-urlfilter-cache-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_webfilter_ips_urlfilter_cache_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',
|
||||
'webfilter_ips_urlfilter_cache_setting': {
|
||||
'dns_retry_interval': '3',
|
||||
'extended_ttl': '4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ips_urlfilter_cache_setting.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'dns-retry-interval': '3',
|
||||
'extended-ttl': '4'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ips-urlfilter-cache-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_webfilter_ips_urlfilter_cache_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',
|
||||
'webfilter_ips_urlfilter_cache_setting': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'dns_retry_interval': '3',
|
||||
'extended_ttl': '4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ips_urlfilter_cache_setting.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'dns-retry-interval': '3',
|
||||
'extended-ttl': '4'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ips-urlfilter-cache-setting', data=expected_data, vdom='root')
|
||||
schema_method_mock.assert_not_called()
|
||||
assert not is_error
|
||||
assert changed
|
||||
assert response['status'] == 'success'
|
||||
assert response['http_status'] == 200
|
@ -0,0 +1,175 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_webfilter_ips_urlfilter_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_webfilter_ips_urlfilter_setting.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_webfilter_ips_urlfilter_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',
|
||||
'webfilter_ips_urlfilter_setting': {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway': 'test_value_5',
|
||||
'geo_filter': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ips_urlfilter_setting.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway': 'test_value_5',
|
||||
'geo-filter': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ips-urlfilter-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_webfilter_ips_urlfilter_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',
|
||||
'webfilter_ips_urlfilter_setting': {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway': 'test_value_5',
|
||||
'geo_filter': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ips_urlfilter_setting.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway': 'test_value_5',
|
||||
'geo-filter': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ips-urlfilter-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_webfilter_ips_urlfilter_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',
|
||||
'webfilter_ips_urlfilter_setting': {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway': 'test_value_5',
|
||||
'geo_filter': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ips_urlfilter_setting.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway': 'test_value_5',
|
||||
'geo-filter': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ips-urlfilter-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_webfilter_ips_urlfilter_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',
|
||||
'webfilter_ips_urlfilter_setting': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway': 'test_value_5',
|
||||
'geo_filter': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ips_urlfilter_setting.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway': 'test_value_5',
|
||||
'geo-filter': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ips-urlfilter-setting', data=expected_data, vdom='root')
|
||||
schema_method_mock.assert_not_called()
|
||||
assert not is_error
|
||||
assert changed
|
||||
assert response['status'] == 'success'
|
||||
assert response['http_status'] == 200
|
@ -0,0 +1,175 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_webfilter_ips_urlfilter_setting6
|
||||
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_webfilter_ips_urlfilter_setting6.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_webfilter_ips_urlfilter_setting6_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',
|
||||
'webfilter_ips_urlfilter_setting6': {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway6': 'test_value_5',
|
||||
'geo_filter': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ips_urlfilter_setting6.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway6': 'test_value_5',
|
||||
'geo-filter': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ips-urlfilter-setting6', 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_webfilter_ips_urlfilter_setting6_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',
|
||||
'webfilter_ips_urlfilter_setting6': {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway6': 'test_value_5',
|
||||
'geo_filter': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ips_urlfilter_setting6.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway6': 'test_value_5',
|
||||
'geo-filter': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ips-urlfilter-setting6', 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_webfilter_ips_urlfilter_setting6_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',
|
||||
'webfilter_ips_urlfilter_setting6': {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway6': 'test_value_5',
|
||||
'geo_filter': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ips_urlfilter_setting6.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway6': 'test_value_5',
|
||||
'geo-filter': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ips-urlfilter-setting6', 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_webfilter_ips_urlfilter_setting6_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',
|
||||
'webfilter_ips_urlfilter_setting6': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway6': 'test_value_5',
|
||||
'geo_filter': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_ips_urlfilter_setting6.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'device': 'test_value_3',
|
||||
'distance': '4',
|
||||
'gateway6': 'test_value_5',
|
||||
'geo-filter': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'ips-urlfilter-setting6', 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,299 @@
|
||||
# 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_webfilter_override
|
||||
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_webfilter_override.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_webfilter_override_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',
|
||||
'webfilter_override': {
|
||||
'expires': 'test_value_3',
|
||||
'id': '4',
|
||||
'initiator': 'test_value_5',
|
||||
'ip': 'test_value_6',
|
||||
'ip6': 'test_value_7',
|
||||
'new_profile': 'test_value_8',
|
||||
'old_profile': 'test_value_9',
|
||||
'scope': 'user',
|
||||
'status': 'enable',
|
||||
'user': 'test_value_12',
|
||||
'user_group': 'test_value_13'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_override.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'expires': 'test_value_3',
|
||||
'id': '4',
|
||||
'initiator': 'test_value_5',
|
||||
'ip': 'test_value_6',
|
||||
'ip6': 'test_value_7',
|
||||
'new-profile': 'test_value_8',
|
||||
'old-profile': 'test_value_9',
|
||||
'scope': 'user',
|
||||
'status': 'enable',
|
||||
'user': 'test_value_12',
|
||||
'user-group': 'test_value_13'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'override', 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_webfilter_override_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',
|
||||
'webfilter_override': {
|
||||
'expires': 'test_value_3',
|
||||
'id': '4',
|
||||
'initiator': 'test_value_5',
|
||||
'ip': 'test_value_6',
|
||||
'ip6': 'test_value_7',
|
||||
'new_profile': 'test_value_8',
|
||||
'old_profile': 'test_value_9',
|
||||
'scope': 'user',
|
||||
'status': 'enable',
|
||||
'user': 'test_value_12',
|
||||
'user_group': 'test_value_13'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_override.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'expires': 'test_value_3',
|
||||
'id': '4',
|
||||
'initiator': 'test_value_5',
|
||||
'ip': 'test_value_6',
|
||||
'ip6': 'test_value_7',
|
||||
'new-profile': 'test_value_8',
|
||||
'old-profile': 'test_value_9',
|
||||
'scope': 'user',
|
||||
'status': 'enable',
|
||||
'user': 'test_value_12',
|
||||
'user-group': 'test_value_13'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'override', 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_webfilter_override_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',
|
||||
'webfilter_override': {
|
||||
'expires': 'test_value_3',
|
||||
'id': '4',
|
||||
'initiator': 'test_value_5',
|
||||
'ip': 'test_value_6',
|
||||
'ip6': 'test_value_7',
|
||||
'new_profile': 'test_value_8',
|
||||
'old_profile': 'test_value_9',
|
||||
'scope': 'user',
|
||||
'status': 'enable',
|
||||
'user': 'test_value_12',
|
||||
'user_group': 'test_value_13'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_override.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('webfilter', 'override', 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_webfilter_override_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',
|
||||
'webfilter_override': {
|
||||
'expires': 'test_value_3',
|
||||
'id': '4',
|
||||
'initiator': 'test_value_5',
|
||||
'ip': 'test_value_6',
|
||||
'ip6': 'test_value_7',
|
||||
'new_profile': 'test_value_8',
|
||||
'old_profile': 'test_value_9',
|
||||
'scope': 'user',
|
||||
'status': 'enable',
|
||||
'user': 'test_value_12',
|
||||
'user_group': 'test_value_13'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_override.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('webfilter', 'override', 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_webfilter_override_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',
|
||||
'webfilter_override': {
|
||||
'expires': 'test_value_3',
|
||||
'id': '4',
|
||||
'initiator': 'test_value_5',
|
||||
'ip': 'test_value_6',
|
||||
'ip6': 'test_value_7',
|
||||
'new_profile': 'test_value_8',
|
||||
'old_profile': 'test_value_9',
|
||||
'scope': 'user',
|
||||
'status': 'enable',
|
||||
'user': 'test_value_12',
|
||||
'user_group': 'test_value_13'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_override.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'expires': 'test_value_3',
|
||||
'id': '4',
|
||||
'initiator': 'test_value_5',
|
||||
'ip': 'test_value_6',
|
||||
'ip6': 'test_value_7',
|
||||
'new-profile': 'test_value_8',
|
||||
'old-profile': 'test_value_9',
|
||||
'scope': 'user',
|
||||
'status': 'enable',
|
||||
'user': 'test_value_12',
|
||||
'user-group': 'test_value_13'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'override', 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_webfilter_override_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',
|
||||
'webfilter_override': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'expires': 'test_value_3',
|
||||
'id': '4',
|
||||
'initiator': 'test_value_5',
|
||||
'ip': 'test_value_6',
|
||||
'ip6': 'test_value_7',
|
||||
'new_profile': 'test_value_8',
|
||||
'old_profile': 'test_value_9',
|
||||
'scope': 'user',
|
||||
'status': 'enable',
|
||||
'user': 'test_value_12',
|
||||
'user_group': 'test_value_13'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_override.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'expires': 'test_value_3',
|
||||
'id': '4',
|
||||
'initiator': 'test_value_5',
|
||||
'ip': 'test_value_6',
|
||||
'ip6': 'test_value_7',
|
||||
'new-profile': 'test_value_8',
|
||||
'old-profile': 'test_value_9',
|
||||
'scope': 'user',
|
||||
'status': 'enable',
|
||||
'user': 'test_value_12',
|
||||
'user-group': 'test_value_13'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'override', 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,479 @@
|
||||
# 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_webfilter_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_webfilter_profile.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_webfilter_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',
|
||||
'webfilter_profile': {
|
||||
'comment': 'Optional comments.',
|
||||
'extended_log': 'enable',
|
||||
'https_replacemsg': 'enable',
|
||||
'inspection_mode': 'proxy',
|
||||
'log_all_url': 'enable',
|
||||
'name': 'default_name_8',
|
||||
'options': 'activexfilter',
|
||||
'ovrd_perm': 'bannedword-override',
|
||||
'post_action': 'normal',
|
||||
'replacemsg_group': 'test_value_12',
|
||||
'web_content_log': 'enable',
|
||||
'web_extended_all_action_log': 'enable',
|
||||
'web_filter_activex_log': 'enable',
|
||||
'web_filter_applet_log': 'enable',
|
||||
'web_filter_command_block_log': 'enable',
|
||||
'web_filter_cookie_log': 'enable',
|
||||
'web_filter_cookie_removal_log': 'enable',
|
||||
'web_filter_js_log': 'enable',
|
||||
'web_filter_jscript_log': 'enable',
|
||||
'web_filter_referer_log': 'enable',
|
||||
'web_filter_unknown_log': 'enable',
|
||||
'web_filter_vbs_log': 'enable',
|
||||
'web_ftgd_err_log': 'enable',
|
||||
'web_ftgd_quota_usage': 'enable',
|
||||
'web_invalid_domain_log': 'enable',
|
||||
'web_url_log': 'enable',
|
||||
'wisp': 'enable',
|
||||
'wisp_algorithm': 'primary-secondary',
|
||||
'youtube_channel_status': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_profile.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Optional comments.',
|
||||
'extended-log': 'enable',
|
||||
'https-replacemsg': 'enable',
|
||||
'inspection-mode': 'proxy',
|
||||
'log-all-url': 'enable',
|
||||
'name': 'default_name_8',
|
||||
'options': 'activexfilter',
|
||||
'ovrd-perm': 'bannedword-override',
|
||||
'post-action': 'normal',
|
||||
'replacemsg-group': 'test_value_12',
|
||||
'web-content-log': 'enable',
|
||||
'web-extended-all-action-log': 'enable',
|
||||
'web-filter-activex-log': 'enable',
|
||||
'web-filter-applet-log': 'enable',
|
||||
'web-filter-command-block-log': 'enable',
|
||||
'web-filter-cookie-log': 'enable',
|
||||
'web-filter-cookie-removal-log': 'enable',
|
||||
'web-filter-js-log': 'enable',
|
||||
'web-filter-jscript-log': 'enable',
|
||||
'web-filter-referer-log': 'enable',
|
||||
'web-filter-unknown-log': 'enable',
|
||||
'web-filter-vbs-log': 'enable',
|
||||
'web-ftgd-err-log': 'enable',
|
||||
'web-ftgd-quota-usage': 'enable',
|
||||
'web-invalid-domain-log': 'enable',
|
||||
'web-url-log': 'enable',
|
||||
'wisp': 'enable',
|
||||
'wisp-algorithm': 'primary-secondary',
|
||||
'youtube-channel-status': 'disable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', '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_webfilter_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',
|
||||
'webfilter_profile': {
|
||||
'comment': 'Optional comments.',
|
||||
'extended_log': 'enable',
|
||||
'https_replacemsg': 'enable',
|
||||
'inspection_mode': 'proxy',
|
||||
'log_all_url': 'enable',
|
||||
'name': 'default_name_8',
|
||||
'options': 'activexfilter',
|
||||
'ovrd_perm': 'bannedword-override',
|
||||
'post_action': 'normal',
|
||||
'replacemsg_group': 'test_value_12',
|
||||
'web_content_log': 'enable',
|
||||
'web_extended_all_action_log': 'enable',
|
||||
'web_filter_activex_log': 'enable',
|
||||
'web_filter_applet_log': 'enable',
|
||||
'web_filter_command_block_log': 'enable',
|
||||
'web_filter_cookie_log': 'enable',
|
||||
'web_filter_cookie_removal_log': 'enable',
|
||||
'web_filter_js_log': 'enable',
|
||||
'web_filter_jscript_log': 'enable',
|
||||
'web_filter_referer_log': 'enable',
|
||||
'web_filter_unknown_log': 'enable',
|
||||
'web_filter_vbs_log': 'enable',
|
||||
'web_ftgd_err_log': 'enable',
|
||||
'web_ftgd_quota_usage': 'enable',
|
||||
'web_invalid_domain_log': 'enable',
|
||||
'web_url_log': 'enable',
|
||||
'wisp': 'enable',
|
||||
'wisp_algorithm': 'primary-secondary',
|
||||
'youtube_channel_status': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_profile.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Optional comments.',
|
||||
'extended-log': 'enable',
|
||||
'https-replacemsg': 'enable',
|
||||
'inspection-mode': 'proxy',
|
||||
'log-all-url': 'enable',
|
||||
'name': 'default_name_8',
|
||||
'options': 'activexfilter',
|
||||
'ovrd-perm': 'bannedword-override',
|
||||
'post-action': 'normal',
|
||||
'replacemsg-group': 'test_value_12',
|
||||
'web-content-log': 'enable',
|
||||
'web-extended-all-action-log': 'enable',
|
||||
'web-filter-activex-log': 'enable',
|
||||
'web-filter-applet-log': 'enable',
|
||||
'web-filter-command-block-log': 'enable',
|
||||
'web-filter-cookie-log': 'enable',
|
||||
'web-filter-cookie-removal-log': 'enable',
|
||||
'web-filter-js-log': 'enable',
|
||||
'web-filter-jscript-log': 'enable',
|
||||
'web-filter-referer-log': 'enable',
|
||||
'web-filter-unknown-log': 'enable',
|
||||
'web-filter-vbs-log': 'enable',
|
||||
'web-ftgd-err-log': 'enable',
|
||||
'web-ftgd-quota-usage': 'enable',
|
||||
'web-invalid-domain-log': 'enable',
|
||||
'web-url-log': 'enable',
|
||||
'wisp': 'enable',
|
||||
'wisp-algorithm': 'primary-secondary',
|
||||
'youtube-channel-status': 'disable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', '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_webfilter_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',
|
||||
'webfilter_profile': {
|
||||
'comment': 'Optional comments.',
|
||||
'extended_log': 'enable',
|
||||
'https_replacemsg': 'enable',
|
||||
'inspection_mode': 'proxy',
|
||||
'log_all_url': 'enable',
|
||||
'name': 'default_name_8',
|
||||
'options': 'activexfilter',
|
||||
'ovrd_perm': 'bannedword-override',
|
||||
'post_action': 'normal',
|
||||
'replacemsg_group': 'test_value_12',
|
||||
'web_content_log': 'enable',
|
||||
'web_extended_all_action_log': 'enable',
|
||||
'web_filter_activex_log': 'enable',
|
||||
'web_filter_applet_log': 'enable',
|
||||
'web_filter_command_block_log': 'enable',
|
||||
'web_filter_cookie_log': 'enable',
|
||||
'web_filter_cookie_removal_log': 'enable',
|
||||
'web_filter_js_log': 'enable',
|
||||
'web_filter_jscript_log': 'enable',
|
||||
'web_filter_referer_log': 'enable',
|
||||
'web_filter_unknown_log': 'enable',
|
||||
'web_filter_vbs_log': 'enable',
|
||||
'web_ftgd_err_log': 'enable',
|
||||
'web_ftgd_quota_usage': 'enable',
|
||||
'web_invalid_domain_log': 'enable',
|
||||
'web_url_log': 'enable',
|
||||
'wisp': 'enable',
|
||||
'wisp_algorithm': 'primary-secondary',
|
||||
'youtube_channel_status': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_profile.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('webfilter', '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_webfilter_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',
|
||||
'webfilter_profile': {
|
||||
'comment': 'Optional comments.',
|
||||
'extended_log': 'enable',
|
||||
'https_replacemsg': 'enable',
|
||||
'inspection_mode': 'proxy',
|
||||
'log_all_url': 'enable',
|
||||
'name': 'default_name_8',
|
||||
'options': 'activexfilter',
|
||||
'ovrd_perm': 'bannedword-override',
|
||||
'post_action': 'normal',
|
||||
'replacemsg_group': 'test_value_12',
|
||||
'web_content_log': 'enable',
|
||||
'web_extended_all_action_log': 'enable',
|
||||
'web_filter_activex_log': 'enable',
|
||||
'web_filter_applet_log': 'enable',
|
||||
'web_filter_command_block_log': 'enable',
|
||||
'web_filter_cookie_log': 'enable',
|
||||
'web_filter_cookie_removal_log': 'enable',
|
||||
'web_filter_js_log': 'enable',
|
||||
'web_filter_jscript_log': 'enable',
|
||||
'web_filter_referer_log': 'enable',
|
||||
'web_filter_unknown_log': 'enable',
|
||||
'web_filter_vbs_log': 'enable',
|
||||
'web_ftgd_err_log': 'enable',
|
||||
'web_ftgd_quota_usage': 'enable',
|
||||
'web_invalid_domain_log': 'enable',
|
||||
'web_url_log': 'enable',
|
||||
'wisp': 'enable',
|
||||
'wisp_algorithm': 'primary-secondary',
|
||||
'youtube_channel_status': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_profile.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('webfilter', '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_webfilter_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',
|
||||
'webfilter_profile': {
|
||||
'comment': 'Optional comments.',
|
||||
'extended_log': 'enable',
|
||||
'https_replacemsg': 'enable',
|
||||
'inspection_mode': 'proxy',
|
||||
'log_all_url': 'enable',
|
||||
'name': 'default_name_8',
|
||||
'options': 'activexfilter',
|
||||
'ovrd_perm': 'bannedword-override',
|
||||
'post_action': 'normal',
|
||||
'replacemsg_group': 'test_value_12',
|
||||
'web_content_log': 'enable',
|
||||
'web_extended_all_action_log': 'enable',
|
||||
'web_filter_activex_log': 'enable',
|
||||
'web_filter_applet_log': 'enable',
|
||||
'web_filter_command_block_log': 'enable',
|
||||
'web_filter_cookie_log': 'enable',
|
||||
'web_filter_cookie_removal_log': 'enable',
|
||||
'web_filter_js_log': 'enable',
|
||||
'web_filter_jscript_log': 'enable',
|
||||
'web_filter_referer_log': 'enable',
|
||||
'web_filter_unknown_log': 'enable',
|
||||
'web_filter_vbs_log': 'enable',
|
||||
'web_ftgd_err_log': 'enable',
|
||||
'web_ftgd_quota_usage': 'enable',
|
||||
'web_invalid_domain_log': 'enable',
|
||||
'web_url_log': 'enable',
|
||||
'wisp': 'enable',
|
||||
'wisp_algorithm': 'primary-secondary',
|
||||
'youtube_channel_status': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_profile.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Optional comments.',
|
||||
'extended-log': 'enable',
|
||||
'https-replacemsg': 'enable',
|
||||
'inspection-mode': 'proxy',
|
||||
'log-all-url': 'enable',
|
||||
'name': 'default_name_8',
|
||||
'options': 'activexfilter',
|
||||
'ovrd-perm': 'bannedword-override',
|
||||
'post-action': 'normal',
|
||||
'replacemsg-group': 'test_value_12',
|
||||
'web-content-log': 'enable',
|
||||
'web-extended-all-action-log': 'enable',
|
||||
'web-filter-activex-log': 'enable',
|
||||
'web-filter-applet-log': 'enable',
|
||||
'web-filter-command-block-log': 'enable',
|
||||
'web-filter-cookie-log': 'enable',
|
||||
'web-filter-cookie-removal-log': 'enable',
|
||||
'web-filter-js-log': 'enable',
|
||||
'web-filter-jscript-log': 'enable',
|
||||
'web-filter-referer-log': 'enable',
|
||||
'web-filter-unknown-log': 'enable',
|
||||
'web-filter-vbs-log': 'enable',
|
||||
'web-ftgd-err-log': 'enable',
|
||||
'web-ftgd-quota-usage': 'enable',
|
||||
'web-invalid-domain-log': 'enable',
|
||||
'web-url-log': 'enable',
|
||||
'wisp': 'enable',
|
||||
'wisp-algorithm': 'primary-secondary',
|
||||
'youtube-channel-status': 'disable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', '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_webfilter_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',
|
||||
'webfilter_profile': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'comment': 'Optional comments.',
|
||||
'extended_log': 'enable',
|
||||
'https_replacemsg': 'enable',
|
||||
'inspection_mode': 'proxy',
|
||||
'log_all_url': 'enable',
|
||||
'name': 'default_name_8',
|
||||
'options': 'activexfilter',
|
||||
'ovrd_perm': 'bannedword-override',
|
||||
'post_action': 'normal',
|
||||
'replacemsg_group': 'test_value_12',
|
||||
'web_content_log': 'enable',
|
||||
'web_extended_all_action_log': 'enable',
|
||||
'web_filter_activex_log': 'enable',
|
||||
'web_filter_applet_log': 'enable',
|
||||
'web_filter_command_block_log': 'enable',
|
||||
'web_filter_cookie_log': 'enable',
|
||||
'web_filter_cookie_removal_log': 'enable',
|
||||
'web_filter_js_log': 'enable',
|
||||
'web_filter_jscript_log': 'enable',
|
||||
'web_filter_referer_log': 'enable',
|
||||
'web_filter_unknown_log': 'enable',
|
||||
'web_filter_vbs_log': 'enable',
|
||||
'web_ftgd_err_log': 'enable',
|
||||
'web_ftgd_quota_usage': 'enable',
|
||||
'web_invalid_domain_log': 'enable',
|
||||
'web_url_log': 'enable',
|
||||
'wisp': 'enable',
|
||||
'wisp_algorithm': 'primary-secondary',
|
||||
'youtube_channel_status': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_profile.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Optional comments.',
|
||||
'extended-log': 'enable',
|
||||
'https-replacemsg': 'enable',
|
||||
'inspection-mode': 'proxy',
|
||||
'log-all-url': 'enable',
|
||||
'name': 'default_name_8',
|
||||
'options': 'activexfilter',
|
||||
'ovrd-perm': 'bannedword-override',
|
||||
'post-action': 'normal',
|
||||
'replacemsg-group': 'test_value_12',
|
||||
'web-content-log': 'enable',
|
||||
'web-extended-all-action-log': 'enable',
|
||||
'web-filter-activex-log': 'enable',
|
||||
'web-filter-applet-log': 'enable',
|
||||
'web-filter-command-block-log': 'enable',
|
||||
'web-filter-cookie-log': 'enable',
|
||||
'web-filter-cookie-removal-log': 'enable',
|
||||
'web-filter-js-log': 'enable',
|
||||
'web-filter-jscript-log': 'enable',
|
||||
'web-filter-referer-log': 'enable',
|
||||
'web-filter-unknown-log': 'enable',
|
||||
'web-filter-vbs-log': 'enable',
|
||||
'web-ftgd-err-log': 'enable',
|
||||
'web-ftgd-quota-usage': 'enable',
|
||||
'web-invalid-domain-log': 'enable',
|
||||
'web-url-log': 'enable',
|
||||
'wisp': 'enable',
|
||||
'wisp-algorithm': 'primary-secondary',
|
||||
'youtube-channel-status': 'disable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', '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,259 @@
|
||||
# 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_webfilter_search_engine
|
||||
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_webfilter_search_engine.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_webfilter_search_engine_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',
|
||||
'webfilter_search_engine': {
|
||||
'charset': 'utf-8',
|
||||
'hostname': 'myhostname4',
|
||||
'name': 'default_name_5',
|
||||
'query': 'test_value_6',
|
||||
'safesearch': 'disable',
|
||||
'safesearch_str': 'test_value_8',
|
||||
'url': 'myurl_9.com'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_search_engine.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'charset': 'utf-8',
|
||||
'hostname': 'myhostname4',
|
||||
'name': 'default_name_5',
|
||||
'query': 'test_value_6',
|
||||
'safesearch': 'disable',
|
||||
'safesearch-str': 'test_value_8',
|
||||
'url': 'myurl_9.com'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'search-engine', 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_webfilter_search_engine_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',
|
||||
'webfilter_search_engine': {
|
||||
'charset': 'utf-8',
|
||||
'hostname': 'myhostname4',
|
||||
'name': 'default_name_5',
|
||||
'query': 'test_value_6',
|
||||
'safesearch': 'disable',
|
||||
'safesearch_str': 'test_value_8',
|
||||
'url': 'myurl_9.com'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_search_engine.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'charset': 'utf-8',
|
||||
'hostname': 'myhostname4',
|
||||
'name': 'default_name_5',
|
||||
'query': 'test_value_6',
|
||||
'safesearch': 'disable',
|
||||
'safesearch-str': 'test_value_8',
|
||||
'url': 'myurl_9.com'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'search-engine', 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_webfilter_search_engine_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',
|
||||
'webfilter_search_engine': {
|
||||
'charset': 'utf-8',
|
||||
'hostname': 'myhostname4',
|
||||
'name': 'default_name_5',
|
||||
'query': 'test_value_6',
|
||||
'safesearch': 'disable',
|
||||
'safesearch_str': 'test_value_8',
|
||||
'url': 'myurl_9.com'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_search_engine.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('webfilter', 'search-engine', 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_webfilter_search_engine_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',
|
||||
'webfilter_search_engine': {
|
||||
'charset': 'utf-8',
|
||||
'hostname': 'myhostname4',
|
||||
'name': 'default_name_5',
|
||||
'query': 'test_value_6',
|
||||
'safesearch': 'disable',
|
||||
'safesearch_str': 'test_value_8',
|
||||
'url': 'myurl_9.com'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_search_engine.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('webfilter', 'search-engine', 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_webfilter_search_engine_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',
|
||||
'webfilter_search_engine': {
|
||||
'charset': 'utf-8',
|
||||
'hostname': 'myhostname4',
|
||||
'name': 'default_name_5',
|
||||
'query': 'test_value_6',
|
||||
'safesearch': 'disable',
|
||||
'safesearch_str': 'test_value_8',
|
||||
'url': 'myurl_9.com'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_search_engine.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'charset': 'utf-8',
|
||||
'hostname': 'myhostname4',
|
||||
'name': 'default_name_5',
|
||||
'query': 'test_value_6',
|
||||
'safesearch': 'disable',
|
||||
'safesearch-str': 'test_value_8',
|
||||
'url': 'myurl_9.com'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'search-engine', 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_webfilter_search_engine_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',
|
||||
'webfilter_search_engine': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'charset': 'utf-8',
|
||||
'hostname': 'myhostname4',
|
||||
'name': 'default_name_5',
|
||||
'query': 'test_value_6',
|
||||
'safesearch': 'disable',
|
||||
'safesearch_str': 'test_value_8',
|
||||
'url': 'myurl_9.com'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_search_engine.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'charset': 'utf-8',
|
||||
'hostname': 'myhostname4',
|
||||
'name': 'default_name_5',
|
||||
'query': 'test_value_6',
|
||||
'safesearch': 'disable',
|
||||
'safesearch-str': 'test_value_8',
|
||||
'url': 'myurl_9.com'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'search-engine', 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,239 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_webfilter_urlfilter
|
||||
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_webfilter_urlfilter.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_webfilter_urlfilter_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',
|
||||
'webfilter_urlfilter': {
|
||||
'comment': 'Optional comments.',
|
||||
'id': '4',
|
||||
'ip_addr_block': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'one_arm_ips_urlfilter': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_urlfilter.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Optional comments.',
|
||||
'id': '4',
|
||||
'ip-addr-block': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'one-arm-ips-urlfilter': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'urlfilter', 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_webfilter_urlfilter_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',
|
||||
'webfilter_urlfilter': {
|
||||
'comment': 'Optional comments.',
|
||||
'id': '4',
|
||||
'ip_addr_block': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'one_arm_ips_urlfilter': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_urlfilter.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Optional comments.',
|
||||
'id': '4',
|
||||
'ip-addr-block': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'one-arm-ips-urlfilter': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'urlfilter', 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_webfilter_urlfilter_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',
|
||||
'webfilter_urlfilter': {
|
||||
'comment': 'Optional comments.',
|
||||
'id': '4',
|
||||
'ip_addr_block': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'one_arm_ips_urlfilter': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_urlfilter.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('webfilter', 'urlfilter', 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_webfilter_urlfilter_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',
|
||||
'webfilter_urlfilter': {
|
||||
'comment': 'Optional comments.',
|
||||
'id': '4',
|
||||
'ip_addr_block': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'one_arm_ips_urlfilter': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_urlfilter.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('webfilter', 'urlfilter', 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_webfilter_urlfilter_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',
|
||||
'webfilter_urlfilter': {
|
||||
'comment': 'Optional comments.',
|
||||
'id': '4',
|
||||
'ip_addr_block': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'one_arm_ips_urlfilter': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_urlfilter.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Optional comments.',
|
||||
'id': '4',
|
||||
'ip-addr-block': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'one-arm-ips-urlfilter': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'urlfilter', 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_webfilter_urlfilter_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',
|
||||
'webfilter_urlfilter': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'comment': 'Optional comments.',
|
||||
'id': '4',
|
||||
'ip_addr_block': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'one_arm_ips_urlfilter': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_webfilter_urlfilter.fortios_webfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Optional comments.',
|
||||
'id': '4',
|
||||
'ip-addr-block': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'one-arm-ips-urlfilter': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('webfilter', 'urlfilter', 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_wireless_controller_global
|
||||
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_wireless_controller_global.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_wireless_controller_global_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',
|
||||
'wireless_controller_global': {
|
||||
'ap_log_server': 'enable',
|
||||
'ap_log_server_ip': 'test_value_4',
|
||||
'ap_log_server_port': '5',
|
||||
'control_message_offload': 'ebp-frame',
|
||||
'data_ethernet_II': 'enable',
|
||||
'discovery_mc_addr': 'test_value_8',
|
||||
'fiapp_eth_type': '9',
|
||||
'image_download': 'enable',
|
||||
'ipsec_base_ip': 'test_value_11',
|
||||
'link_aggregation': 'enable',
|
||||
'location': 'test_value_13',
|
||||
'max_clients': '14',
|
||||
'max_retransmit': '15',
|
||||
'mesh_eth_type': '16',
|
||||
'name': 'default_name_17',
|
||||
'rogue_scan_mac_adjacency': '18',
|
||||
'wtp_share': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_global.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ap-log-server': 'enable',
|
||||
'ap-log-server-ip': 'test_value_4',
|
||||
'ap-log-server-port': '5',
|
||||
'control-message-offload': 'ebp-frame',
|
||||
'data-ethernet-II': 'enable',
|
||||
'discovery-mc-addr': 'test_value_8',
|
||||
'fiapp-eth-type': '9',
|
||||
'image-download': 'enable',
|
||||
'ipsec-base-ip': 'test_value_11',
|
||||
'link-aggregation': 'enable',
|
||||
'location': 'test_value_13',
|
||||
'max-clients': '14',
|
||||
'max-retransmit': '15',
|
||||
'mesh-eth-type': '16',
|
||||
'name': 'default_name_17',
|
||||
'rogue-scan-mac-adjacency': '18',
|
||||
'wtp-share': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'global', 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_wireless_controller_global_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',
|
||||
'wireless_controller_global': {
|
||||
'ap_log_server': 'enable',
|
||||
'ap_log_server_ip': 'test_value_4',
|
||||
'ap_log_server_port': '5',
|
||||
'control_message_offload': 'ebp-frame',
|
||||
'data_ethernet_II': 'enable',
|
||||
'discovery_mc_addr': 'test_value_8',
|
||||
'fiapp_eth_type': '9',
|
||||
'image_download': 'enable',
|
||||
'ipsec_base_ip': 'test_value_11',
|
||||
'link_aggregation': 'enable',
|
||||
'location': 'test_value_13',
|
||||
'max_clients': '14',
|
||||
'max_retransmit': '15',
|
||||
'mesh_eth_type': '16',
|
||||
'name': 'default_name_17',
|
||||
'rogue_scan_mac_adjacency': '18',
|
||||
'wtp_share': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_global.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ap-log-server': 'enable',
|
||||
'ap-log-server-ip': 'test_value_4',
|
||||
'ap-log-server-port': '5',
|
||||
'control-message-offload': 'ebp-frame',
|
||||
'data-ethernet-II': 'enable',
|
||||
'discovery-mc-addr': 'test_value_8',
|
||||
'fiapp-eth-type': '9',
|
||||
'image-download': 'enable',
|
||||
'ipsec-base-ip': 'test_value_11',
|
||||
'link-aggregation': 'enable',
|
||||
'location': 'test_value_13',
|
||||
'max-clients': '14',
|
||||
'max-retransmit': '15',
|
||||
'mesh-eth-type': '16',
|
||||
'name': 'default_name_17',
|
||||
'rogue-scan-mac-adjacency': '18',
|
||||
'wtp-share': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'global', 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_wireless_controller_global_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',
|
||||
'wireless_controller_global': {
|
||||
'ap_log_server': 'enable',
|
||||
'ap_log_server_ip': 'test_value_4',
|
||||
'ap_log_server_port': '5',
|
||||
'control_message_offload': 'ebp-frame',
|
||||
'data_ethernet_II': 'enable',
|
||||
'discovery_mc_addr': 'test_value_8',
|
||||
'fiapp_eth_type': '9',
|
||||
'image_download': 'enable',
|
||||
'ipsec_base_ip': 'test_value_11',
|
||||
'link_aggregation': 'enable',
|
||||
'location': 'test_value_13',
|
||||
'max_clients': '14',
|
||||
'max_retransmit': '15',
|
||||
'mesh_eth_type': '16',
|
||||
'name': 'default_name_17',
|
||||
'rogue_scan_mac_adjacency': '18',
|
||||
'wtp_share': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_global.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ap-log-server': 'enable',
|
||||
'ap-log-server-ip': 'test_value_4',
|
||||
'ap-log-server-port': '5',
|
||||
'control-message-offload': 'ebp-frame',
|
||||
'data-ethernet-II': 'enable',
|
||||
'discovery-mc-addr': 'test_value_8',
|
||||
'fiapp-eth-type': '9',
|
||||
'image-download': 'enable',
|
||||
'ipsec-base-ip': 'test_value_11',
|
||||
'link-aggregation': 'enable',
|
||||
'location': 'test_value_13',
|
||||
'max-clients': '14',
|
||||
'max-retransmit': '15',
|
||||
'mesh-eth-type': '16',
|
||||
'name': 'default_name_17',
|
||||
'rogue-scan-mac-adjacency': '18',
|
||||
'wtp-share': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'global', 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_wireless_controller_global_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',
|
||||
'wireless_controller_global': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'ap_log_server': 'enable',
|
||||
'ap_log_server_ip': 'test_value_4',
|
||||
'ap_log_server_port': '5',
|
||||
'control_message_offload': 'ebp-frame',
|
||||
'data_ethernet_II': 'enable',
|
||||
'discovery_mc_addr': 'test_value_8',
|
||||
'fiapp_eth_type': '9',
|
||||
'image_download': 'enable',
|
||||
'ipsec_base_ip': 'test_value_11',
|
||||
'link_aggregation': 'enable',
|
||||
'location': 'test_value_13',
|
||||
'max_clients': '14',
|
||||
'max_retransmit': '15',
|
||||
'mesh_eth_type': '16',
|
||||
'name': 'default_name_17',
|
||||
'rogue_scan_mac_adjacency': '18',
|
||||
'wtp_share': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_global.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ap-log-server': 'enable',
|
||||
'ap-log-server-ip': 'test_value_4',
|
||||
'ap-log-server-port': '5',
|
||||
'control-message-offload': 'ebp-frame',
|
||||
'data-ethernet-II': 'enable',
|
||||
'discovery-mc-addr': 'test_value_8',
|
||||
'fiapp-eth-type': '9',
|
||||
'image-download': 'enable',
|
||||
'ipsec-base-ip': 'test_value_11',
|
||||
'link-aggregation': 'enable',
|
||||
'location': 'test_value_13',
|
||||
'max-clients': '14',
|
||||
'max-retransmit': '15',
|
||||
'mesh-eth-type': '16',
|
||||
'name': 'default_name_17',
|
||||
'rogue-scan-mac-adjacency': '18',
|
||||
'wtp-share': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'global', data=expected_data, vdom='root')
|
||||
schema_method_mock.assert_not_called()
|
||||
assert not is_error
|
||||
assert changed
|
||||
assert response['status'] == 'success'
|
||||
assert response['http_status'] == 200
|
@ -0,0 +1,175 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_wireless_controller_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_wireless_controller_setting.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_wireless_controller_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',
|
||||
'wireless_controller_setting': {
|
||||
'account_id': 'test_value_3',
|
||||
'country': 'NA',
|
||||
'duplicate_ssid': 'enable',
|
||||
'fapc_compatibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_setting.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'account-id': 'test_value_3',
|
||||
'country': 'NA',
|
||||
'duplicate-ssid': 'enable',
|
||||
'fapc-compatibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', '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_wireless_controller_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',
|
||||
'wireless_controller_setting': {
|
||||
'account_id': 'test_value_3',
|
||||
'country': 'NA',
|
||||
'duplicate_ssid': 'enable',
|
||||
'fapc_compatibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_setting.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'account-id': 'test_value_3',
|
||||
'country': 'NA',
|
||||
'duplicate-ssid': 'enable',
|
||||
'fapc-compatibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', '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_wireless_controller_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',
|
||||
'wireless_controller_setting': {
|
||||
'account_id': 'test_value_3',
|
||||
'country': 'NA',
|
||||
'duplicate_ssid': 'enable',
|
||||
'fapc_compatibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_setting.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'account-id': 'test_value_3',
|
||||
'country': 'NA',
|
||||
'duplicate-ssid': 'enable',
|
||||
'fapc-compatibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', '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_wireless_controller_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',
|
||||
'wireless_controller_setting': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'account_id': 'test_value_3',
|
||||
'country': 'NA',
|
||||
'duplicate_ssid': 'enable',
|
||||
'fapc_compatibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_setting.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'account-id': 'test_value_3',
|
||||
'country': 'NA',
|
||||
'duplicate-ssid': 'enable',
|
||||
'fapc-compatibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', '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,269 @@
|
||||
# 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_wireless_controller_utm_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_wireless_controller_utm_profile.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_wireless_controller_utm_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',
|
||||
'wireless_controller_utm_profile': {
|
||||
'antivirus_profile': 'test_value_3',
|
||||
'application_list': 'test_value_4',
|
||||
'comment': 'Comment.',
|
||||
'ips_sensor': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'utm_log': 'enable',
|
||||
'webfilter_profile': 'test_value_10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_utm_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'antivirus-profile': 'test_value_3',
|
||||
'application-list': 'test_value_4',
|
||||
'comment': 'Comment.',
|
||||
'ips-sensor': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'scan-botnet-connections': 'disable',
|
||||
'utm-log': 'enable',
|
||||
'webfilter-profile': 'test_value_10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'utm-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_wireless_controller_utm_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',
|
||||
'wireless_controller_utm_profile': {
|
||||
'antivirus_profile': 'test_value_3',
|
||||
'application_list': 'test_value_4',
|
||||
'comment': 'Comment.',
|
||||
'ips_sensor': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'utm_log': 'enable',
|
||||
'webfilter_profile': 'test_value_10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_utm_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'antivirus-profile': 'test_value_3',
|
||||
'application-list': 'test_value_4',
|
||||
'comment': 'Comment.',
|
||||
'ips-sensor': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'scan-botnet-connections': 'disable',
|
||||
'utm-log': 'enable',
|
||||
'webfilter-profile': 'test_value_10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'utm-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_wireless_controller_utm_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',
|
||||
'wireless_controller_utm_profile': {
|
||||
'antivirus_profile': 'test_value_3',
|
||||
'application_list': 'test_value_4',
|
||||
'comment': 'Comment.',
|
||||
'ips_sensor': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'utm_log': 'enable',
|
||||
'webfilter_profile': 'test_value_10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_utm_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('wireless-controller', 'utm-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_wireless_controller_utm_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',
|
||||
'wireless_controller_utm_profile': {
|
||||
'antivirus_profile': 'test_value_3',
|
||||
'application_list': 'test_value_4',
|
||||
'comment': 'Comment.',
|
||||
'ips_sensor': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'utm_log': 'enable',
|
||||
'webfilter_profile': 'test_value_10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_utm_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('wireless-controller', 'utm-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_wireless_controller_utm_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',
|
||||
'wireless_controller_utm_profile': {
|
||||
'antivirus_profile': 'test_value_3',
|
||||
'application_list': 'test_value_4',
|
||||
'comment': 'Comment.',
|
||||
'ips_sensor': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'utm_log': 'enable',
|
||||
'webfilter_profile': 'test_value_10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_utm_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'antivirus-profile': 'test_value_3',
|
||||
'application-list': 'test_value_4',
|
||||
'comment': 'Comment.',
|
||||
'ips-sensor': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'scan-botnet-connections': 'disable',
|
||||
'utm-log': 'enable',
|
||||
'webfilter-profile': 'test_value_10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'utm-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_wireless_controller_utm_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',
|
||||
'wireless_controller_utm_profile': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'antivirus_profile': 'test_value_3',
|
||||
'application_list': 'test_value_4',
|
||||
'comment': 'Comment.',
|
||||
'ips_sensor': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'utm_log': 'enable',
|
||||
'webfilter_profile': 'test_value_10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_utm_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'antivirus-profile': 'test_value_3',
|
||||
'application-list': 'test_value_4',
|
||||
'comment': 'Comment.',
|
||||
'ips-sensor': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'scan-botnet-connections': 'disable',
|
||||
'utm-log': 'enable',
|
||||
'webfilter-profile': 'test_value_10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'utm-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
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,679 @@
|
||||
# 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_wireless_controller_wids_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_wireless_controller_wids_profile.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_wireless_controller_wids_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',
|
||||
'wireless_controller_wids_profile': {
|
||||
'ap_auto_suppress': 'enable',
|
||||
'ap_bgscan_disable_day': 'sunday',
|
||||
'ap_bgscan_disable_end': 'test_value_5',
|
||||
'ap_bgscan_disable_start': 'test_value_6',
|
||||
'ap_bgscan_duration': '7',
|
||||
'ap_bgscan_idle': '8',
|
||||
'ap_bgscan_intv': '9',
|
||||
'ap_bgscan_period': '10',
|
||||
'ap_bgscan_report_intv': '11',
|
||||
'ap_fgscan_report_intv': '12',
|
||||
'ap_scan': 'disable',
|
||||
'ap_scan_passive': 'enable',
|
||||
'asleap_attack': 'enable',
|
||||
'assoc_flood_thresh': '16',
|
||||
'assoc_flood_time': '17',
|
||||
'assoc_frame_flood': 'enable',
|
||||
'auth_flood_thresh': '19',
|
||||
'auth_flood_time': '20',
|
||||
'auth_frame_flood': 'enable',
|
||||
'comment': 'Comment.',
|
||||
'deauth_broadcast': 'enable',
|
||||
'deauth_unknown_src_thresh': '24',
|
||||
'eapol_fail_flood': 'enable',
|
||||
'eapol_fail_intv': '26',
|
||||
'eapol_fail_thresh': '27',
|
||||
'eapol_logoff_flood': 'enable',
|
||||
'eapol_logoff_intv': '29',
|
||||
'eapol_logoff_thresh': '30',
|
||||
'eapol_pre_fail_flood': 'enable',
|
||||
'eapol_pre_fail_intv': '32',
|
||||
'eapol_pre_fail_thresh': '33',
|
||||
'eapol_pre_succ_flood': 'enable',
|
||||
'eapol_pre_succ_intv': '35',
|
||||
'eapol_pre_succ_thresh': '36',
|
||||
'eapol_start_flood': 'enable',
|
||||
'eapol_start_intv': '38',
|
||||
'eapol_start_thresh': '39',
|
||||
'eapol_succ_flood': 'enable',
|
||||
'eapol_succ_intv': '41',
|
||||
'eapol_succ_thresh': '42',
|
||||
'invalid_mac_oui': 'enable',
|
||||
'long_duration_attack': 'enable',
|
||||
'long_duration_thresh': '45',
|
||||
'name': 'default_name_46',
|
||||
'null_ssid_probe_resp': 'enable',
|
||||
'sensor_mode': 'disable',
|
||||
'spoofed_deauth': 'enable',
|
||||
'weak_wep_iv': 'enable',
|
||||
'wireless_bridge': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wids_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ap-auto-suppress': 'enable',
|
||||
'ap-bgscan-disable-day': 'sunday',
|
||||
'ap-bgscan-disable-end': 'test_value_5',
|
||||
'ap-bgscan-disable-start': 'test_value_6',
|
||||
'ap-bgscan-duration': '7',
|
||||
'ap-bgscan-idle': '8',
|
||||
'ap-bgscan-intv': '9',
|
||||
'ap-bgscan-period': '10',
|
||||
'ap-bgscan-report-intv': '11',
|
||||
'ap-fgscan-report-intv': '12',
|
||||
'ap-scan': 'disable',
|
||||
'ap-scan-passive': 'enable',
|
||||
'asleap-attack': 'enable',
|
||||
'assoc-flood-thresh': '16',
|
||||
'assoc-flood-time': '17',
|
||||
'assoc-frame-flood': 'enable',
|
||||
'auth-flood-thresh': '19',
|
||||
'auth-flood-time': '20',
|
||||
'auth-frame-flood': 'enable',
|
||||
'comment': 'Comment.',
|
||||
'deauth-broadcast': 'enable',
|
||||
'deauth-unknown-src-thresh': '24',
|
||||
'eapol-fail-flood': 'enable',
|
||||
'eapol-fail-intv': '26',
|
||||
'eapol-fail-thresh': '27',
|
||||
'eapol-logoff-flood': 'enable',
|
||||
'eapol-logoff-intv': '29',
|
||||
'eapol-logoff-thresh': '30',
|
||||
'eapol-pre-fail-flood': 'enable',
|
||||
'eapol-pre-fail-intv': '32',
|
||||
'eapol-pre-fail-thresh': '33',
|
||||
'eapol-pre-succ-flood': 'enable',
|
||||
'eapol-pre-succ-intv': '35',
|
||||
'eapol-pre-succ-thresh': '36',
|
||||
'eapol-start-flood': 'enable',
|
||||
'eapol-start-intv': '38',
|
||||
'eapol-start-thresh': '39',
|
||||
'eapol-succ-flood': 'enable',
|
||||
'eapol-succ-intv': '41',
|
||||
'eapol-succ-thresh': '42',
|
||||
'invalid-mac-oui': 'enable',
|
||||
'long-duration-attack': 'enable',
|
||||
'long-duration-thresh': '45',
|
||||
'name': 'default_name_46',
|
||||
'null-ssid-probe-resp': 'enable',
|
||||
'sensor-mode': 'disable',
|
||||
'spoofed-deauth': 'enable',
|
||||
'weak-wep-iv': 'enable',
|
||||
'wireless-bridge': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'wids-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_wireless_controller_wids_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',
|
||||
'wireless_controller_wids_profile': {
|
||||
'ap_auto_suppress': 'enable',
|
||||
'ap_bgscan_disable_day': 'sunday',
|
||||
'ap_bgscan_disable_end': 'test_value_5',
|
||||
'ap_bgscan_disable_start': 'test_value_6',
|
||||
'ap_bgscan_duration': '7',
|
||||
'ap_bgscan_idle': '8',
|
||||
'ap_bgscan_intv': '9',
|
||||
'ap_bgscan_period': '10',
|
||||
'ap_bgscan_report_intv': '11',
|
||||
'ap_fgscan_report_intv': '12',
|
||||
'ap_scan': 'disable',
|
||||
'ap_scan_passive': 'enable',
|
||||
'asleap_attack': 'enable',
|
||||
'assoc_flood_thresh': '16',
|
||||
'assoc_flood_time': '17',
|
||||
'assoc_frame_flood': 'enable',
|
||||
'auth_flood_thresh': '19',
|
||||
'auth_flood_time': '20',
|
||||
'auth_frame_flood': 'enable',
|
||||
'comment': 'Comment.',
|
||||
'deauth_broadcast': 'enable',
|
||||
'deauth_unknown_src_thresh': '24',
|
||||
'eapol_fail_flood': 'enable',
|
||||
'eapol_fail_intv': '26',
|
||||
'eapol_fail_thresh': '27',
|
||||
'eapol_logoff_flood': 'enable',
|
||||
'eapol_logoff_intv': '29',
|
||||
'eapol_logoff_thresh': '30',
|
||||
'eapol_pre_fail_flood': 'enable',
|
||||
'eapol_pre_fail_intv': '32',
|
||||
'eapol_pre_fail_thresh': '33',
|
||||
'eapol_pre_succ_flood': 'enable',
|
||||
'eapol_pre_succ_intv': '35',
|
||||
'eapol_pre_succ_thresh': '36',
|
||||
'eapol_start_flood': 'enable',
|
||||
'eapol_start_intv': '38',
|
||||
'eapol_start_thresh': '39',
|
||||
'eapol_succ_flood': 'enable',
|
||||
'eapol_succ_intv': '41',
|
||||
'eapol_succ_thresh': '42',
|
||||
'invalid_mac_oui': 'enable',
|
||||
'long_duration_attack': 'enable',
|
||||
'long_duration_thresh': '45',
|
||||
'name': 'default_name_46',
|
||||
'null_ssid_probe_resp': 'enable',
|
||||
'sensor_mode': 'disable',
|
||||
'spoofed_deauth': 'enable',
|
||||
'weak_wep_iv': 'enable',
|
||||
'wireless_bridge': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wids_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ap-auto-suppress': 'enable',
|
||||
'ap-bgscan-disable-day': 'sunday',
|
||||
'ap-bgscan-disable-end': 'test_value_5',
|
||||
'ap-bgscan-disable-start': 'test_value_6',
|
||||
'ap-bgscan-duration': '7',
|
||||
'ap-bgscan-idle': '8',
|
||||
'ap-bgscan-intv': '9',
|
||||
'ap-bgscan-period': '10',
|
||||
'ap-bgscan-report-intv': '11',
|
||||
'ap-fgscan-report-intv': '12',
|
||||
'ap-scan': 'disable',
|
||||
'ap-scan-passive': 'enable',
|
||||
'asleap-attack': 'enable',
|
||||
'assoc-flood-thresh': '16',
|
||||
'assoc-flood-time': '17',
|
||||
'assoc-frame-flood': 'enable',
|
||||
'auth-flood-thresh': '19',
|
||||
'auth-flood-time': '20',
|
||||
'auth-frame-flood': 'enable',
|
||||
'comment': 'Comment.',
|
||||
'deauth-broadcast': 'enable',
|
||||
'deauth-unknown-src-thresh': '24',
|
||||
'eapol-fail-flood': 'enable',
|
||||
'eapol-fail-intv': '26',
|
||||
'eapol-fail-thresh': '27',
|
||||
'eapol-logoff-flood': 'enable',
|
||||
'eapol-logoff-intv': '29',
|
||||
'eapol-logoff-thresh': '30',
|
||||
'eapol-pre-fail-flood': 'enable',
|
||||
'eapol-pre-fail-intv': '32',
|
||||
'eapol-pre-fail-thresh': '33',
|
||||
'eapol-pre-succ-flood': 'enable',
|
||||
'eapol-pre-succ-intv': '35',
|
||||
'eapol-pre-succ-thresh': '36',
|
||||
'eapol-start-flood': 'enable',
|
||||
'eapol-start-intv': '38',
|
||||
'eapol-start-thresh': '39',
|
||||
'eapol-succ-flood': 'enable',
|
||||
'eapol-succ-intv': '41',
|
||||
'eapol-succ-thresh': '42',
|
||||
'invalid-mac-oui': 'enable',
|
||||
'long-duration-attack': 'enable',
|
||||
'long-duration-thresh': '45',
|
||||
'name': 'default_name_46',
|
||||
'null-ssid-probe-resp': 'enable',
|
||||
'sensor-mode': 'disable',
|
||||
'spoofed-deauth': 'enable',
|
||||
'weak-wep-iv': 'enable',
|
||||
'wireless-bridge': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'wids-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_wireless_controller_wids_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',
|
||||
'wireless_controller_wids_profile': {
|
||||
'ap_auto_suppress': 'enable',
|
||||
'ap_bgscan_disable_day': 'sunday',
|
||||
'ap_bgscan_disable_end': 'test_value_5',
|
||||
'ap_bgscan_disable_start': 'test_value_6',
|
||||
'ap_bgscan_duration': '7',
|
||||
'ap_bgscan_idle': '8',
|
||||
'ap_bgscan_intv': '9',
|
||||
'ap_bgscan_period': '10',
|
||||
'ap_bgscan_report_intv': '11',
|
||||
'ap_fgscan_report_intv': '12',
|
||||
'ap_scan': 'disable',
|
||||
'ap_scan_passive': 'enable',
|
||||
'asleap_attack': 'enable',
|
||||
'assoc_flood_thresh': '16',
|
||||
'assoc_flood_time': '17',
|
||||
'assoc_frame_flood': 'enable',
|
||||
'auth_flood_thresh': '19',
|
||||
'auth_flood_time': '20',
|
||||
'auth_frame_flood': 'enable',
|
||||
'comment': 'Comment.',
|
||||
'deauth_broadcast': 'enable',
|
||||
'deauth_unknown_src_thresh': '24',
|
||||
'eapol_fail_flood': 'enable',
|
||||
'eapol_fail_intv': '26',
|
||||
'eapol_fail_thresh': '27',
|
||||
'eapol_logoff_flood': 'enable',
|
||||
'eapol_logoff_intv': '29',
|
||||
'eapol_logoff_thresh': '30',
|
||||
'eapol_pre_fail_flood': 'enable',
|
||||
'eapol_pre_fail_intv': '32',
|
||||
'eapol_pre_fail_thresh': '33',
|
||||
'eapol_pre_succ_flood': 'enable',
|
||||
'eapol_pre_succ_intv': '35',
|
||||
'eapol_pre_succ_thresh': '36',
|
||||
'eapol_start_flood': 'enable',
|
||||
'eapol_start_intv': '38',
|
||||
'eapol_start_thresh': '39',
|
||||
'eapol_succ_flood': 'enable',
|
||||
'eapol_succ_intv': '41',
|
||||
'eapol_succ_thresh': '42',
|
||||
'invalid_mac_oui': 'enable',
|
||||
'long_duration_attack': 'enable',
|
||||
'long_duration_thresh': '45',
|
||||
'name': 'default_name_46',
|
||||
'null_ssid_probe_resp': 'enable',
|
||||
'sensor_mode': 'disable',
|
||||
'spoofed_deauth': 'enable',
|
||||
'weak_wep_iv': 'enable',
|
||||
'wireless_bridge': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wids_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('wireless-controller', 'wids-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_wireless_controller_wids_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',
|
||||
'wireless_controller_wids_profile': {
|
||||
'ap_auto_suppress': 'enable',
|
||||
'ap_bgscan_disable_day': 'sunday',
|
||||
'ap_bgscan_disable_end': 'test_value_5',
|
||||
'ap_bgscan_disable_start': 'test_value_6',
|
||||
'ap_bgscan_duration': '7',
|
||||
'ap_bgscan_idle': '8',
|
||||
'ap_bgscan_intv': '9',
|
||||
'ap_bgscan_period': '10',
|
||||
'ap_bgscan_report_intv': '11',
|
||||
'ap_fgscan_report_intv': '12',
|
||||
'ap_scan': 'disable',
|
||||
'ap_scan_passive': 'enable',
|
||||
'asleap_attack': 'enable',
|
||||
'assoc_flood_thresh': '16',
|
||||
'assoc_flood_time': '17',
|
||||
'assoc_frame_flood': 'enable',
|
||||
'auth_flood_thresh': '19',
|
||||
'auth_flood_time': '20',
|
||||
'auth_frame_flood': 'enable',
|
||||
'comment': 'Comment.',
|
||||
'deauth_broadcast': 'enable',
|
||||
'deauth_unknown_src_thresh': '24',
|
||||
'eapol_fail_flood': 'enable',
|
||||
'eapol_fail_intv': '26',
|
||||
'eapol_fail_thresh': '27',
|
||||
'eapol_logoff_flood': 'enable',
|
||||
'eapol_logoff_intv': '29',
|
||||
'eapol_logoff_thresh': '30',
|
||||
'eapol_pre_fail_flood': 'enable',
|
||||
'eapol_pre_fail_intv': '32',
|
||||
'eapol_pre_fail_thresh': '33',
|
||||
'eapol_pre_succ_flood': 'enable',
|
||||
'eapol_pre_succ_intv': '35',
|
||||
'eapol_pre_succ_thresh': '36',
|
||||
'eapol_start_flood': 'enable',
|
||||
'eapol_start_intv': '38',
|
||||
'eapol_start_thresh': '39',
|
||||
'eapol_succ_flood': 'enable',
|
||||
'eapol_succ_intv': '41',
|
||||
'eapol_succ_thresh': '42',
|
||||
'invalid_mac_oui': 'enable',
|
||||
'long_duration_attack': 'enable',
|
||||
'long_duration_thresh': '45',
|
||||
'name': 'default_name_46',
|
||||
'null_ssid_probe_resp': 'enable',
|
||||
'sensor_mode': 'disable',
|
||||
'spoofed_deauth': 'enable',
|
||||
'weak_wep_iv': 'enable',
|
||||
'wireless_bridge': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wids_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('wireless-controller', 'wids-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_wireless_controller_wids_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',
|
||||
'wireless_controller_wids_profile': {
|
||||
'ap_auto_suppress': 'enable',
|
||||
'ap_bgscan_disable_day': 'sunday',
|
||||
'ap_bgscan_disable_end': 'test_value_5',
|
||||
'ap_bgscan_disable_start': 'test_value_6',
|
||||
'ap_bgscan_duration': '7',
|
||||
'ap_bgscan_idle': '8',
|
||||
'ap_bgscan_intv': '9',
|
||||
'ap_bgscan_period': '10',
|
||||
'ap_bgscan_report_intv': '11',
|
||||
'ap_fgscan_report_intv': '12',
|
||||
'ap_scan': 'disable',
|
||||
'ap_scan_passive': 'enable',
|
||||
'asleap_attack': 'enable',
|
||||
'assoc_flood_thresh': '16',
|
||||
'assoc_flood_time': '17',
|
||||
'assoc_frame_flood': 'enable',
|
||||
'auth_flood_thresh': '19',
|
||||
'auth_flood_time': '20',
|
||||
'auth_frame_flood': 'enable',
|
||||
'comment': 'Comment.',
|
||||
'deauth_broadcast': 'enable',
|
||||
'deauth_unknown_src_thresh': '24',
|
||||
'eapol_fail_flood': 'enable',
|
||||
'eapol_fail_intv': '26',
|
||||
'eapol_fail_thresh': '27',
|
||||
'eapol_logoff_flood': 'enable',
|
||||
'eapol_logoff_intv': '29',
|
||||
'eapol_logoff_thresh': '30',
|
||||
'eapol_pre_fail_flood': 'enable',
|
||||
'eapol_pre_fail_intv': '32',
|
||||
'eapol_pre_fail_thresh': '33',
|
||||
'eapol_pre_succ_flood': 'enable',
|
||||
'eapol_pre_succ_intv': '35',
|
||||
'eapol_pre_succ_thresh': '36',
|
||||
'eapol_start_flood': 'enable',
|
||||
'eapol_start_intv': '38',
|
||||
'eapol_start_thresh': '39',
|
||||
'eapol_succ_flood': 'enable',
|
||||
'eapol_succ_intv': '41',
|
||||
'eapol_succ_thresh': '42',
|
||||
'invalid_mac_oui': 'enable',
|
||||
'long_duration_attack': 'enable',
|
||||
'long_duration_thresh': '45',
|
||||
'name': 'default_name_46',
|
||||
'null_ssid_probe_resp': 'enable',
|
||||
'sensor_mode': 'disable',
|
||||
'spoofed_deauth': 'enable',
|
||||
'weak_wep_iv': 'enable',
|
||||
'wireless_bridge': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wids_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ap-auto-suppress': 'enable',
|
||||
'ap-bgscan-disable-day': 'sunday',
|
||||
'ap-bgscan-disable-end': 'test_value_5',
|
||||
'ap-bgscan-disable-start': 'test_value_6',
|
||||
'ap-bgscan-duration': '7',
|
||||
'ap-bgscan-idle': '8',
|
||||
'ap-bgscan-intv': '9',
|
||||
'ap-bgscan-period': '10',
|
||||
'ap-bgscan-report-intv': '11',
|
||||
'ap-fgscan-report-intv': '12',
|
||||
'ap-scan': 'disable',
|
||||
'ap-scan-passive': 'enable',
|
||||
'asleap-attack': 'enable',
|
||||
'assoc-flood-thresh': '16',
|
||||
'assoc-flood-time': '17',
|
||||
'assoc-frame-flood': 'enable',
|
||||
'auth-flood-thresh': '19',
|
||||
'auth-flood-time': '20',
|
||||
'auth-frame-flood': 'enable',
|
||||
'comment': 'Comment.',
|
||||
'deauth-broadcast': 'enable',
|
||||
'deauth-unknown-src-thresh': '24',
|
||||
'eapol-fail-flood': 'enable',
|
||||
'eapol-fail-intv': '26',
|
||||
'eapol-fail-thresh': '27',
|
||||
'eapol-logoff-flood': 'enable',
|
||||
'eapol-logoff-intv': '29',
|
||||
'eapol-logoff-thresh': '30',
|
||||
'eapol-pre-fail-flood': 'enable',
|
||||
'eapol-pre-fail-intv': '32',
|
||||
'eapol-pre-fail-thresh': '33',
|
||||
'eapol-pre-succ-flood': 'enable',
|
||||
'eapol-pre-succ-intv': '35',
|
||||
'eapol-pre-succ-thresh': '36',
|
||||
'eapol-start-flood': 'enable',
|
||||
'eapol-start-intv': '38',
|
||||
'eapol-start-thresh': '39',
|
||||
'eapol-succ-flood': 'enable',
|
||||
'eapol-succ-intv': '41',
|
||||
'eapol-succ-thresh': '42',
|
||||
'invalid-mac-oui': 'enable',
|
||||
'long-duration-attack': 'enable',
|
||||
'long-duration-thresh': '45',
|
||||
'name': 'default_name_46',
|
||||
'null-ssid-probe-resp': 'enable',
|
||||
'sensor-mode': 'disable',
|
||||
'spoofed-deauth': 'enable',
|
||||
'weak-wep-iv': 'enable',
|
||||
'wireless-bridge': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'wids-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_wireless_controller_wids_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',
|
||||
'wireless_controller_wids_profile': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'ap_auto_suppress': 'enable',
|
||||
'ap_bgscan_disable_day': 'sunday',
|
||||
'ap_bgscan_disable_end': 'test_value_5',
|
||||
'ap_bgscan_disable_start': 'test_value_6',
|
||||
'ap_bgscan_duration': '7',
|
||||
'ap_bgscan_idle': '8',
|
||||
'ap_bgscan_intv': '9',
|
||||
'ap_bgscan_period': '10',
|
||||
'ap_bgscan_report_intv': '11',
|
||||
'ap_fgscan_report_intv': '12',
|
||||
'ap_scan': 'disable',
|
||||
'ap_scan_passive': 'enable',
|
||||
'asleap_attack': 'enable',
|
||||
'assoc_flood_thresh': '16',
|
||||
'assoc_flood_time': '17',
|
||||
'assoc_frame_flood': 'enable',
|
||||
'auth_flood_thresh': '19',
|
||||
'auth_flood_time': '20',
|
||||
'auth_frame_flood': 'enable',
|
||||
'comment': 'Comment.',
|
||||
'deauth_broadcast': 'enable',
|
||||
'deauth_unknown_src_thresh': '24',
|
||||
'eapol_fail_flood': 'enable',
|
||||
'eapol_fail_intv': '26',
|
||||
'eapol_fail_thresh': '27',
|
||||
'eapol_logoff_flood': 'enable',
|
||||
'eapol_logoff_intv': '29',
|
||||
'eapol_logoff_thresh': '30',
|
||||
'eapol_pre_fail_flood': 'enable',
|
||||
'eapol_pre_fail_intv': '32',
|
||||
'eapol_pre_fail_thresh': '33',
|
||||
'eapol_pre_succ_flood': 'enable',
|
||||
'eapol_pre_succ_intv': '35',
|
||||
'eapol_pre_succ_thresh': '36',
|
||||
'eapol_start_flood': 'enable',
|
||||
'eapol_start_intv': '38',
|
||||
'eapol_start_thresh': '39',
|
||||
'eapol_succ_flood': 'enable',
|
||||
'eapol_succ_intv': '41',
|
||||
'eapol_succ_thresh': '42',
|
||||
'invalid_mac_oui': 'enable',
|
||||
'long_duration_attack': 'enable',
|
||||
'long_duration_thresh': '45',
|
||||
'name': 'default_name_46',
|
||||
'null_ssid_probe_resp': 'enable',
|
||||
'sensor_mode': 'disable',
|
||||
'spoofed_deauth': 'enable',
|
||||
'weak_wep_iv': 'enable',
|
||||
'wireless_bridge': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wids_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ap-auto-suppress': 'enable',
|
||||
'ap-bgscan-disable-day': 'sunday',
|
||||
'ap-bgscan-disable-end': 'test_value_5',
|
||||
'ap-bgscan-disable-start': 'test_value_6',
|
||||
'ap-bgscan-duration': '7',
|
||||
'ap-bgscan-idle': '8',
|
||||
'ap-bgscan-intv': '9',
|
||||
'ap-bgscan-period': '10',
|
||||
'ap-bgscan-report-intv': '11',
|
||||
'ap-fgscan-report-intv': '12',
|
||||
'ap-scan': 'disable',
|
||||
'ap-scan-passive': 'enable',
|
||||
'asleap-attack': 'enable',
|
||||
'assoc-flood-thresh': '16',
|
||||
'assoc-flood-time': '17',
|
||||
'assoc-frame-flood': 'enable',
|
||||
'auth-flood-thresh': '19',
|
||||
'auth-flood-time': '20',
|
||||
'auth-frame-flood': 'enable',
|
||||
'comment': 'Comment.',
|
||||
'deauth-broadcast': 'enable',
|
||||
'deauth-unknown-src-thresh': '24',
|
||||
'eapol-fail-flood': 'enable',
|
||||
'eapol-fail-intv': '26',
|
||||
'eapol-fail-thresh': '27',
|
||||
'eapol-logoff-flood': 'enable',
|
||||
'eapol-logoff-intv': '29',
|
||||
'eapol-logoff-thresh': '30',
|
||||
'eapol-pre-fail-flood': 'enable',
|
||||
'eapol-pre-fail-intv': '32',
|
||||
'eapol-pre-fail-thresh': '33',
|
||||
'eapol-pre-succ-flood': 'enable',
|
||||
'eapol-pre-succ-intv': '35',
|
||||
'eapol-pre-succ-thresh': '36',
|
||||
'eapol-start-flood': 'enable',
|
||||
'eapol-start-intv': '38',
|
||||
'eapol-start-thresh': '39',
|
||||
'eapol-succ-flood': 'enable',
|
||||
'eapol-succ-intv': '41',
|
||||
'eapol-succ-thresh': '42',
|
||||
'invalid-mac-oui': 'enable',
|
||||
'long-duration-attack': 'enable',
|
||||
'long-duration-thresh': '45',
|
||||
'name': 'default_name_46',
|
||||
'null-ssid-probe-resp': 'enable',
|
||||
'sensor-mode': 'disable',
|
||||
'spoofed-deauth': 'enable',
|
||||
'weak-wep-iv': 'enable',
|
||||
'wireless-bridge': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'wids-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,509 @@
|
||||
# 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_wireless_controller_wtp
|
||||
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_wireless_controller_wtp.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_wireless_controller_wtp_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',
|
||||
'wireless_controller_wtp': {
|
||||
'admin': 'discovered',
|
||||
'allowaccess': 'telnet',
|
||||
'bonjour_profile': 'test_value_5',
|
||||
'coordinate_enable': 'enable',
|
||||
'coordinate_latitude': 'test_value_7',
|
||||
'coordinate_longitude': 'test_value_8',
|
||||
'coordinate_x': 'test_value_9',
|
||||
'coordinate_y': 'test_value_10',
|
||||
'image_download': 'enable',
|
||||
'index': '12',
|
||||
'ip_fragment_preventing': 'tcp-mss-adjust',
|
||||
'led_state': 'enable',
|
||||
'location': 'test_value_15',
|
||||
'login_passwd': 'test_value_16',
|
||||
'login_passwd_change': 'yes',
|
||||
'mesh_bridge_enable': 'default',
|
||||
'name': 'default_name_19',
|
||||
'override_allowaccess': 'enable',
|
||||
'override_ip_fragment': 'enable',
|
||||
'override_lan': 'enable',
|
||||
'override_led_state': 'enable',
|
||||
'override_login_passwd_change': 'enable',
|
||||
'override_split_tunnel': 'enable',
|
||||
'override_wan_port_mode': 'enable',
|
||||
'split_tunneling_acl_local_ap_subnet': 'enable',
|
||||
'split_tunneling_acl_path': 'tunnel',
|
||||
'tun_mtu_downlink': '29',
|
||||
'tun_mtu_uplink': '30',
|
||||
'wan_port_mode': 'wan-lan',
|
||||
'wtp_id': 'test_value_32',
|
||||
'wtp_mode': 'normal',
|
||||
'wtp_profile': 'test_value_34'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wtp.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'admin': 'discovered',
|
||||
'allowaccess': 'telnet',
|
||||
'bonjour-profile': 'test_value_5',
|
||||
'coordinate-enable': 'enable',
|
||||
'coordinate-latitude': 'test_value_7',
|
||||
'coordinate-longitude': 'test_value_8',
|
||||
'coordinate-x': 'test_value_9',
|
||||
'coordinate-y': 'test_value_10',
|
||||
'image-download': 'enable',
|
||||
'index': '12',
|
||||
'ip-fragment-preventing': 'tcp-mss-adjust',
|
||||
'led-state': 'enable',
|
||||
'location': 'test_value_15',
|
||||
'login-passwd': 'test_value_16',
|
||||
'login-passwd-change': 'yes',
|
||||
'mesh-bridge-enable': 'default',
|
||||
'name': 'default_name_19',
|
||||
'override-allowaccess': 'enable',
|
||||
'override-ip-fragment': 'enable',
|
||||
'override-lan': 'enable',
|
||||
'override-led-state': 'enable',
|
||||
'override-login-passwd-change': 'enable',
|
||||
'override-split-tunnel': 'enable',
|
||||
'override-wan-port-mode': 'enable',
|
||||
'split-tunneling-acl-local-ap-subnet': 'enable',
|
||||
'split-tunneling-acl-path': 'tunnel',
|
||||
'tun-mtu-downlink': '29',
|
||||
'tun-mtu-uplink': '30',
|
||||
'wan-port-mode': 'wan-lan',
|
||||
'wtp-id': 'test_value_32',
|
||||
'wtp-mode': 'normal',
|
||||
'wtp-profile': 'test_value_34'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'wtp', 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_wireless_controller_wtp_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',
|
||||
'wireless_controller_wtp': {
|
||||
'admin': 'discovered',
|
||||
'allowaccess': 'telnet',
|
||||
'bonjour_profile': 'test_value_5',
|
||||
'coordinate_enable': 'enable',
|
||||
'coordinate_latitude': 'test_value_7',
|
||||
'coordinate_longitude': 'test_value_8',
|
||||
'coordinate_x': 'test_value_9',
|
||||
'coordinate_y': 'test_value_10',
|
||||
'image_download': 'enable',
|
||||
'index': '12',
|
||||
'ip_fragment_preventing': 'tcp-mss-adjust',
|
||||
'led_state': 'enable',
|
||||
'location': 'test_value_15',
|
||||
'login_passwd': 'test_value_16',
|
||||
'login_passwd_change': 'yes',
|
||||
'mesh_bridge_enable': 'default',
|
||||
'name': 'default_name_19',
|
||||
'override_allowaccess': 'enable',
|
||||
'override_ip_fragment': 'enable',
|
||||
'override_lan': 'enable',
|
||||
'override_led_state': 'enable',
|
||||
'override_login_passwd_change': 'enable',
|
||||
'override_split_tunnel': 'enable',
|
||||
'override_wan_port_mode': 'enable',
|
||||
'split_tunneling_acl_local_ap_subnet': 'enable',
|
||||
'split_tunneling_acl_path': 'tunnel',
|
||||
'tun_mtu_downlink': '29',
|
||||
'tun_mtu_uplink': '30',
|
||||
'wan_port_mode': 'wan-lan',
|
||||
'wtp_id': 'test_value_32',
|
||||
'wtp_mode': 'normal',
|
||||
'wtp_profile': 'test_value_34'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wtp.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'admin': 'discovered',
|
||||
'allowaccess': 'telnet',
|
||||
'bonjour-profile': 'test_value_5',
|
||||
'coordinate-enable': 'enable',
|
||||
'coordinate-latitude': 'test_value_7',
|
||||
'coordinate-longitude': 'test_value_8',
|
||||
'coordinate-x': 'test_value_9',
|
||||
'coordinate-y': 'test_value_10',
|
||||
'image-download': 'enable',
|
||||
'index': '12',
|
||||
'ip-fragment-preventing': 'tcp-mss-adjust',
|
||||
'led-state': 'enable',
|
||||
'location': 'test_value_15',
|
||||
'login-passwd': 'test_value_16',
|
||||
'login-passwd-change': 'yes',
|
||||
'mesh-bridge-enable': 'default',
|
||||
'name': 'default_name_19',
|
||||
'override-allowaccess': 'enable',
|
||||
'override-ip-fragment': 'enable',
|
||||
'override-lan': 'enable',
|
||||
'override-led-state': 'enable',
|
||||
'override-login-passwd-change': 'enable',
|
||||
'override-split-tunnel': 'enable',
|
||||
'override-wan-port-mode': 'enable',
|
||||
'split-tunneling-acl-local-ap-subnet': 'enable',
|
||||
'split-tunneling-acl-path': 'tunnel',
|
||||
'tun-mtu-downlink': '29',
|
||||
'tun-mtu-uplink': '30',
|
||||
'wan-port-mode': 'wan-lan',
|
||||
'wtp-id': 'test_value_32',
|
||||
'wtp-mode': 'normal',
|
||||
'wtp-profile': 'test_value_34'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'wtp', 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_wireless_controller_wtp_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',
|
||||
'wireless_controller_wtp': {
|
||||
'admin': 'discovered',
|
||||
'allowaccess': 'telnet',
|
||||
'bonjour_profile': 'test_value_5',
|
||||
'coordinate_enable': 'enable',
|
||||
'coordinate_latitude': 'test_value_7',
|
||||
'coordinate_longitude': 'test_value_8',
|
||||
'coordinate_x': 'test_value_9',
|
||||
'coordinate_y': 'test_value_10',
|
||||
'image_download': 'enable',
|
||||
'index': '12',
|
||||
'ip_fragment_preventing': 'tcp-mss-adjust',
|
||||
'led_state': 'enable',
|
||||
'location': 'test_value_15',
|
||||
'login_passwd': 'test_value_16',
|
||||
'login_passwd_change': 'yes',
|
||||
'mesh_bridge_enable': 'default',
|
||||
'name': 'default_name_19',
|
||||
'override_allowaccess': 'enable',
|
||||
'override_ip_fragment': 'enable',
|
||||
'override_lan': 'enable',
|
||||
'override_led_state': 'enable',
|
||||
'override_login_passwd_change': 'enable',
|
||||
'override_split_tunnel': 'enable',
|
||||
'override_wan_port_mode': 'enable',
|
||||
'split_tunneling_acl_local_ap_subnet': 'enable',
|
||||
'split_tunneling_acl_path': 'tunnel',
|
||||
'tun_mtu_downlink': '29',
|
||||
'tun_mtu_uplink': '30',
|
||||
'wan_port_mode': 'wan-lan',
|
||||
'wtp_id': 'test_value_32',
|
||||
'wtp_mode': 'normal',
|
||||
'wtp_profile': 'test_value_34'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wtp.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('wireless-controller', 'wtp', 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_wireless_controller_wtp_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',
|
||||
'wireless_controller_wtp': {
|
||||
'admin': 'discovered',
|
||||
'allowaccess': 'telnet',
|
||||
'bonjour_profile': 'test_value_5',
|
||||
'coordinate_enable': 'enable',
|
||||
'coordinate_latitude': 'test_value_7',
|
||||
'coordinate_longitude': 'test_value_8',
|
||||
'coordinate_x': 'test_value_9',
|
||||
'coordinate_y': 'test_value_10',
|
||||
'image_download': 'enable',
|
||||
'index': '12',
|
||||
'ip_fragment_preventing': 'tcp-mss-adjust',
|
||||
'led_state': 'enable',
|
||||
'location': 'test_value_15',
|
||||
'login_passwd': 'test_value_16',
|
||||
'login_passwd_change': 'yes',
|
||||
'mesh_bridge_enable': 'default',
|
||||
'name': 'default_name_19',
|
||||
'override_allowaccess': 'enable',
|
||||
'override_ip_fragment': 'enable',
|
||||
'override_lan': 'enable',
|
||||
'override_led_state': 'enable',
|
||||
'override_login_passwd_change': 'enable',
|
||||
'override_split_tunnel': 'enable',
|
||||
'override_wan_port_mode': 'enable',
|
||||
'split_tunneling_acl_local_ap_subnet': 'enable',
|
||||
'split_tunneling_acl_path': 'tunnel',
|
||||
'tun_mtu_downlink': '29',
|
||||
'tun_mtu_uplink': '30',
|
||||
'wan_port_mode': 'wan-lan',
|
||||
'wtp_id': 'test_value_32',
|
||||
'wtp_mode': 'normal',
|
||||
'wtp_profile': 'test_value_34'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wtp.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('wireless-controller', 'wtp', 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_wireless_controller_wtp_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',
|
||||
'wireless_controller_wtp': {
|
||||
'admin': 'discovered',
|
||||
'allowaccess': 'telnet',
|
||||
'bonjour_profile': 'test_value_5',
|
||||
'coordinate_enable': 'enable',
|
||||
'coordinate_latitude': 'test_value_7',
|
||||
'coordinate_longitude': 'test_value_8',
|
||||
'coordinate_x': 'test_value_9',
|
||||
'coordinate_y': 'test_value_10',
|
||||
'image_download': 'enable',
|
||||
'index': '12',
|
||||
'ip_fragment_preventing': 'tcp-mss-adjust',
|
||||
'led_state': 'enable',
|
||||
'location': 'test_value_15',
|
||||
'login_passwd': 'test_value_16',
|
||||
'login_passwd_change': 'yes',
|
||||
'mesh_bridge_enable': 'default',
|
||||
'name': 'default_name_19',
|
||||
'override_allowaccess': 'enable',
|
||||
'override_ip_fragment': 'enable',
|
||||
'override_lan': 'enable',
|
||||
'override_led_state': 'enable',
|
||||
'override_login_passwd_change': 'enable',
|
||||
'override_split_tunnel': 'enable',
|
||||
'override_wan_port_mode': 'enable',
|
||||
'split_tunneling_acl_local_ap_subnet': 'enable',
|
||||
'split_tunneling_acl_path': 'tunnel',
|
||||
'tun_mtu_downlink': '29',
|
||||
'tun_mtu_uplink': '30',
|
||||
'wan_port_mode': 'wan-lan',
|
||||
'wtp_id': 'test_value_32',
|
||||
'wtp_mode': 'normal',
|
||||
'wtp_profile': 'test_value_34'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wtp.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'admin': 'discovered',
|
||||
'allowaccess': 'telnet',
|
||||
'bonjour-profile': 'test_value_5',
|
||||
'coordinate-enable': 'enable',
|
||||
'coordinate-latitude': 'test_value_7',
|
||||
'coordinate-longitude': 'test_value_8',
|
||||
'coordinate-x': 'test_value_9',
|
||||
'coordinate-y': 'test_value_10',
|
||||
'image-download': 'enable',
|
||||
'index': '12',
|
||||
'ip-fragment-preventing': 'tcp-mss-adjust',
|
||||
'led-state': 'enable',
|
||||
'location': 'test_value_15',
|
||||
'login-passwd': 'test_value_16',
|
||||
'login-passwd-change': 'yes',
|
||||
'mesh-bridge-enable': 'default',
|
||||
'name': 'default_name_19',
|
||||
'override-allowaccess': 'enable',
|
||||
'override-ip-fragment': 'enable',
|
||||
'override-lan': 'enable',
|
||||
'override-led-state': 'enable',
|
||||
'override-login-passwd-change': 'enable',
|
||||
'override-split-tunnel': 'enable',
|
||||
'override-wan-port-mode': 'enable',
|
||||
'split-tunneling-acl-local-ap-subnet': 'enable',
|
||||
'split-tunneling-acl-path': 'tunnel',
|
||||
'tun-mtu-downlink': '29',
|
||||
'tun-mtu-uplink': '30',
|
||||
'wan-port-mode': 'wan-lan',
|
||||
'wtp-id': 'test_value_32',
|
||||
'wtp-mode': 'normal',
|
||||
'wtp-profile': 'test_value_34'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'wtp', 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_wireless_controller_wtp_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',
|
||||
'wireless_controller_wtp': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'admin': 'discovered',
|
||||
'allowaccess': 'telnet',
|
||||
'bonjour_profile': 'test_value_5',
|
||||
'coordinate_enable': 'enable',
|
||||
'coordinate_latitude': 'test_value_7',
|
||||
'coordinate_longitude': 'test_value_8',
|
||||
'coordinate_x': 'test_value_9',
|
||||
'coordinate_y': 'test_value_10',
|
||||
'image_download': 'enable',
|
||||
'index': '12',
|
||||
'ip_fragment_preventing': 'tcp-mss-adjust',
|
||||
'led_state': 'enable',
|
||||
'location': 'test_value_15',
|
||||
'login_passwd': 'test_value_16',
|
||||
'login_passwd_change': 'yes',
|
||||
'mesh_bridge_enable': 'default',
|
||||
'name': 'default_name_19',
|
||||
'override_allowaccess': 'enable',
|
||||
'override_ip_fragment': 'enable',
|
||||
'override_lan': 'enable',
|
||||
'override_led_state': 'enable',
|
||||
'override_login_passwd_change': 'enable',
|
||||
'override_split_tunnel': 'enable',
|
||||
'override_wan_port_mode': 'enable',
|
||||
'split_tunneling_acl_local_ap_subnet': 'enable',
|
||||
'split_tunneling_acl_path': 'tunnel',
|
||||
'tun_mtu_downlink': '29',
|
||||
'tun_mtu_uplink': '30',
|
||||
'wan_port_mode': 'wan-lan',
|
||||
'wtp_id': 'test_value_32',
|
||||
'wtp_mode': 'normal',
|
||||
'wtp_profile': 'test_value_34'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wtp.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'admin': 'discovered',
|
||||
'allowaccess': 'telnet',
|
||||
'bonjour-profile': 'test_value_5',
|
||||
'coordinate-enable': 'enable',
|
||||
'coordinate-latitude': 'test_value_7',
|
||||
'coordinate-longitude': 'test_value_8',
|
||||
'coordinate-x': 'test_value_9',
|
||||
'coordinate-y': 'test_value_10',
|
||||
'image-download': 'enable',
|
||||
'index': '12',
|
||||
'ip-fragment-preventing': 'tcp-mss-adjust',
|
||||
'led-state': 'enable',
|
||||
'location': 'test_value_15',
|
||||
'login-passwd': 'test_value_16',
|
||||
'login-passwd-change': 'yes',
|
||||
'mesh-bridge-enable': 'default',
|
||||
'name': 'default_name_19',
|
||||
'override-allowaccess': 'enable',
|
||||
'override-ip-fragment': 'enable',
|
||||
'override-lan': 'enable',
|
||||
'override-led-state': 'enable',
|
||||
'override-login-passwd-change': 'enable',
|
||||
'override-split-tunnel': 'enable',
|
||||
'override-wan-port-mode': 'enable',
|
||||
'split-tunneling-acl-local-ap-subnet': 'enable',
|
||||
'split-tunneling-acl-path': 'tunnel',
|
||||
'tun-mtu-downlink': '29',
|
||||
'tun-mtu-uplink': '30',
|
||||
'wan-port-mode': 'wan-lan',
|
||||
'wtp-id': 'test_value_32',
|
||||
'wtp-mode': 'normal',
|
||||
'wtp-profile': 'test_value_34'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'wtp', 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,439 @@
|
||||
# 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_wireless_controller_wtp_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_wireless_controller_wtp_profile.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_wireless_controller_wtp_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',
|
||||
'wireless_controller_wtp_profile': {
|
||||
'allowaccess': 'telnet',
|
||||
'ap_country': 'NA',
|
||||
'ble_profile': 'test_value_5',
|
||||
'comment': 'Comment.',
|
||||
'control_message_offload': 'ebp-frame',
|
||||
'dtls_in_kernel': 'enable',
|
||||
'dtls_policy': 'clear-text',
|
||||
'energy_efficient_ethernet': 'enable',
|
||||
'ext_info_enable': 'enable',
|
||||
'handoff_roaming': 'enable',
|
||||
'handoff_rssi': '13',
|
||||
'handoff_sta_thresh': '14',
|
||||
'ip_fragment_preventing': 'tcp-mss-adjust',
|
||||
'led_state': 'enable',
|
||||
'lldp': 'enable',
|
||||
'login_passwd': 'test_value_18',
|
||||
'login_passwd_change': 'yes',
|
||||
'max_clients': '20',
|
||||
'name': 'default_name_21',
|
||||
'poe_mode': 'auto',
|
||||
'split_tunneling_acl_local_ap_subnet': 'enable',
|
||||
'split_tunneling_acl_path': 'tunnel',
|
||||
'tun_mtu_downlink': '25',
|
||||
'tun_mtu_uplink': '26',
|
||||
'wan_port_mode': 'wan-lan'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wtp_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allowaccess': 'telnet',
|
||||
'ap-country': 'NA',
|
||||
'ble-profile': 'test_value_5',
|
||||
'comment': 'Comment.',
|
||||
'control-message-offload': 'ebp-frame',
|
||||
'dtls-in-kernel': 'enable',
|
||||
'dtls-policy': 'clear-text',
|
||||
'energy-efficient-ethernet': 'enable',
|
||||
'ext-info-enable': 'enable',
|
||||
'handoff-roaming': 'enable',
|
||||
'handoff-rssi': '13',
|
||||
'handoff-sta-thresh': '14',
|
||||
'ip-fragment-preventing': 'tcp-mss-adjust',
|
||||
'led-state': 'enable',
|
||||
'lldp': 'enable',
|
||||
'login-passwd': 'test_value_18',
|
||||
'login-passwd-change': 'yes',
|
||||
'max-clients': '20',
|
||||
'name': 'default_name_21',
|
||||
'poe-mode': 'auto',
|
||||
'split-tunneling-acl-local-ap-subnet': 'enable',
|
||||
'split-tunneling-acl-path': 'tunnel',
|
||||
'tun-mtu-downlink': '25',
|
||||
'tun-mtu-uplink': '26',
|
||||
'wan-port-mode': 'wan-lan'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'wtp-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_wireless_controller_wtp_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',
|
||||
'wireless_controller_wtp_profile': {
|
||||
'allowaccess': 'telnet',
|
||||
'ap_country': 'NA',
|
||||
'ble_profile': 'test_value_5',
|
||||
'comment': 'Comment.',
|
||||
'control_message_offload': 'ebp-frame',
|
||||
'dtls_in_kernel': 'enable',
|
||||
'dtls_policy': 'clear-text',
|
||||
'energy_efficient_ethernet': 'enable',
|
||||
'ext_info_enable': 'enable',
|
||||
'handoff_roaming': 'enable',
|
||||
'handoff_rssi': '13',
|
||||
'handoff_sta_thresh': '14',
|
||||
'ip_fragment_preventing': 'tcp-mss-adjust',
|
||||
'led_state': 'enable',
|
||||
'lldp': 'enable',
|
||||
'login_passwd': 'test_value_18',
|
||||
'login_passwd_change': 'yes',
|
||||
'max_clients': '20',
|
||||
'name': 'default_name_21',
|
||||
'poe_mode': 'auto',
|
||||
'split_tunneling_acl_local_ap_subnet': 'enable',
|
||||
'split_tunneling_acl_path': 'tunnel',
|
||||
'tun_mtu_downlink': '25',
|
||||
'tun_mtu_uplink': '26',
|
||||
'wan_port_mode': 'wan-lan'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wtp_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allowaccess': 'telnet',
|
||||
'ap-country': 'NA',
|
||||
'ble-profile': 'test_value_5',
|
||||
'comment': 'Comment.',
|
||||
'control-message-offload': 'ebp-frame',
|
||||
'dtls-in-kernel': 'enable',
|
||||
'dtls-policy': 'clear-text',
|
||||
'energy-efficient-ethernet': 'enable',
|
||||
'ext-info-enable': 'enable',
|
||||
'handoff-roaming': 'enable',
|
||||
'handoff-rssi': '13',
|
||||
'handoff-sta-thresh': '14',
|
||||
'ip-fragment-preventing': 'tcp-mss-adjust',
|
||||
'led-state': 'enable',
|
||||
'lldp': 'enable',
|
||||
'login-passwd': 'test_value_18',
|
||||
'login-passwd-change': 'yes',
|
||||
'max-clients': '20',
|
||||
'name': 'default_name_21',
|
||||
'poe-mode': 'auto',
|
||||
'split-tunneling-acl-local-ap-subnet': 'enable',
|
||||
'split-tunneling-acl-path': 'tunnel',
|
||||
'tun-mtu-downlink': '25',
|
||||
'tun-mtu-uplink': '26',
|
||||
'wan-port-mode': 'wan-lan'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'wtp-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_wireless_controller_wtp_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',
|
||||
'wireless_controller_wtp_profile': {
|
||||
'allowaccess': 'telnet',
|
||||
'ap_country': 'NA',
|
||||
'ble_profile': 'test_value_5',
|
||||
'comment': 'Comment.',
|
||||
'control_message_offload': 'ebp-frame',
|
||||
'dtls_in_kernel': 'enable',
|
||||
'dtls_policy': 'clear-text',
|
||||
'energy_efficient_ethernet': 'enable',
|
||||
'ext_info_enable': 'enable',
|
||||
'handoff_roaming': 'enable',
|
||||
'handoff_rssi': '13',
|
||||
'handoff_sta_thresh': '14',
|
||||
'ip_fragment_preventing': 'tcp-mss-adjust',
|
||||
'led_state': 'enable',
|
||||
'lldp': 'enable',
|
||||
'login_passwd': 'test_value_18',
|
||||
'login_passwd_change': 'yes',
|
||||
'max_clients': '20',
|
||||
'name': 'default_name_21',
|
||||
'poe_mode': 'auto',
|
||||
'split_tunneling_acl_local_ap_subnet': 'enable',
|
||||
'split_tunneling_acl_path': 'tunnel',
|
||||
'tun_mtu_downlink': '25',
|
||||
'tun_mtu_uplink': '26',
|
||||
'wan_port_mode': 'wan-lan'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wtp_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('wireless-controller', 'wtp-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_wireless_controller_wtp_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',
|
||||
'wireless_controller_wtp_profile': {
|
||||
'allowaccess': 'telnet',
|
||||
'ap_country': 'NA',
|
||||
'ble_profile': 'test_value_5',
|
||||
'comment': 'Comment.',
|
||||
'control_message_offload': 'ebp-frame',
|
||||
'dtls_in_kernel': 'enable',
|
||||
'dtls_policy': 'clear-text',
|
||||
'energy_efficient_ethernet': 'enable',
|
||||
'ext_info_enable': 'enable',
|
||||
'handoff_roaming': 'enable',
|
||||
'handoff_rssi': '13',
|
||||
'handoff_sta_thresh': '14',
|
||||
'ip_fragment_preventing': 'tcp-mss-adjust',
|
||||
'led_state': 'enable',
|
||||
'lldp': 'enable',
|
||||
'login_passwd': 'test_value_18',
|
||||
'login_passwd_change': 'yes',
|
||||
'max_clients': '20',
|
||||
'name': 'default_name_21',
|
||||
'poe_mode': 'auto',
|
||||
'split_tunneling_acl_local_ap_subnet': 'enable',
|
||||
'split_tunneling_acl_path': 'tunnel',
|
||||
'tun_mtu_downlink': '25',
|
||||
'tun_mtu_uplink': '26',
|
||||
'wan_port_mode': 'wan-lan'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wtp_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('wireless-controller', 'wtp-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_wireless_controller_wtp_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',
|
||||
'wireless_controller_wtp_profile': {
|
||||
'allowaccess': 'telnet',
|
||||
'ap_country': 'NA',
|
||||
'ble_profile': 'test_value_5',
|
||||
'comment': 'Comment.',
|
||||
'control_message_offload': 'ebp-frame',
|
||||
'dtls_in_kernel': 'enable',
|
||||
'dtls_policy': 'clear-text',
|
||||
'energy_efficient_ethernet': 'enable',
|
||||
'ext_info_enable': 'enable',
|
||||
'handoff_roaming': 'enable',
|
||||
'handoff_rssi': '13',
|
||||
'handoff_sta_thresh': '14',
|
||||
'ip_fragment_preventing': 'tcp-mss-adjust',
|
||||
'led_state': 'enable',
|
||||
'lldp': 'enable',
|
||||
'login_passwd': 'test_value_18',
|
||||
'login_passwd_change': 'yes',
|
||||
'max_clients': '20',
|
||||
'name': 'default_name_21',
|
||||
'poe_mode': 'auto',
|
||||
'split_tunneling_acl_local_ap_subnet': 'enable',
|
||||
'split_tunneling_acl_path': 'tunnel',
|
||||
'tun_mtu_downlink': '25',
|
||||
'tun_mtu_uplink': '26',
|
||||
'wan_port_mode': 'wan-lan'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wtp_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allowaccess': 'telnet',
|
||||
'ap-country': 'NA',
|
||||
'ble-profile': 'test_value_5',
|
||||
'comment': 'Comment.',
|
||||
'control-message-offload': 'ebp-frame',
|
||||
'dtls-in-kernel': 'enable',
|
||||
'dtls-policy': 'clear-text',
|
||||
'energy-efficient-ethernet': 'enable',
|
||||
'ext-info-enable': 'enable',
|
||||
'handoff-roaming': 'enable',
|
||||
'handoff-rssi': '13',
|
||||
'handoff-sta-thresh': '14',
|
||||
'ip-fragment-preventing': 'tcp-mss-adjust',
|
||||
'led-state': 'enable',
|
||||
'lldp': 'enable',
|
||||
'login-passwd': 'test_value_18',
|
||||
'login-passwd-change': 'yes',
|
||||
'max-clients': '20',
|
||||
'name': 'default_name_21',
|
||||
'poe-mode': 'auto',
|
||||
'split-tunneling-acl-local-ap-subnet': 'enable',
|
||||
'split-tunneling-acl-path': 'tunnel',
|
||||
'tun-mtu-downlink': '25',
|
||||
'tun-mtu-uplink': '26',
|
||||
'wan-port-mode': 'wan-lan'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'wtp-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_wireless_controller_wtp_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',
|
||||
'wireless_controller_wtp_profile': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'allowaccess': 'telnet',
|
||||
'ap_country': 'NA',
|
||||
'ble_profile': 'test_value_5',
|
||||
'comment': 'Comment.',
|
||||
'control_message_offload': 'ebp-frame',
|
||||
'dtls_in_kernel': 'enable',
|
||||
'dtls_policy': 'clear-text',
|
||||
'energy_efficient_ethernet': 'enable',
|
||||
'ext_info_enable': 'enable',
|
||||
'handoff_roaming': 'enable',
|
||||
'handoff_rssi': '13',
|
||||
'handoff_sta_thresh': '14',
|
||||
'ip_fragment_preventing': 'tcp-mss-adjust',
|
||||
'led_state': 'enable',
|
||||
'lldp': 'enable',
|
||||
'login_passwd': 'test_value_18',
|
||||
'login_passwd_change': 'yes',
|
||||
'max_clients': '20',
|
||||
'name': 'default_name_21',
|
||||
'poe_mode': 'auto',
|
||||
'split_tunneling_acl_local_ap_subnet': 'enable',
|
||||
'split_tunneling_acl_path': 'tunnel',
|
||||
'tun_mtu_downlink': '25',
|
||||
'tun_mtu_uplink': '26',
|
||||
'wan_port_mode': 'wan-lan'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_wireless_controller_wtp_profile.fortios_wireless_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allowaccess': 'telnet',
|
||||
'ap-country': 'NA',
|
||||
'ble-profile': 'test_value_5',
|
||||
'comment': 'Comment.',
|
||||
'control-message-offload': 'ebp-frame',
|
||||
'dtls-in-kernel': 'enable',
|
||||
'dtls-policy': 'clear-text',
|
||||
'energy-efficient-ethernet': 'enable',
|
||||
'ext-info-enable': 'enable',
|
||||
'handoff-roaming': 'enable',
|
||||
'handoff-rssi': '13',
|
||||
'handoff-sta-thresh': '14',
|
||||
'ip-fragment-preventing': 'tcp-mss-adjust',
|
||||
'led-state': 'enable',
|
||||
'lldp': 'enable',
|
||||
'login-passwd': 'test_value_18',
|
||||
'login-passwd-change': 'yes',
|
||||
'max-clients': '20',
|
||||
'name': 'default_name_21',
|
||||
'poe-mode': 'auto',
|
||||
'split-tunneling-acl-local-ap-subnet': 'enable',
|
||||
'split-tunneling-acl-path': 'tunnel',
|
||||
'tun-mtu-downlink': '25',
|
||||
'tun-mtu-uplink': '26',
|
||||
'wan-port-mode': 'wan-lan'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('wireless-controller', 'wtp-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
|
Loading…
Reference in New Issue