mirror of https://github.com/ansible/ansible.git
FortiOS modules for 2.9 - 5 (#61062)
* FortiOS modules for 2.9 - 5 * Update fortios_firewall_vip.py * Update fortios_firewall_vip6.pypull/61170/head
parent
3373a2518a
commit
628aa3a808
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,309 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_firewall_ssl_ssh_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_firewall_ssl_ssh_profile.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ssl_ssh_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',
|
||||||
|
'firewall_ssl_ssh_profile': {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'mapi_over_https': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'rpc_over_https': 'enable',
|
||||||
|
'server_cert': 'test_value_8',
|
||||||
|
'server_cert_mode': 're-sign',
|
||||||
|
'ssl_anomalies_log': 'disable',
|
||||||
|
'ssl_exemptions_log': 'disable',
|
||||||
|
'untrusted_caname': 'test_value_12',
|
||||||
|
'use_ssl_server': 'disable',
|
||||||
|
'whitelist': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_ssh_profile.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'mapi-over-https': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'rpc-over-https': 'enable',
|
||||||
|
'server-cert': 'test_value_8',
|
||||||
|
'server-cert-mode': 're-sign',
|
||||||
|
'ssl-anomalies-log': 'disable',
|
||||||
|
'ssl-exemptions-log': 'disable',
|
||||||
|
'untrusted-caname': 'test_value_12',
|
||||||
|
'use-ssl-server': 'disable',
|
||||||
|
'whitelist': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'ssl-ssh-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_firewall_ssl_ssh_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',
|
||||||
|
'firewall_ssl_ssh_profile': {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'mapi_over_https': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'rpc_over_https': 'enable',
|
||||||
|
'server_cert': 'test_value_8',
|
||||||
|
'server_cert_mode': 're-sign',
|
||||||
|
'ssl_anomalies_log': 'disable',
|
||||||
|
'ssl_exemptions_log': 'disable',
|
||||||
|
'untrusted_caname': 'test_value_12',
|
||||||
|
'use_ssl_server': 'disable',
|
||||||
|
'whitelist': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_ssh_profile.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'mapi-over-https': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'rpc-over-https': 'enable',
|
||||||
|
'server-cert': 'test_value_8',
|
||||||
|
'server-cert-mode': 're-sign',
|
||||||
|
'ssl-anomalies-log': 'disable',
|
||||||
|
'ssl-exemptions-log': 'disable',
|
||||||
|
'untrusted-caname': 'test_value_12',
|
||||||
|
'use-ssl-server': 'disable',
|
||||||
|
'whitelist': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'ssl-ssh-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_firewall_ssl_ssh_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',
|
||||||
|
'firewall_ssl_ssh_profile': {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'mapi_over_https': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'rpc_over_https': 'enable',
|
||||||
|
'server_cert': 'test_value_8',
|
||||||
|
'server_cert_mode': 're-sign',
|
||||||
|
'ssl_anomalies_log': 'disable',
|
||||||
|
'ssl_exemptions_log': 'disable',
|
||||||
|
'untrusted_caname': 'test_value_12',
|
||||||
|
'use_ssl_server': 'disable',
|
||||||
|
'whitelist': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_ssh_profile.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'ssl-ssh-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_firewall_ssl_ssh_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',
|
||||||
|
'firewall_ssl_ssh_profile': {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'mapi_over_https': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'rpc_over_https': 'enable',
|
||||||
|
'server_cert': 'test_value_8',
|
||||||
|
'server_cert_mode': 're-sign',
|
||||||
|
'ssl_anomalies_log': 'disable',
|
||||||
|
'ssl_exemptions_log': 'disable',
|
||||||
|
'untrusted_caname': 'test_value_12',
|
||||||
|
'use_ssl_server': 'disable',
|
||||||
|
'whitelist': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_ssh_profile.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'ssl-ssh-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_firewall_ssl_ssh_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',
|
||||||
|
'firewall_ssl_ssh_profile': {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'mapi_over_https': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'rpc_over_https': 'enable',
|
||||||
|
'server_cert': 'test_value_8',
|
||||||
|
'server_cert_mode': 're-sign',
|
||||||
|
'ssl_anomalies_log': 'disable',
|
||||||
|
'ssl_exemptions_log': 'disable',
|
||||||
|
'untrusted_caname': 'test_value_12',
|
||||||
|
'use_ssl_server': 'disable',
|
||||||
|
'whitelist': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_ssh_profile.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'mapi-over-https': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'rpc-over-https': 'enable',
|
||||||
|
'server-cert': 'test_value_8',
|
||||||
|
'server-cert-mode': 're-sign',
|
||||||
|
'ssl-anomalies-log': 'disable',
|
||||||
|
'ssl-exemptions-log': 'disable',
|
||||||
|
'untrusted-caname': 'test_value_12',
|
||||||
|
'use-ssl-server': 'disable',
|
||||||
|
'whitelist': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'ssl-ssh-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_firewall_ssl_ssh_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',
|
||||||
|
'firewall_ssl_ssh_profile': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'mapi_over_https': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'rpc_over_https': 'enable',
|
||||||
|
'server_cert': 'test_value_8',
|
||||||
|
'server_cert_mode': 're-sign',
|
||||||
|
'ssl_anomalies_log': 'disable',
|
||||||
|
'ssl_exemptions_log': 'disable',
|
||||||
|
'untrusted_caname': 'test_value_12',
|
||||||
|
'use_ssl_server': 'disable',
|
||||||
|
'whitelist': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_ssh_profile.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'mapi-over-https': 'enable',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'rpc-over-https': 'enable',
|
||||||
|
'server-cert': 'test_value_8',
|
||||||
|
'server-cert-mode': 're-sign',
|
||||||
|
'ssl-anomalies-log': 'disable',
|
||||||
|
'ssl-exemptions-log': 'disable',
|
||||||
|
'untrusted-caname': 'test_value_12',
|
||||||
|
'use-ssl-server': 'disable',
|
||||||
|
'whitelist': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'ssl-ssh-profile', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,249 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_firewall_ttl_policy
|
||||||
|
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_firewall_ttl_policy.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ttl_policy_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',
|
||||||
|
'firewall_ttl_policy': {
|
||||||
|
'action': 'accept',
|
||||||
|
'id': '4',
|
||||||
|
'schedule': 'test_value_5',
|
||||||
|
'srcintf': 'test_value_6',
|
||||||
|
'status': 'enable',
|
||||||
|
'ttl': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ttl_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'accept',
|
||||||
|
'id': '4',
|
||||||
|
'schedule': 'test_value_5',
|
||||||
|
'srcintf': 'test_value_6',
|
||||||
|
'status': 'enable',
|
||||||
|
'ttl': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'ttl-policy', 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_firewall_ttl_policy_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',
|
||||||
|
'firewall_ttl_policy': {
|
||||||
|
'action': 'accept',
|
||||||
|
'id': '4',
|
||||||
|
'schedule': 'test_value_5',
|
||||||
|
'srcintf': 'test_value_6',
|
||||||
|
'status': 'enable',
|
||||||
|
'ttl': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ttl_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'accept',
|
||||||
|
'id': '4',
|
||||||
|
'schedule': 'test_value_5',
|
||||||
|
'srcintf': 'test_value_6',
|
||||||
|
'status': 'enable',
|
||||||
|
'ttl': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'ttl-policy', 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_firewall_ttl_policy_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',
|
||||||
|
'firewall_ttl_policy': {
|
||||||
|
'action': 'accept',
|
||||||
|
'id': '4',
|
||||||
|
'schedule': 'test_value_5',
|
||||||
|
'srcintf': 'test_value_6',
|
||||||
|
'status': 'enable',
|
||||||
|
'ttl': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ttl_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'ttl-policy', 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_firewall_ttl_policy_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',
|
||||||
|
'firewall_ttl_policy': {
|
||||||
|
'action': 'accept',
|
||||||
|
'id': '4',
|
||||||
|
'schedule': 'test_value_5',
|
||||||
|
'srcintf': 'test_value_6',
|
||||||
|
'status': 'enable',
|
||||||
|
'ttl': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ttl_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'ttl-policy', 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_firewall_ttl_policy_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',
|
||||||
|
'firewall_ttl_policy': {
|
||||||
|
'action': 'accept',
|
||||||
|
'id': '4',
|
||||||
|
'schedule': 'test_value_5',
|
||||||
|
'srcintf': 'test_value_6',
|
||||||
|
'status': 'enable',
|
||||||
|
'ttl': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ttl_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'accept',
|
||||||
|
'id': '4',
|
||||||
|
'schedule': 'test_value_5',
|
||||||
|
'srcintf': 'test_value_6',
|
||||||
|
'status': 'enable',
|
||||||
|
'ttl': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'ttl-policy', 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_firewall_ttl_policy_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',
|
||||||
|
'firewall_ttl_policy': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'action': 'accept',
|
||||||
|
'id': '4',
|
||||||
|
'schedule': 'test_value_5',
|
||||||
|
'srcintf': 'test_value_6',
|
||||||
|
'status': 'enable',
|
||||||
|
'ttl': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ttl_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'accept',
|
||||||
|
'id': '4',
|
||||||
|
'schedule': 'test_value_5',
|
||||||
|
'srcintf': 'test_value_6',
|
||||||
|
'status': 'enable',
|
||||||
|
'ttl': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'ttl-policy', 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,839 @@
|
|||||||
|
# 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_firewall_vip
|
||||||
|
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_firewall_vip.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_vip_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',
|
||||||
|
'firewall_vip': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dns_mapping_ttl': '6',
|
||||||
|
'extintf': 'test_value_7',
|
||||||
|
'extip': 'test_value_8',
|
||||||
|
'extport': 'test_value_9',
|
||||||
|
'gratuitous_arp_interval': '10',
|
||||||
|
'http_cookie_age': '11',
|
||||||
|
'http_cookie_domain': 'test_value_12',
|
||||||
|
'http_cookie_domain_from_host': 'disable',
|
||||||
|
'http_cookie_generation': '14',
|
||||||
|
'http_cookie_path': 'test_value_15',
|
||||||
|
'http_cookie_share': 'disable',
|
||||||
|
'http_ip_header': 'enable',
|
||||||
|
'http_ip_header_name': 'test_value_18',
|
||||||
|
'http_multiplex': 'enable',
|
||||||
|
'https_cookie_secure': 'disable',
|
||||||
|
'id': '21',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mapped_addr': 'test_value_23',
|
||||||
|
'mappedport': 'test_value_24',
|
||||||
|
'max_embryonic_connections': '25',
|
||||||
|
'name': 'default_name_26',
|
||||||
|
'nat_source_vip': 'disable',
|
||||||
|
'outlook_web_access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'portmapping_type': '1-to-1',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_certificate': 'test_value_35',
|
||||||
|
'ssl_client_fallback': 'disable',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_client_session_state_max': '38',
|
||||||
|
'ssl_client_session_state_timeout': '39',
|
||||||
|
'ssl_client_session_state_type': 'disable',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_hpkp': 'disable',
|
||||||
|
'ssl_hpkp_age': '43',
|
||||||
|
'ssl_hpkp_backup': 'test_value_44',
|
||||||
|
'ssl_hpkp_include_subdomains': 'disable',
|
||||||
|
'ssl_hpkp_primary': 'test_value_46',
|
||||||
|
'ssl_hpkp_report_uri': 'test_value_47',
|
||||||
|
'ssl_hsts': 'disable',
|
||||||
|
'ssl_hsts_age': '49',
|
||||||
|
'ssl_hsts_include_subdomains': 'disable',
|
||||||
|
'ssl_http_location_conversion': 'enable',
|
||||||
|
'ssl_http_match_host': 'enable',
|
||||||
|
'ssl_max_version': 'ssl-3.0',
|
||||||
|
'ssl_min_version': 'ssl-3.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_pfs': 'require',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'ssl_server_algorithm': 'high',
|
||||||
|
'ssl_server_max_version': 'ssl-3.0',
|
||||||
|
'ssl_server_min_version': 'ssl-3.0',
|
||||||
|
'ssl_server_session_state_max': '61',
|
||||||
|
'ssl_server_session_state_timeout': '62',
|
||||||
|
'ssl_server_session_state_type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_65',
|
||||||
|
'weblogic_server': 'disable',
|
||||||
|
'websphere_server': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dns-mapping-ttl': '6',
|
||||||
|
'extintf': 'test_value_7',
|
||||||
|
'extip': 'test_value_8',
|
||||||
|
'extport': 'test_value_9',
|
||||||
|
'gratuitous-arp-interval': '10',
|
||||||
|
'http-cookie-age': '11',
|
||||||
|
'http-cookie-domain': 'test_value_12',
|
||||||
|
'http-cookie-domain-from-host': 'disable',
|
||||||
|
'http-cookie-generation': '14',
|
||||||
|
'http-cookie-path': 'test_value_15',
|
||||||
|
'http-cookie-share': 'disable',
|
||||||
|
'http-ip-header': 'enable',
|
||||||
|
'http-ip-header-name': 'test_value_18',
|
||||||
|
'http-multiplex': 'enable',
|
||||||
|
'https-cookie-secure': 'disable',
|
||||||
|
'id': '21',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mapped-addr': 'test_value_23',
|
||||||
|
'mappedport': 'test_value_24',
|
||||||
|
'max-embryonic-connections': '25',
|
||||||
|
'name': 'default_name_26',
|
||||||
|
'nat-source-vip': 'disable',
|
||||||
|
'outlook-web-access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'portmapping-type': '1-to-1',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'ssl-algorithm': 'high',
|
||||||
|
'ssl-certificate': 'test_value_35',
|
||||||
|
'ssl-client-fallback': 'disable',
|
||||||
|
'ssl-client-renegotiation': 'allow',
|
||||||
|
'ssl-client-session-state-max': '38',
|
||||||
|
'ssl-client-session-state-timeout': '39',
|
||||||
|
'ssl-client-session-state-type': 'disable',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-hpkp': 'disable',
|
||||||
|
'ssl-hpkp-age': '43',
|
||||||
|
'ssl-hpkp-backup': 'test_value_44',
|
||||||
|
'ssl-hpkp-include-subdomains': 'disable',
|
||||||
|
'ssl-hpkp-primary': 'test_value_46',
|
||||||
|
'ssl-hpkp-report-uri': 'test_value_47',
|
||||||
|
'ssl-hsts': 'disable',
|
||||||
|
'ssl-hsts-age': '49',
|
||||||
|
'ssl-hsts-include-subdomains': 'disable',
|
||||||
|
'ssl-http-location-conversion': 'enable',
|
||||||
|
'ssl-http-match-host': 'enable',
|
||||||
|
'ssl-max-version': 'ssl-3.0',
|
||||||
|
'ssl-min-version': 'ssl-3.0',
|
||||||
|
'ssl-mode': 'half',
|
||||||
|
'ssl-pfs': 'require',
|
||||||
|
'ssl-send-empty-frags': 'enable',
|
||||||
|
'ssl-server-algorithm': 'high',
|
||||||
|
'ssl-server-max-version': 'ssl-3.0',
|
||||||
|
'ssl-server-min-version': 'ssl-3.0',
|
||||||
|
'ssl-server-session-state-max': '61',
|
||||||
|
'ssl-server-session-state-timeout': '62',
|
||||||
|
'ssl-server-session-state-type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_65',
|
||||||
|
'weblogic-server': 'disable',
|
||||||
|
'websphere-server': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip', 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_firewall_vip_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',
|
||||||
|
'firewall_vip': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dns_mapping_ttl': '6',
|
||||||
|
'extintf': 'test_value_7',
|
||||||
|
'extip': 'test_value_8',
|
||||||
|
'extport': 'test_value_9',
|
||||||
|
'gratuitous_arp_interval': '10',
|
||||||
|
'http_cookie_age': '11',
|
||||||
|
'http_cookie_domain': 'test_value_12',
|
||||||
|
'http_cookie_domain_from_host': 'disable',
|
||||||
|
'http_cookie_generation': '14',
|
||||||
|
'http_cookie_path': 'test_value_15',
|
||||||
|
'http_cookie_share': 'disable',
|
||||||
|
'http_ip_header': 'enable',
|
||||||
|
'http_ip_header_name': 'test_value_18',
|
||||||
|
'http_multiplex': 'enable',
|
||||||
|
'https_cookie_secure': 'disable',
|
||||||
|
'id': '21',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mapped_addr': 'test_value_23',
|
||||||
|
'mappedport': 'test_value_24',
|
||||||
|
'max_embryonic_connections': '25',
|
||||||
|
'name': 'default_name_26',
|
||||||
|
'nat_source_vip': 'disable',
|
||||||
|
'outlook_web_access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'portmapping_type': '1-to-1',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_certificate': 'test_value_35',
|
||||||
|
'ssl_client_fallback': 'disable',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_client_session_state_max': '38',
|
||||||
|
'ssl_client_session_state_timeout': '39',
|
||||||
|
'ssl_client_session_state_type': 'disable',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_hpkp': 'disable',
|
||||||
|
'ssl_hpkp_age': '43',
|
||||||
|
'ssl_hpkp_backup': 'test_value_44',
|
||||||
|
'ssl_hpkp_include_subdomains': 'disable',
|
||||||
|
'ssl_hpkp_primary': 'test_value_46',
|
||||||
|
'ssl_hpkp_report_uri': 'test_value_47',
|
||||||
|
'ssl_hsts': 'disable',
|
||||||
|
'ssl_hsts_age': '49',
|
||||||
|
'ssl_hsts_include_subdomains': 'disable',
|
||||||
|
'ssl_http_location_conversion': 'enable',
|
||||||
|
'ssl_http_match_host': 'enable',
|
||||||
|
'ssl_max_version': 'ssl-3.0',
|
||||||
|
'ssl_min_version': 'ssl-3.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_pfs': 'require',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'ssl_server_algorithm': 'high',
|
||||||
|
'ssl_server_max_version': 'ssl-3.0',
|
||||||
|
'ssl_server_min_version': 'ssl-3.0',
|
||||||
|
'ssl_server_session_state_max': '61',
|
||||||
|
'ssl_server_session_state_timeout': '62',
|
||||||
|
'ssl_server_session_state_type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_65',
|
||||||
|
'weblogic_server': 'disable',
|
||||||
|
'websphere_server': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dns-mapping-ttl': '6',
|
||||||
|
'extintf': 'test_value_7',
|
||||||
|
'extip': 'test_value_8',
|
||||||
|
'extport': 'test_value_9',
|
||||||
|
'gratuitous-arp-interval': '10',
|
||||||
|
'http-cookie-age': '11',
|
||||||
|
'http-cookie-domain': 'test_value_12',
|
||||||
|
'http-cookie-domain-from-host': 'disable',
|
||||||
|
'http-cookie-generation': '14',
|
||||||
|
'http-cookie-path': 'test_value_15',
|
||||||
|
'http-cookie-share': 'disable',
|
||||||
|
'http-ip-header': 'enable',
|
||||||
|
'http-ip-header-name': 'test_value_18',
|
||||||
|
'http-multiplex': 'enable',
|
||||||
|
'https-cookie-secure': 'disable',
|
||||||
|
'id': '21',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mapped-addr': 'test_value_23',
|
||||||
|
'mappedport': 'test_value_24',
|
||||||
|
'max-embryonic-connections': '25',
|
||||||
|
'name': 'default_name_26',
|
||||||
|
'nat-source-vip': 'disable',
|
||||||
|
'outlook-web-access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'portmapping-type': '1-to-1',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'ssl-algorithm': 'high',
|
||||||
|
'ssl-certificate': 'test_value_35',
|
||||||
|
'ssl-client-fallback': 'disable',
|
||||||
|
'ssl-client-renegotiation': 'allow',
|
||||||
|
'ssl-client-session-state-max': '38',
|
||||||
|
'ssl-client-session-state-timeout': '39',
|
||||||
|
'ssl-client-session-state-type': 'disable',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-hpkp': 'disable',
|
||||||
|
'ssl-hpkp-age': '43',
|
||||||
|
'ssl-hpkp-backup': 'test_value_44',
|
||||||
|
'ssl-hpkp-include-subdomains': 'disable',
|
||||||
|
'ssl-hpkp-primary': 'test_value_46',
|
||||||
|
'ssl-hpkp-report-uri': 'test_value_47',
|
||||||
|
'ssl-hsts': 'disable',
|
||||||
|
'ssl-hsts-age': '49',
|
||||||
|
'ssl-hsts-include-subdomains': 'disable',
|
||||||
|
'ssl-http-location-conversion': 'enable',
|
||||||
|
'ssl-http-match-host': 'enable',
|
||||||
|
'ssl-max-version': 'ssl-3.0',
|
||||||
|
'ssl-min-version': 'ssl-3.0',
|
||||||
|
'ssl-mode': 'half',
|
||||||
|
'ssl-pfs': 'require',
|
||||||
|
'ssl-send-empty-frags': 'enable',
|
||||||
|
'ssl-server-algorithm': 'high',
|
||||||
|
'ssl-server-max-version': 'ssl-3.0',
|
||||||
|
'ssl-server-min-version': 'ssl-3.0',
|
||||||
|
'ssl-server-session-state-max': '61',
|
||||||
|
'ssl-server-session-state-timeout': '62',
|
||||||
|
'ssl-server-session-state-type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_65',
|
||||||
|
'weblogic-server': 'disable',
|
||||||
|
'websphere-server': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip', 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_firewall_vip_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',
|
||||||
|
'firewall_vip': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dns_mapping_ttl': '6',
|
||||||
|
'extintf': 'test_value_7',
|
||||||
|
'extip': 'test_value_8',
|
||||||
|
'extport': 'test_value_9',
|
||||||
|
'gratuitous_arp_interval': '10',
|
||||||
|
'http_cookie_age': '11',
|
||||||
|
'http_cookie_domain': 'test_value_12',
|
||||||
|
'http_cookie_domain_from_host': 'disable',
|
||||||
|
'http_cookie_generation': '14',
|
||||||
|
'http_cookie_path': 'test_value_15',
|
||||||
|
'http_cookie_share': 'disable',
|
||||||
|
'http_ip_header': 'enable',
|
||||||
|
'http_ip_header_name': 'test_value_18',
|
||||||
|
'http_multiplex': 'enable',
|
||||||
|
'https_cookie_secure': 'disable',
|
||||||
|
'id': '21',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mapped_addr': 'test_value_23',
|
||||||
|
'mappedport': 'test_value_24',
|
||||||
|
'max_embryonic_connections': '25',
|
||||||
|
'name': 'default_name_26',
|
||||||
|
'nat_source_vip': 'disable',
|
||||||
|
'outlook_web_access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'portmapping_type': '1-to-1',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_certificate': 'test_value_35',
|
||||||
|
'ssl_client_fallback': 'disable',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_client_session_state_max': '38',
|
||||||
|
'ssl_client_session_state_timeout': '39',
|
||||||
|
'ssl_client_session_state_type': 'disable',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_hpkp': 'disable',
|
||||||
|
'ssl_hpkp_age': '43',
|
||||||
|
'ssl_hpkp_backup': 'test_value_44',
|
||||||
|
'ssl_hpkp_include_subdomains': 'disable',
|
||||||
|
'ssl_hpkp_primary': 'test_value_46',
|
||||||
|
'ssl_hpkp_report_uri': 'test_value_47',
|
||||||
|
'ssl_hsts': 'disable',
|
||||||
|
'ssl_hsts_age': '49',
|
||||||
|
'ssl_hsts_include_subdomains': 'disable',
|
||||||
|
'ssl_http_location_conversion': 'enable',
|
||||||
|
'ssl_http_match_host': 'enable',
|
||||||
|
'ssl_max_version': 'ssl-3.0',
|
||||||
|
'ssl_min_version': 'ssl-3.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_pfs': 'require',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'ssl_server_algorithm': 'high',
|
||||||
|
'ssl_server_max_version': 'ssl-3.0',
|
||||||
|
'ssl_server_min_version': 'ssl-3.0',
|
||||||
|
'ssl_server_session_state_max': '61',
|
||||||
|
'ssl_server_session_state_timeout': '62',
|
||||||
|
'ssl_server_session_state_type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_65',
|
||||||
|
'weblogic_server': 'disable',
|
||||||
|
'websphere_server': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vip', 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_firewall_vip_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',
|
||||||
|
'firewall_vip': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dns_mapping_ttl': '6',
|
||||||
|
'extintf': 'test_value_7',
|
||||||
|
'extip': 'test_value_8',
|
||||||
|
'extport': 'test_value_9',
|
||||||
|
'gratuitous_arp_interval': '10',
|
||||||
|
'http_cookie_age': '11',
|
||||||
|
'http_cookie_domain': 'test_value_12',
|
||||||
|
'http_cookie_domain_from_host': 'disable',
|
||||||
|
'http_cookie_generation': '14',
|
||||||
|
'http_cookie_path': 'test_value_15',
|
||||||
|
'http_cookie_share': 'disable',
|
||||||
|
'http_ip_header': 'enable',
|
||||||
|
'http_ip_header_name': 'test_value_18',
|
||||||
|
'http_multiplex': 'enable',
|
||||||
|
'https_cookie_secure': 'disable',
|
||||||
|
'id': '21',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mapped_addr': 'test_value_23',
|
||||||
|
'mappedport': 'test_value_24',
|
||||||
|
'max_embryonic_connections': '25',
|
||||||
|
'name': 'default_name_26',
|
||||||
|
'nat_source_vip': 'disable',
|
||||||
|
'outlook_web_access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'portmapping_type': '1-to-1',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_certificate': 'test_value_35',
|
||||||
|
'ssl_client_fallback': 'disable',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_client_session_state_max': '38',
|
||||||
|
'ssl_client_session_state_timeout': '39',
|
||||||
|
'ssl_client_session_state_type': 'disable',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_hpkp': 'disable',
|
||||||
|
'ssl_hpkp_age': '43',
|
||||||
|
'ssl_hpkp_backup': 'test_value_44',
|
||||||
|
'ssl_hpkp_include_subdomains': 'disable',
|
||||||
|
'ssl_hpkp_primary': 'test_value_46',
|
||||||
|
'ssl_hpkp_report_uri': 'test_value_47',
|
||||||
|
'ssl_hsts': 'disable',
|
||||||
|
'ssl_hsts_age': '49',
|
||||||
|
'ssl_hsts_include_subdomains': 'disable',
|
||||||
|
'ssl_http_location_conversion': 'enable',
|
||||||
|
'ssl_http_match_host': 'enable',
|
||||||
|
'ssl_max_version': 'ssl-3.0',
|
||||||
|
'ssl_min_version': 'ssl-3.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_pfs': 'require',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'ssl_server_algorithm': 'high',
|
||||||
|
'ssl_server_max_version': 'ssl-3.0',
|
||||||
|
'ssl_server_min_version': 'ssl-3.0',
|
||||||
|
'ssl_server_session_state_max': '61',
|
||||||
|
'ssl_server_session_state_timeout': '62',
|
||||||
|
'ssl_server_session_state_type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_65',
|
||||||
|
'weblogic_server': 'disable',
|
||||||
|
'websphere_server': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vip', 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_firewall_vip_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',
|
||||||
|
'firewall_vip': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dns_mapping_ttl': '6',
|
||||||
|
'extintf': 'test_value_7',
|
||||||
|
'extip': 'test_value_8',
|
||||||
|
'extport': 'test_value_9',
|
||||||
|
'gratuitous_arp_interval': '10',
|
||||||
|
'http_cookie_age': '11',
|
||||||
|
'http_cookie_domain': 'test_value_12',
|
||||||
|
'http_cookie_domain_from_host': 'disable',
|
||||||
|
'http_cookie_generation': '14',
|
||||||
|
'http_cookie_path': 'test_value_15',
|
||||||
|
'http_cookie_share': 'disable',
|
||||||
|
'http_ip_header': 'enable',
|
||||||
|
'http_ip_header_name': 'test_value_18',
|
||||||
|
'http_multiplex': 'enable',
|
||||||
|
'https_cookie_secure': 'disable',
|
||||||
|
'id': '21',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mapped_addr': 'test_value_23',
|
||||||
|
'mappedport': 'test_value_24',
|
||||||
|
'max_embryonic_connections': '25',
|
||||||
|
'name': 'default_name_26',
|
||||||
|
'nat_source_vip': 'disable',
|
||||||
|
'outlook_web_access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'portmapping_type': '1-to-1',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_certificate': 'test_value_35',
|
||||||
|
'ssl_client_fallback': 'disable',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_client_session_state_max': '38',
|
||||||
|
'ssl_client_session_state_timeout': '39',
|
||||||
|
'ssl_client_session_state_type': 'disable',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_hpkp': 'disable',
|
||||||
|
'ssl_hpkp_age': '43',
|
||||||
|
'ssl_hpkp_backup': 'test_value_44',
|
||||||
|
'ssl_hpkp_include_subdomains': 'disable',
|
||||||
|
'ssl_hpkp_primary': 'test_value_46',
|
||||||
|
'ssl_hpkp_report_uri': 'test_value_47',
|
||||||
|
'ssl_hsts': 'disable',
|
||||||
|
'ssl_hsts_age': '49',
|
||||||
|
'ssl_hsts_include_subdomains': 'disable',
|
||||||
|
'ssl_http_location_conversion': 'enable',
|
||||||
|
'ssl_http_match_host': 'enable',
|
||||||
|
'ssl_max_version': 'ssl-3.0',
|
||||||
|
'ssl_min_version': 'ssl-3.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_pfs': 'require',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'ssl_server_algorithm': 'high',
|
||||||
|
'ssl_server_max_version': 'ssl-3.0',
|
||||||
|
'ssl_server_min_version': 'ssl-3.0',
|
||||||
|
'ssl_server_session_state_max': '61',
|
||||||
|
'ssl_server_session_state_timeout': '62',
|
||||||
|
'ssl_server_session_state_type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_65',
|
||||||
|
'weblogic_server': 'disable',
|
||||||
|
'websphere_server': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dns-mapping-ttl': '6',
|
||||||
|
'extintf': 'test_value_7',
|
||||||
|
'extip': 'test_value_8',
|
||||||
|
'extport': 'test_value_9',
|
||||||
|
'gratuitous-arp-interval': '10',
|
||||||
|
'http-cookie-age': '11',
|
||||||
|
'http-cookie-domain': 'test_value_12',
|
||||||
|
'http-cookie-domain-from-host': 'disable',
|
||||||
|
'http-cookie-generation': '14',
|
||||||
|
'http-cookie-path': 'test_value_15',
|
||||||
|
'http-cookie-share': 'disable',
|
||||||
|
'http-ip-header': 'enable',
|
||||||
|
'http-ip-header-name': 'test_value_18',
|
||||||
|
'http-multiplex': 'enable',
|
||||||
|
'https-cookie-secure': 'disable',
|
||||||
|
'id': '21',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mapped-addr': 'test_value_23',
|
||||||
|
'mappedport': 'test_value_24',
|
||||||
|
'max-embryonic-connections': '25',
|
||||||
|
'name': 'default_name_26',
|
||||||
|
'nat-source-vip': 'disable',
|
||||||
|
'outlook-web-access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'portmapping-type': '1-to-1',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'ssl-algorithm': 'high',
|
||||||
|
'ssl-certificate': 'test_value_35',
|
||||||
|
'ssl-client-fallback': 'disable',
|
||||||
|
'ssl-client-renegotiation': 'allow',
|
||||||
|
'ssl-client-session-state-max': '38',
|
||||||
|
'ssl-client-session-state-timeout': '39',
|
||||||
|
'ssl-client-session-state-type': 'disable',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-hpkp': 'disable',
|
||||||
|
'ssl-hpkp-age': '43',
|
||||||
|
'ssl-hpkp-backup': 'test_value_44',
|
||||||
|
'ssl-hpkp-include-subdomains': 'disable',
|
||||||
|
'ssl-hpkp-primary': 'test_value_46',
|
||||||
|
'ssl-hpkp-report-uri': 'test_value_47',
|
||||||
|
'ssl-hsts': 'disable',
|
||||||
|
'ssl-hsts-age': '49',
|
||||||
|
'ssl-hsts-include-subdomains': 'disable',
|
||||||
|
'ssl-http-location-conversion': 'enable',
|
||||||
|
'ssl-http-match-host': 'enable',
|
||||||
|
'ssl-max-version': 'ssl-3.0',
|
||||||
|
'ssl-min-version': 'ssl-3.0',
|
||||||
|
'ssl-mode': 'half',
|
||||||
|
'ssl-pfs': 'require',
|
||||||
|
'ssl-send-empty-frags': 'enable',
|
||||||
|
'ssl-server-algorithm': 'high',
|
||||||
|
'ssl-server-max-version': 'ssl-3.0',
|
||||||
|
'ssl-server-min-version': 'ssl-3.0',
|
||||||
|
'ssl-server-session-state-max': '61',
|
||||||
|
'ssl-server-session-state-timeout': '62',
|
||||||
|
'ssl-server-session-state-type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_65',
|
||||||
|
'weblogic-server': 'disable',
|
||||||
|
'websphere-server': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip', 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_firewall_vip_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',
|
||||||
|
'firewall_vip': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dns_mapping_ttl': '6',
|
||||||
|
'extintf': 'test_value_7',
|
||||||
|
'extip': 'test_value_8',
|
||||||
|
'extport': 'test_value_9',
|
||||||
|
'gratuitous_arp_interval': '10',
|
||||||
|
'http_cookie_age': '11',
|
||||||
|
'http_cookie_domain': 'test_value_12',
|
||||||
|
'http_cookie_domain_from_host': 'disable',
|
||||||
|
'http_cookie_generation': '14',
|
||||||
|
'http_cookie_path': 'test_value_15',
|
||||||
|
'http_cookie_share': 'disable',
|
||||||
|
'http_ip_header': 'enable',
|
||||||
|
'http_ip_header_name': 'test_value_18',
|
||||||
|
'http_multiplex': 'enable',
|
||||||
|
'https_cookie_secure': 'disable',
|
||||||
|
'id': '21',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mapped_addr': 'test_value_23',
|
||||||
|
'mappedport': 'test_value_24',
|
||||||
|
'max_embryonic_connections': '25',
|
||||||
|
'name': 'default_name_26',
|
||||||
|
'nat_source_vip': 'disable',
|
||||||
|
'outlook_web_access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'portmapping_type': '1-to-1',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_certificate': 'test_value_35',
|
||||||
|
'ssl_client_fallback': 'disable',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_client_session_state_max': '38',
|
||||||
|
'ssl_client_session_state_timeout': '39',
|
||||||
|
'ssl_client_session_state_type': 'disable',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_hpkp': 'disable',
|
||||||
|
'ssl_hpkp_age': '43',
|
||||||
|
'ssl_hpkp_backup': 'test_value_44',
|
||||||
|
'ssl_hpkp_include_subdomains': 'disable',
|
||||||
|
'ssl_hpkp_primary': 'test_value_46',
|
||||||
|
'ssl_hpkp_report_uri': 'test_value_47',
|
||||||
|
'ssl_hsts': 'disable',
|
||||||
|
'ssl_hsts_age': '49',
|
||||||
|
'ssl_hsts_include_subdomains': 'disable',
|
||||||
|
'ssl_http_location_conversion': 'enable',
|
||||||
|
'ssl_http_match_host': 'enable',
|
||||||
|
'ssl_max_version': 'ssl-3.0',
|
||||||
|
'ssl_min_version': 'ssl-3.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_pfs': 'require',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'ssl_server_algorithm': 'high',
|
||||||
|
'ssl_server_max_version': 'ssl-3.0',
|
||||||
|
'ssl_server_min_version': 'ssl-3.0',
|
||||||
|
'ssl_server_session_state_max': '61',
|
||||||
|
'ssl_server_session_state_timeout': '62',
|
||||||
|
'ssl_server_session_state_type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_65',
|
||||||
|
'weblogic_server': 'disable',
|
||||||
|
'websphere_server': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'dns-mapping-ttl': '6',
|
||||||
|
'extintf': 'test_value_7',
|
||||||
|
'extip': 'test_value_8',
|
||||||
|
'extport': 'test_value_9',
|
||||||
|
'gratuitous-arp-interval': '10',
|
||||||
|
'http-cookie-age': '11',
|
||||||
|
'http-cookie-domain': 'test_value_12',
|
||||||
|
'http-cookie-domain-from-host': 'disable',
|
||||||
|
'http-cookie-generation': '14',
|
||||||
|
'http-cookie-path': 'test_value_15',
|
||||||
|
'http-cookie-share': 'disable',
|
||||||
|
'http-ip-header': 'enable',
|
||||||
|
'http-ip-header-name': 'test_value_18',
|
||||||
|
'http-multiplex': 'enable',
|
||||||
|
'https-cookie-secure': 'disable',
|
||||||
|
'id': '21',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mapped-addr': 'test_value_23',
|
||||||
|
'mappedport': 'test_value_24',
|
||||||
|
'max-embryonic-connections': '25',
|
||||||
|
'name': 'default_name_26',
|
||||||
|
'nat-source-vip': 'disable',
|
||||||
|
'outlook-web-access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'portmapping-type': '1-to-1',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'ssl-algorithm': 'high',
|
||||||
|
'ssl-certificate': 'test_value_35',
|
||||||
|
'ssl-client-fallback': 'disable',
|
||||||
|
'ssl-client-renegotiation': 'allow',
|
||||||
|
'ssl-client-session-state-max': '38',
|
||||||
|
'ssl-client-session-state-timeout': '39',
|
||||||
|
'ssl-client-session-state-type': 'disable',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-hpkp': 'disable',
|
||||||
|
'ssl-hpkp-age': '43',
|
||||||
|
'ssl-hpkp-backup': 'test_value_44',
|
||||||
|
'ssl-hpkp-include-subdomains': 'disable',
|
||||||
|
'ssl-hpkp-primary': 'test_value_46',
|
||||||
|
'ssl-hpkp-report-uri': 'test_value_47',
|
||||||
|
'ssl-hsts': 'disable',
|
||||||
|
'ssl-hsts-age': '49',
|
||||||
|
'ssl-hsts-include-subdomains': 'disable',
|
||||||
|
'ssl-http-location-conversion': 'enable',
|
||||||
|
'ssl-http-match-host': 'enable',
|
||||||
|
'ssl-max-version': 'ssl-3.0',
|
||||||
|
'ssl-min-version': 'ssl-3.0',
|
||||||
|
'ssl-mode': 'half',
|
||||||
|
'ssl-pfs': 'require',
|
||||||
|
'ssl-send-empty-frags': 'enable',
|
||||||
|
'ssl-server-algorithm': 'high',
|
||||||
|
'ssl-server-max-version': 'ssl-3.0',
|
||||||
|
'ssl-server-min-version': 'ssl-3.0',
|
||||||
|
'ssl-server-session-state-max': '61',
|
||||||
|
'ssl-server-session-state-timeout': '62',
|
||||||
|
'ssl-server-session-state-type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_65',
|
||||||
|
'weblogic-server': 'disable',
|
||||||
|
'websphere-server': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,339 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_firewall_vip46
|
||||||
|
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_firewall_vip46.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_vip46_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',
|
||||||
|
'firewall_vip46': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip46.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip46', 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_firewall_vip46_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',
|
||||||
|
'firewall_vip46': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip46.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip46', 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_firewall_vip46_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',
|
||||||
|
'firewall_vip46': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip46.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vip46', 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_firewall_vip46_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',
|
||||||
|
'firewall_vip46': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip46.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vip46', 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_firewall_vip46_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',
|
||||||
|
'firewall_vip46': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip46.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip46', 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_firewall_vip46_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',
|
||||||
|
'firewall_vip46': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip46.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip46', 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,789 @@
|
|||||||
|
# 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_firewall_vip6
|
||||||
|
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_firewall_vip6.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_vip6_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',
|
||||||
|
'firewall_vip6': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'http_cookie_age': '8',
|
||||||
|
'http_cookie_domain': 'test_value_9',
|
||||||
|
'http_cookie_domain_from_host': 'disable',
|
||||||
|
'http_cookie_generation': '11',
|
||||||
|
'http_cookie_path': 'test_value_12',
|
||||||
|
'http_cookie_share': 'disable',
|
||||||
|
'http_ip_header': 'enable',
|
||||||
|
'http_ip_header_name': 'test_value_15',
|
||||||
|
'http_multiplex': 'enable',
|
||||||
|
'https_cookie_secure': 'disable',
|
||||||
|
'id': '18',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_20',
|
||||||
|
'mappedport': 'test_value_21',
|
||||||
|
'max_embryonic_connections': '22',
|
||||||
|
'name': 'default_name_23',
|
||||||
|
'outlook_web_access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_certificate': 'test_value_30',
|
||||||
|
'ssl_client_fallback': 'disable',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_client_session_state_max': '33',
|
||||||
|
'ssl_client_session_state_timeout': '34',
|
||||||
|
'ssl_client_session_state_type': 'disable',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_hpkp': 'disable',
|
||||||
|
'ssl_hpkp_age': '38',
|
||||||
|
'ssl_hpkp_backup': 'test_value_39',
|
||||||
|
'ssl_hpkp_include_subdomains': 'disable',
|
||||||
|
'ssl_hpkp_primary': 'test_value_41',
|
||||||
|
'ssl_hpkp_report_uri': 'test_value_42',
|
||||||
|
'ssl_hsts': 'disable',
|
||||||
|
'ssl_hsts_age': '44',
|
||||||
|
'ssl_hsts_include_subdomains': 'disable',
|
||||||
|
'ssl_http_location_conversion': 'enable',
|
||||||
|
'ssl_http_match_host': 'enable',
|
||||||
|
'ssl_max_version': 'ssl-3.0',
|
||||||
|
'ssl_min_version': 'ssl-3.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_pfs': 'require',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'ssl_server_algorithm': 'high',
|
||||||
|
'ssl_server_max_version': 'ssl-3.0',
|
||||||
|
'ssl_server_min_version': 'ssl-3.0',
|
||||||
|
'ssl_server_session_state_max': '56',
|
||||||
|
'ssl_server_session_state_timeout': '57',
|
||||||
|
'ssl_server_session_state_type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_60',
|
||||||
|
'weblogic_server': 'disable',
|
||||||
|
'websphere_server': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip6.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'http-cookie-age': '8',
|
||||||
|
'http-cookie-domain': 'test_value_9',
|
||||||
|
'http-cookie-domain-from-host': 'disable',
|
||||||
|
'http-cookie-generation': '11',
|
||||||
|
'http-cookie-path': 'test_value_12',
|
||||||
|
'http-cookie-share': 'disable',
|
||||||
|
'http-ip-header': 'enable',
|
||||||
|
'http-ip-header-name': 'test_value_15',
|
||||||
|
'http-multiplex': 'enable',
|
||||||
|
'https-cookie-secure': 'disable',
|
||||||
|
'id': '18',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mappedip': 'test_value_20',
|
||||||
|
'mappedport': 'test_value_21',
|
||||||
|
'max-embryonic-connections': '22',
|
||||||
|
'name': 'default_name_23',
|
||||||
|
'outlook-web-access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'ssl-algorithm': 'high',
|
||||||
|
'ssl-certificate': 'test_value_30',
|
||||||
|
'ssl-client-fallback': 'disable',
|
||||||
|
'ssl-client-renegotiation': 'allow',
|
||||||
|
'ssl-client-session-state-max': '33',
|
||||||
|
'ssl-client-session-state-timeout': '34',
|
||||||
|
'ssl-client-session-state-type': 'disable',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-hpkp': 'disable',
|
||||||
|
'ssl-hpkp-age': '38',
|
||||||
|
'ssl-hpkp-backup': 'test_value_39',
|
||||||
|
'ssl-hpkp-include-subdomains': 'disable',
|
||||||
|
'ssl-hpkp-primary': 'test_value_41',
|
||||||
|
'ssl-hpkp-report-uri': 'test_value_42',
|
||||||
|
'ssl-hsts': 'disable',
|
||||||
|
'ssl-hsts-age': '44',
|
||||||
|
'ssl-hsts-include-subdomains': 'disable',
|
||||||
|
'ssl-http-location-conversion': 'enable',
|
||||||
|
'ssl-http-match-host': 'enable',
|
||||||
|
'ssl-max-version': 'ssl-3.0',
|
||||||
|
'ssl-min-version': 'ssl-3.0',
|
||||||
|
'ssl-mode': 'half',
|
||||||
|
'ssl-pfs': 'require',
|
||||||
|
'ssl-send-empty-frags': 'enable',
|
||||||
|
'ssl-server-algorithm': 'high',
|
||||||
|
'ssl-server-max-version': 'ssl-3.0',
|
||||||
|
'ssl-server-min-version': 'ssl-3.0',
|
||||||
|
'ssl-server-session-state-max': '56',
|
||||||
|
'ssl-server-session-state-timeout': '57',
|
||||||
|
'ssl-server-session-state-type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_60',
|
||||||
|
'weblogic-server': 'disable',
|
||||||
|
'websphere-server': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip6', 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_firewall_vip6_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',
|
||||||
|
'firewall_vip6': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'http_cookie_age': '8',
|
||||||
|
'http_cookie_domain': 'test_value_9',
|
||||||
|
'http_cookie_domain_from_host': 'disable',
|
||||||
|
'http_cookie_generation': '11',
|
||||||
|
'http_cookie_path': 'test_value_12',
|
||||||
|
'http_cookie_share': 'disable',
|
||||||
|
'http_ip_header': 'enable',
|
||||||
|
'http_ip_header_name': 'test_value_15',
|
||||||
|
'http_multiplex': 'enable',
|
||||||
|
'https_cookie_secure': 'disable',
|
||||||
|
'id': '18',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_20',
|
||||||
|
'mappedport': 'test_value_21',
|
||||||
|
'max_embryonic_connections': '22',
|
||||||
|
'name': 'default_name_23',
|
||||||
|
'outlook_web_access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_certificate': 'test_value_30',
|
||||||
|
'ssl_client_fallback': 'disable',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_client_session_state_max': '33',
|
||||||
|
'ssl_client_session_state_timeout': '34',
|
||||||
|
'ssl_client_session_state_type': 'disable',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_hpkp': 'disable',
|
||||||
|
'ssl_hpkp_age': '38',
|
||||||
|
'ssl_hpkp_backup': 'test_value_39',
|
||||||
|
'ssl_hpkp_include_subdomains': 'disable',
|
||||||
|
'ssl_hpkp_primary': 'test_value_41',
|
||||||
|
'ssl_hpkp_report_uri': 'test_value_42',
|
||||||
|
'ssl_hsts': 'disable',
|
||||||
|
'ssl_hsts_age': '44',
|
||||||
|
'ssl_hsts_include_subdomains': 'disable',
|
||||||
|
'ssl_http_location_conversion': 'enable',
|
||||||
|
'ssl_http_match_host': 'enable',
|
||||||
|
'ssl_max_version': 'ssl-3.0',
|
||||||
|
'ssl_min_version': 'ssl-3.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_pfs': 'require',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'ssl_server_algorithm': 'high',
|
||||||
|
'ssl_server_max_version': 'ssl-3.0',
|
||||||
|
'ssl_server_min_version': 'ssl-3.0',
|
||||||
|
'ssl_server_session_state_max': '56',
|
||||||
|
'ssl_server_session_state_timeout': '57',
|
||||||
|
'ssl_server_session_state_type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_60',
|
||||||
|
'weblogic_server': 'disable',
|
||||||
|
'websphere_server': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip6.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'http-cookie-age': '8',
|
||||||
|
'http-cookie-domain': 'test_value_9',
|
||||||
|
'http-cookie-domain-from-host': 'disable',
|
||||||
|
'http-cookie-generation': '11',
|
||||||
|
'http-cookie-path': 'test_value_12',
|
||||||
|
'http-cookie-share': 'disable',
|
||||||
|
'http-ip-header': 'enable',
|
||||||
|
'http-ip-header-name': 'test_value_15',
|
||||||
|
'http-multiplex': 'enable',
|
||||||
|
'https-cookie-secure': 'disable',
|
||||||
|
'id': '18',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mappedip': 'test_value_20',
|
||||||
|
'mappedport': 'test_value_21',
|
||||||
|
'max-embryonic-connections': '22',
|
||||||
|
'name': 'default_name_23',
|
||||||
|
'outlook-web-access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'ssl-algorithm': 'high',
|
||||||
|
'ssl-certificate': 'test_value_30',
|
||||||
|
'ssl-client-fallback': 'disable',
|
||||||
|
'ssl-client-renegotiation': 'allow',
|
||||||
|
'ssl-client-session-state-max': '33',
|
||||||
|
'ssl-client-session-state-timeout': '34',
|
||||||
|
'ssl-client-session-state-type': 'disable',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-hpkp': 'disable',
|
||||||
|
'ssl-hpkp-age': '38',
|
||||||
|
'ssl-hpkp-backup': 'test_value_39',
|
||||||
|
'ssl-hpkp-include-subdomains': 'disable',
|
||||||
|
'ssl-hpkp-primary': 'test_value_41',
|
||||||
|
'ssl-hpkp-report-uri': 'test_value_42',
|
||||||
|
'ssl-hsts': 'disable',
|
||||||
|
'ssl-hsts-age': '44',
|
||||||
|
'ssl-hsts-include-subdomains': 'disable',
|
||||||
|
'ssl-http-location-conversion': 'enable',
|
||||||
|
'ssl-http-match-host': 'enable',
|
||||||
|
'ssl-max-version': 'ssl-3.0',
|
||||||
|
'ssl-min-version': 'ssl-3.0',
|
||||||
|
'ssl-mode': 'half',
|
||||||
|
'ssl-pfs': 'require',
|
||||||
|
'ssl-send-empty-frags': 'enable',
|
||||||
|
'ssl-server-algorithm': 'high',
|
||||||
|
'ssl-server-max-version': 'ssl-3.0',
|
||||||
|
'ssl-server-min-version': 'ssl-3.0',
|
||||||
|
'ssl-server-session-state-max': '56',
|
||||||
|
'ssl-server-session-state-timeout': '57',
|
||||||
|
'ssl-server-session-state-type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_60',
|
||||||
|
'weblogic-server': 'disable',
|
||||||
|
'websphere-server': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip6', 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_firewall_vip6_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',
|
||||||
|
'firewall_vip6': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'http_cookie_age': '8',
|
||||||
|
'http_cookie_domain': 'test_value_9',
|
||||||
|
'http_cookie_domain_from_host': 'disable',
|
||||||
|
'http_cookie_generation': '11',
|
||||||
|
'http_cookie_path': 'test_value_12',
|
||||||
|
'http_cookie_share': 'disable',
|
||||||
|
'http_ip_header': 'enable',
|
||||||
|
'http_ip_header_name': 'test_value_15',
|
||||||
|
'http_multiplex': 'enable',
|
||||||
|
'https_cookie_secure': 'disable',
|
||||||
|
'id': '18',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_20',
|
||||||
|
'mappedport': 'test_value_21',
|
||||||
|
'max_embryonic_connections': '22',
|
||||||
|
'name': 'default_name_23',
|
||||||
|
'outlook_web_access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_certificate': 'test_value_30',
|
||||||
|
'ssl_client_fallback': 'disable',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_client_session_state_max': '33',
|
||||||
|
'ssl_client_session_state_timeout': '34',
|
||||||
|
'ssl_client_session_state_type': 'disable',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_hpkp': 'disable',
|
||||||
|
'ssl_hpkp_age': '38',
|
||||||
|
'ssl_hpkp_backup': 'test_value_39',
|
||||||
|
'ssl_hpkp_include_subdomains': 'disable',
|
||||||
|
'ssl_hpkp_primary': 'test_value_41',
|
||||||
|
'ssl_hpkp_report_uri': 'test_value_42',
|
||||||
|
'ssl_hsts': 'disable',
|
||||||
|
'ssl_hsts_age': '44',
|
||||||
|
'ssl_hsts_include_subdomains': 'disable',
|
||||||
|
'ssl_http_location_conversion': 'enable',
|
||||||
|
'ssl_http_match_host': 'enable',
|
||||||
|
'ssl_max_version': 'ssl-3.0',
|
||||||
|
'ssl_min_version': 'ssl-3.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_pfs': 'require',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'ssl_server_algorithm': 'high',
|
||||||
|
'ssl_server_max_version': 'ssl-3.0',
|
||||||
|
'ssl_server_min_version': 'ssl-3.0',
|
||||||
|
'ssl_server_session_state_max': '56',
|
||||||
|
'ssl_server_session_state_timeout': '57',
|
||||||
|
'ssl_server_session_state_type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_60',
|
||||||
|
'weblogic_server': 'disable',
|
||||||
|
'websphere_server': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip6.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vip6', 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_firewall_vip6_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',
|
||||||
|
'firewall_vip6': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'http_cookie_age': '8',
|
||||||
|
'http_cookie_domain': 'test_value_9',
|
||||||
|
'http_cookie_domain_from_host': 'disable',
|
||||||
|
'http_cookie_generation': '11',
|
||||||
|
'http_cookie_path': 'test_value_12',
|
||||||
|
'http_cookie_share': 'disable',
|
||||||
|
'http_ip_header': 'enable',
|
||||||
|
'http_ip_header_name': 'test_value_15',
|
||||||
|
'http_multiplex': 'enable',
|
||||||
|
'https_cookie_secure': 'disable',
|
||||||
|
'id': '18',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_20',
|
||||||
|
'mappedport': 'test_value_21',
|
||||||
|
'max_embryonic_connections': '22',
|
||||||
|
'name': 'default_name_23',
|
||||||
|
'outlook_web_access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_certificate': 'test_value_30',
|
||||||
|
'ssl_client_fallback': 'disable',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_client_session_state_max': '33',
|
||||||
|
'ssl_client_session_state_timeout': '34',
|
||||||
|
'ssl_client_session_state_type': 'disable',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_hpkp': 'disable',
|
||||||
|
'ssl_hpkp_age': '38',
|
||||||
|
'ssl_hpkp_backup': 'test_value_39',
|
||||||
|
'ssl_hpkp_include_subdomains': 'disable',
|
||||||
|
'ssl_hpkp_primary': 'test_value_41',
|
||||||
|
'ssl_hpkp_report_uri': 'test_value_42',
|
||||||
|
'ssl_hsts': 'disable',
|
||||||
|
'ssl_hsts_age': '44',
|
||||||
|
'ssl_hsts_include_subdomains': 'disable',
|
||||||
|
'ssl_http_location_conversion': 'enable',
|
||||||
|
'ssl_http_match_host': 'enable',
|
||||||
|
'ssl_max_version': 'ssl-3.0',
|
||||||
|
'ssl_min_version': 'ssl-3.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_pfs': 'require',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'ssl_server_algorithm': 'high',
|
||||||
|
'ssl_server_max_version': 'ssl-3.0',
|
||||||
|
'ssl_server_min_version': 'ssl-3.0',
|
||||||
|
'ssl_server_session_state_max': '56',
|
||||||
|
'ssl_server_session_state_timeout': '57',
|
||||||
|
'ssl_server_session_state_type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_60',
|
||||||
|
'weblogic_server': 'disable',
|
||||||
|
'websphere_server': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip6.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vip6', 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_firewall_vip6_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',
|
||||||
|
'firewall_vip6': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'http_cookie_age': '8',
|
||||||
|
'http_cookie_domain': 'test_value_9',
|
||||||
|
'http_cookie_domain_from_host': 'disable',
|
||||||
|
'http_cookie_generation': '11',
|
||||||
|
'http_cookie_path': 'test_value_12',
|
||||||
|
'http_cookie_share': 'disable',
|
||||||
|
'http_ip_header': 'enable',
|
||||||
|
'http_ip_header_name': 'test_value_15',
|
||||||
|
'http_multiplex': 'enable',
|
||||||
|
'https_cookie_secure': 'disable',
|
||||||
|
'id': '18',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_20',
|
||||||
|
'mappedport': 'test_value_21',
|
||||||
|
'max_embryonic_connections': '22',
|
||||||
|
'name': 'default_name_23',
|
||||||
|
'outlook_web_access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_certificate': 'test_value_30',
|
||||||
|
'ssl_client_fallback': 'disable',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_client_session_state_max': '33',
|
||||||
|
'ssl_client_session_state_timeout': '34',
|
||||||
|
'ssl_client_session_state_type': 'disable',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_hpkp': 'disable',
|
||||||
|
'ssl_hpkp_age': '38',
|
||||||
|
'ssl_hpkp_backup': 'test_value_39',
|
||||||
|
'ssl_hpkp_include_subdomains': 'disable',
|
||||||
|
'ssl_hpkp_primary': 'test_value_41',
|
||||||
|
'ssl_hpkp_report_uri': 'test_value_42',
|
||||||
|
'ssl_hsts': 'disable',
|
||||||
|
'ssl_hsts_age': '44',
|
||||||
|
'ssl_hsts_include_subdomains': 'disable',
|
||||||
|
'ssl_http_location_conversion': 'enable',
|
||||||
|
'ssl_http_match_host': 'enable',
|
||||||
|
'ssl_max_version': 'ssl-3.0',
|
||||||
|
'ssl_min_version': 'ssl-3.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_pfs': 'require',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'ssl_server_algorithm': 'high',
|
||||||
|
'ssl_server_max_version': 'ssl-3.0',
|
||||||
|
'ssl_server_min_version': 'ssl-3.0',
|
||||||
|
'ssl_server_session_state_max': '56',
|
||||||
|
'ssl_server_session_state_timeout': '57',
|
||||||
|
'ssl_server_session_state_type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_60',
|
||||||
|
'weblogic_server': 'disable',
|
||||||
|
'websphere_server': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip6.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'http-cookie-age': '8',
|
||||||
|
'http-cookie-domain': 'test_value_9',
|
||||||
|
'http-cookie-domain-from-host': 'disable',
|
||||||
|
'http-cookie-generation': '11',
|
||||||
|
'http-cookie-path': 'test_value_12',
|
||||||
|
'http-cookie-share': 'disable',
|
||||||
|
'http-ip-header': 'enable',
|
||||||
|
'http-ip-header-name': 'test_value_15',
|
||||||
|
'http-multiplex': 'enable',
|
||||||
|
'https-cookie-secure': 'disable',
|
||||||
|
'id': '18',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mappedip': 'test_value_20',
|
||||||
|
'mappedport': 'test_value_21',
|
||||||
|
'max-embryonic-connections': '22',
|
||||||
|
'name': 'default_name_23',
|
||||||
|
'outlook-web-access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'ssl-algorithm': 'high',
|
||||||
|
'ssl-certificate': 'test_value_30',
|
||||||
|
'ssl-client-fallback': 'disable',
|
||||||
|
'ssl-client-renegotiation': 'allow',
|
||||||
|
'ssl-client-session-state-max': '33',
|
||||||
|
'ssl-client-session-state-timeout': '34',
|
||||||
|
'ssl-client-session-state-type': 'disable',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-hpkp': 'disable',
|
||||||
|
'ssl-hpkp-age': '38',
|
||||||
|
'ssl-hpkp-backup': 'test_value_39',
|
||||||
|
'ssl-hpkp-include-subdomains': 'disable',
|
||||||
|
'ssl-hpkp-primary': 'test_value_41',
|
||||||
|
'ssl-hpkp-report-uri': 'test_value_42',
|
||||||
|
'ssl-hsts': 'disable',
|
||||||
|
'ssl-hsts-age': '44',
|
||||||
|
'ssl-hsts-include-subdomains': 'disable',
|
||||||
|
'ssl-http-location-conversion': 'enable',
|
||||||
|
'ssl-http-match-host': 'enable',
|
||||||
|
'ssl-max-version': 'ssl-3.0',
|
||||||
|
'ssl-min-version': 'ssl-3.0',
|
||||||
|
'ssl-mode': 'half',
|
||||||
|
'ssl-pfs': 'require',
|
||||||
|
'ssl-send-empty-frags': 'enable',
|
||||||
|
'ssl-server-algorithm': 'high',
|
||||||
|
'ssl-server-max-version': 'ssl-3.0',
|
||||||
|
'ssl-server-min-version': 'ssl-3.0',
|
||||||
|
'ssl-server-session-state-max': '56',
|
||||||
|
'ssl-server-session-state-timeout': '57',
|
||||||
|
'ssl-server-session-state-type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_60',
|
||||||
|
'weblogic-server': 'disable',
|
||||||
|
'websphere-server': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip6', 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_firewall_vip6_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',
|
||||||
|
'firewall_vip6': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'http_cookie_age': '8',
|
||||||
|
'http_cookie_domain': 'test_value_9',
|
||||||
|
'http_cookie_domain_from_host': 'disable',
|
||||||
|
'http_cookie_generation': '11',
|
||||||
|
'http_cookie_path': 'test_value_12',
|
||||||
|
'http_cookie_share': 'disable',
|
||||||
|
'http_ip_header': 'enable',
|
||||||
|
'http_ip_header_name': 'test_value_15',
|
||||||
|
'http_multiplex': 'enable',
|
||||||
|
'https_cookie_secure': 'disable',
|
||||||
|
'id': '18',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_20',
|
||||||
|
'mappedport': 'test_value_21',
|
||||||
|
'max_embryonic_connections': '22',
|
||||||
|
'name': 'default_name_23',
|
||||||
|
'outlook_web_access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_certificate': 'test_value_30',
|
||||||
|
'ssl_client_fallback': 'disable',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_client_session_state_max': '33',
|
||||||
|
'ssl_client_session_state_timeout': '34',
|
||||||
|
'ssl_client_session_state_type': 'disable',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_hpkp': 'disable',
|
||||||
|
'ssl_hpkp_age': '38',
|
||||||
|
'ssl_hpkp_backup': 'test_value_39',
|
||||||
|
'ssl_hpkp_include_subdomains': 'disable',
|
||||||
|
'ssl_hpkp_primary': 'test_value_41',
|
||||||
|
'ssl_hpkp_report_uri': 'test_value_42',
|
||||||
|
'ssl_hsts': 'disable',
|
||||||
|
'ssl_hsts_age': '44',
|
||||||
|
'ssl_hsts_include_subdomains': 'disable',
|
||||||
|
'ssl_http_location_conversion': 'enable',
|
||||||
|
'ssl_http_match_host': 'enable',
|
||||||
|
'ssl_max_version': 'ssl-3.0',
|
||||||
|
'ssl_min_version': 'ssl-3.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_pfs': 'require',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'ssl_server_algorithm': 'high',
|
||||||
|
'ssl_server_max_version': 'ssl-3.0',
|
||||||
|
'ssl_server_min_version': 'ssl-3.0',
|
||||||
|
'ssl_server_session_state_max': '56',
|
||||||
|
'ssl_server_session_state_timeout': '57',
|
||||||
|
'ssl_server_session_state_type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_60',
|
||||||
|
'weblogic_server': 'disable',
|
||||||
|
'websphere_server': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip6.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'http-cookie-age': '8',
|
||||||
|
'http-cookie-domain': 'test_value_9',
|
||||||
|
'http-cookie-domain-from-host': 'disable',
|
||||||
|
'http-cookie-generation': '11',
|
||||||
|
'http-cookie-path': 'test_value_12',
|
||||||
|
'http-cookie-share': 'disable',
|
||||||
|
'http-ip-header': 'enable',
|
||||||
|
'http-ip-header-name': 'test_value_15',
|
||||||
|
'http-multiplex': 'enable',
|
||||||
|
'https-cookie-secure': 'disable',
|
||||||
|
'id': '18',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mappedip': 'test_value_20',
|
||||||
|
'mappedport': 'test_value_21',
|
||||||
|
'max-embryonic-connections': '22',
|
||||||
|
'name': 'default_name_23',
|
||||||
|
'outlook-web-access': 'disable',
|
||||||
|
'persistence': 'none',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'ssl-algorithm': 'high',
|
||||||
|
'ssl-certificate': 'test_value_30',
|
||||||
|
'ssl-client-fallback': 'disable',
|
||||||
|
'ssl-client-renegotiation': 'allow',
|
||||||
|
'ssl-client-session-state-max': '33',
|
||||||
|
'ssl-client-session-state-timeout': '34',
|
||||||
|
'ssl-client-session-state-type': 'disable',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-hpkp': 'disable',
|
||||||
|
'ssl-hpkp-age': '38',
|
||||||
|
'ssl-hpkp-backup': 'test_value_39',
|
||||||
|
'ssl-hpkp-include-subdomains': 'disable',
|
||||||
|
'ssl-hpkp-primary': 'test_value_41',
|
||||||
|
'ssl-hpkp-report-uri': 'test_value_42',
|
||||||
|
'ssl-hsts': 'disable',
|
||||||
|
'ssl-hsts-age': '44',
|
||||||
|
'ssl-hsts-include-subdomains': 'disable',
|
||||||
|
'ssl-http-location-conversion': 'enable',
|
||||||
|
'ssl-http-match-host': 'enable',
|
||||||
|
'ssl-max-version': 'ssl-3.0',
|
||||||
|
'ssl-min-version': 'ssl-3.0',
|
||||||
|
'ssl-mode': 'half',
|
||||||
|
'ssl-pfs': 'require',
|
||||||
|
'ssl-send-empty-frags': 'enable',
|
||||||
|
'ssl-server-algorithm': 'high',
|
||||||
|
'ssl-server-max-version': 'ssl-3.0',
|
||||||
|
'ssl-server-min-version': 'ssl-3.0',
|
||||||
|
'ssl-server-session-state-max': '56',
|
||||||
|
'ssl-server-session-state-timeout': '57',
|
||||||
|
'ssl-server-session-state-type': 'disable',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_60',
|
||||||
|
'weblogic-server': 'disable',
|
||||||
|
'websphere-server': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,339 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_firewall_vip64
|
||||||
|
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_firewall_vip64.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_vip64_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',
|
||||||
|
'firewall_vip64': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip64.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip64', 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_firewall_vip64_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',
|
||||||
|
'firewall_vip64': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip64.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip64', 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_firewall_vip64_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',
|
||||||
|
'firewall_vip64': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip64.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vip64', 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_firewall_vip64_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',
|
||||||
|
'firewall_vip64': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip64.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vip64', 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_firewall_vip64_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',
|
||||||
|
'firewall_vip64': {
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip64.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip64', 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_firewall_vip64_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',
|
||||||
|
'firewall_vip64': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'arp_reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb_method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server_type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vip64.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'arp-reply': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'extip': 'test_value_6',
|
||||||
|
'extport': 'test_value_7',
|
||||||
|
'id': '8',
|
||||||
|
'ldb-method': 'static',
|
||||||
|
'mappedip': 'test_value_10',
|
||||||
|
'mappedport': 'test_value_11',
|
||||||
|
'name': 'default_name_12',
|
||||||
|
'portforward': 'disable',
|
||||||
|
'protocol': 'tcp',
|
||||||
|
'server-type': 'http',
|
||||||
|
'type': 'static-nat',
|
||||||
|
'uuid': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vip64', 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_firewall_vipgrp
|
||||||
|
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_firewall_vipgrp.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_vipgrp_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',
|
||||||
|
'firewall_vipgrp': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'interface': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'uuid': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'interface': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'uuid': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp', 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_firewall_vipgrp_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',
|
||||||
|
'firewall_vipgrp': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'interface': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'uuid': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'interface': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'uuid': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp', 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_firewall_vipgrp_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',
|
||||||
|
'firewall_vipgrp': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'interface': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'uuid': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vipgrp', 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_firewall_vipgrp_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',
|
||||||
|
'firewall_vipgrp': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'interface': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'uuid': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vipgrp', 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_firewall_vipgrp_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',
|
||||||
|
'firewall_vipgrp': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'interface': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'uuid': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'interface': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'uuid': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp', 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_firewall_vipgrp_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',
|
||||||
|
'firewall_vipgrp': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'interface': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'uuid': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'interface': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'uuid': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp', 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,229 @@
|
|||||||
|
# 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_firewall_vipgrp46
|
||||||
|
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_firewall_vipgrp46.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_vipgrp46_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',
|
||||||
|
'firewall_vipgrp46': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp46.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp46', 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_firewall_vipgrp46_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',
|
||||||
|
'firewall_vipgrp46': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp46.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp46', 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_firewall_vipgrp46_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',
|
||||||
|
'firewall_vipgrp46': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp46.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vipgrp46', 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_firewall_vipgrp46_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',
|
||||||
|
'firewall_vipgrp46': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp46.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vipgrp46', 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_firewall_vipgrp46_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',
|
||||||
|
'firewall_vipgrp46': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp46.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp46', 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_firewall_vipgrp46_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',
|
||||||
|
'firewall_vipgrp46': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp46.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp46', 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,229 @@
|
|||||||
|
# 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_firewall_vipgrp6
|
||||||
|
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_firewall_vipgrp6.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_vipgrp6_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',
|
||||||
|
'firewall_vipgrp6': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp6.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp6', 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_firewall_vipgrp6_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',
|
||||||
|
'firewall_vipgrp6': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp6.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp6', 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_firewall_vipgrp6_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',
|
||||||
|
'firewall_vipgrp6': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp6.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vipgrp6', 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_firewall_vipgrp6_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',
|
||||||
|
'firewall_vipgrp6': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp6.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vipgrp6', 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_firewall_vipgrp6_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',
|
||||||
|
'firewall_vipgrp6': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp6.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp6', 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_firewall_vipgrp6_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',
|
||||||
|
'firewall_vipgrp6': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp6.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp6', 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,229 @@
|
|||||||
|
# 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_firewall_vipgrp64
|
||||||
|
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_firewall_vipgrp64.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_vipgrp64_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',
|
||||||
|
'firewall_vipgrp64': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp64.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp64', 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_firewall_vipgrp64_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',
|
||||||
|
'firewall_vipgrp64': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp64.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp64', 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_firewall_vipgrp64_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',
|
||||||
|
'firewall_vipgrp64': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp64.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vipgrp64', 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_firewall_vipgrp64_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',
|
||||||
|
'firewall_vipgrp64': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp64.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'vipgrp64', 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_firewall_vipgrp64_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',
|
||||||
|
'firewall_vipgrp64': {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp64.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp64', 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_firewall_vipgrp64_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',
|
||||||
|
'firewall_vipgrp64': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_vipgrp64.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'vipgrp64', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,249 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_firewall_wildcard_fqdn_custom
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_firewall_wildcard_fqdn_custom.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_wildcard_fqdn_custom_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_wildcard_fqdn_custom': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable',
|
||||||
|
'wildcard_fqdn': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_wildcard_fqdn_custom.fortios_firewall_wildcard_fqdn(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable',
|
||||||
|
'wildcard-fqdn': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.wildcard-fqdn', 'custom', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_wildcard_fqdn_custom_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_wildcard_fqdn_custom': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable',
|
||||||
|
'wildcard_fqdn': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_wildcard_fqdn_custom.fortios_firewall_wildcard_fqdn(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable',
|
||||||
|
'wildcard-fqdn': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.wildcard-fqdn', 'custom', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_wildcard_fqdn_custom_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'firewall_wildcard_fqdn_custom': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable',
|
||||||
|
'wildcard_fqdn': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_wildcard_fqdn_custom.fortios_firewall_wildcard_fqdn(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.wildcard-fqdn', 'custom', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_wildcard_fqdn_custom_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'firewall_wildcard_fqdn_custom': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable',
|
||||||
|
'wildcard_fqdn': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_wildcard_fqdn_custom.fortios_firewall_wildcard_fqdn(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.wildcard-fqdn', 'custom', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_wildcard_fqdn_custom_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_wildcard_fqdn_custom': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable',
|
||||||
|
'wildcard_fqdn': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_wildcard_fqdn_custom.fortios_firewall_wildcard_fqdn(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable',
|
||||||
|
'wildcard-fqdn': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.wildcard-fqdn', 'custom', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_wildcard_fqdn_custom_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_wildcard_fqdn_custom': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable',
|
||||||
|
'wildcard_fqdn': 'test_value_8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_wildcard_fqdn_custom.fortios_firewall_wildcard_fqdn(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable',
|
||||||
|
'wildcard-fqdn': 'test_value_8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.wildcard-fqdn', 'custom', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,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_firewall_wildcard_fqdn_group
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_firewall_wildcard_fqdn_group.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_wildcard_fqdn_group_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_wildcard_fqdn_group': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_wildcard_fqdn_group.fortios_firewall_wildcard_fqdn(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.wildcard-fqdn', 'group', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_wildcard_fqdn_group_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_wildcard_fqdn_group': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_wildcard_fqdn_group.fortios_firewall_wildcard_fqdn(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.wildcard-fqdn', 'group', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_wildcard_fqdn_group_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'firewall_wildcard_fqdn_group': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_wildcard_fqdn_group.fortios_firewall_wildcard_fqdn(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.wildcard-fqdn', 'group', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_wildcard_fqdn_group_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'firewall_wildcard_fqdn_group': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_wildcard_fqdn_group.fortios_firewall_wildcard_fqdn(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.wildcard-fqdn', 'group', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_wildcard_fqdn_group_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_wildcard_fqdn_group': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_wildcard_fqdn_group.fortios_firewall_wildcard_fqdn(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.wildcard-fqdn', 'group', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_wildcard_fqdn_group_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_wildcard_fqdn_group': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_wildcard_fqdn_group.fortios_firewall_wildcard_fqdn(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'uuid': 'test_value_6',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.wildcard-fqdn', 'group', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,183 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_ftp_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_ftp_proxy_explicit.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ftp_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',
|
||||||
|
'ftp_proxy_explicit': {
|
||||||
|
'incoming_ip': 'test_value_3',
|
||||||
|
'incoming_port': 'test_value_4',
|
||||||
|
'outgoing_ip': 'test_value_5',
|
||||||
|
'sec_default_action': 'accept',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ftp_proxy_explicit.fortios_ftp_proxy(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'incoming-ip': 'test_value_3',
|
||||||
|
'incoming-port': 'test_value_4',
|
||||||
|
'outgoing-ip': 'test_value_5',
|
||||||
|
'sec-default-action': 'accept',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ftp-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_ftp_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',
|
||||||
|
'ftp_proxy_explicit': {
|
||||||
|
'incoming_ip': 'test_value_3',
|
||||||
|
'incoming_port': 'test_value_4',
|
||||||
|
'outgoing_ip': 'test_value_5',
|
||||||
|
'sec_default_action': 'accept',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ftp_proxy_explicit.fortios_ftp_proxy(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'incoming-ip': 'test_value_3',
|
||||||
|
'incoming-port': 'test_value_4',
|
||||||
|
'outgoing-ip': 'test_value_5',
|
||||||
|
'sec-default-action': 'accept',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ftp-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_ftp_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',
|
||||||
|
'ftp_proxy_explicit': {
|
||||||
|
'incoming_ip': 'test_value_3',
|
||||||
|
'incoming_port': 'test_value_4',
|
||||||
|
'outgoing_ip': 'test_value_5',
|
||||||
|
'sec_default_action': 'accept',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ftp_proxy_explicit.fortios_ftp_proxy(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'incoming-ip': 'test_value_3',
|
||||||
|
'incoming-port': 'test_value_4',
|
||||||
|
'outgoing-ip': 'test_value_5',
|
||||||
|
'sec-default-action': 'accept',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ftp-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_ftp_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',
|
||||||
|
'ftp_proxy_explicit': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'incoming_ip': 'test_value_3',
|
||||||
|
'incoming_port': 'test_value_4',
|
||||||
|
'outgoing_ip': 'test_value_5',
|
||||||
|
'sec_default_action': 'accept',
|
||||||
|
'status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ftp_proxy_explicit.fortios_ftp_proxy(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'incoming-ip': 'test_value_3',
|
||||||
|
'incoming-port': 'test_value_4',
|
||||||
|
'outgoing-ip': 'test_value_5',
|
||||||
|
'sec-default-action': 'accept',
|
||||||
|
'status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ftp-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,309 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_icap_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_icap_profile.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_icap_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',
|
||||||
|
'icap_profile': {
|
||||||
|
'methods': 'delete',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'replacemsg_group': 'test_value_5',
|
||||||
|
'request': 'disable',
|
||||||
|
'request_failure': 'error',
|
||||||
|
'request_path': 'test_value_8',
|
||||||
|
'request_server': 'test_value_9',
|
||||||
|
'response': 'disable',
|
||||||
|
'response_failure': 'error',
|
||||||
|
'response_path': 'test_value_12',
|
||||||
|
'response_server': 'test_value_13',
|
||||||
|
'streaming_content_bypass': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_icap_profile.fortios_icap(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'methods': 'delete',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'replacemsg-group': 'test_value_5',
|
||||||
|
'request': 'disable',
|
||||||
|
'request-failure': 'error',
|
||||||
|
'request-path': 'test_value_8',
|
||||||
|
'request-server': 'test_value_9',
|
||||||
|
'response': 'disable',
|
||||||
|
'response-failure': 'error',
|
||||||
|
'response-path': 'test_value_12',
|
||||||
|
'response-server': 'test_value_13',
|
||||||
|
'streaming-content-bypass': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('icap', '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_icap_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',
|
||||||
|
'icap_profile': {
|
||||||
|
'methods': 'delete',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'replacemsg_group': 'test_value_5',
|
||||||
|
'request': 'disable',
|
||||||
|
'request_failure': 'error',
|
||||||
|
'request_path': 'test_value_8',
|
||||||
|
'request_server': 'test_value_9',
|
||||||
|
'response': 'disable',
|
||||||
|
'response_failure': 'error',
|
||||||
|
'response_path': 'test_value_12',
|
||||||
|
'response_server': 'test_value_13',
|
||||||
|
'streaming_content_bypass': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_icap_profile.fortios_icap(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'methods': 'delete',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'replacemsg-group': 'test_value_5',
|
||||||
|
'request': 'disable',
|
||||||
|
'request-failure': 'error',
|
||||||
|
'request-path': 'test_value_8',
|
||||||
|
'request-server': 'test_value_9',
|
||||||
|
'response': 'disable',
|
||||||
|
'response-failure': 'error',
|
||||||
|
'response-path': 'test_value_12',
|
||||||
|
'response-server': 'test_value_13',
|
||||||
|
'streaming-content-bypass': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('icap', '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_icap_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',
|
||||||
|
'icap_profile': {
|
||||||
|
'methods': 'delete',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'replacemsg_group': 'test_value_5',
|
||||||
|
'request': 'disable',
|
||||||
|
'request_failure': 'error',
|
||||||
|
'request_path': 'test_value_8',
|
||||||
|
'request_server': 'test_value_9',
|
||||||
|
'response': 'disable',
|
||||||
|
'response_failure': 'error',
|
||||||
|
'response_path': 'test_value_12',
|
||||||
|
'response_server': 'test_value_13',
|
||||||
|
'streaming_content_bypass': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_icap_profile.fortios_icap(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('icap', '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_icap_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',
|
||||||
|
'icap_profile': {
|
||||||
|
'methods': 'delete',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'replacemsg_group': 'test_value_5',
|
||||||
|
'request': 'disable',
|
||||||
|
'request_failure': 'error',
|
||||||
|
'request_path': 'test_value_8',
|
||||||
|
'request_server': 'test_value_9',
|
||||||
|
'response': 'disable',
|
||||||
|
'response_failure': 'error',
|
||||||
|
'response_path': 'test_value_12',
|
||||||
|
'response_server': 'test_value_13',
|
||||||
|
'streaming_content_bypass': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_icap_profile.fortios_icap(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('icap', '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_icap_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',
|
||||||
|
'icap_profile': {
|
||||||
|
'methods': 'delete',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'replacemsg_group': 'test_value_5',
|
||||||
|
'request': 'disable',
|
||||||
|
'request_failure': 'error',
|
||||||
|
'request_path': 'test_value_8',
|
||||||
|
'request_server': 'test_value_9',
|
||||||
|
'response': 'disable',
|
||||||
|
'response_failure': 'error',
|
||||||
|
'response_path': 'test_value_12',
|
||||||
|
'response_server': 'test_value_13',
|
||||||
|
'streaming_content_bypass': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_icap_profile.fortios_icap(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'methods': 'delete',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'replacemsg-group': 'test_value_5',
|
||||||
|
'request': 'disable',
|
||||||
|
'request-failure': 'error',
|
||||||
|
'request-path': 'test_value_8',
|
||||||
|
'request-server': 'test_value_9',
|
||||||
|
'response': 'disable',
|
||||||
|
'response-failure': 'error',
|
||||||
|
'response-path': 'test_value_12',
|
||||||
|
'response-server': 'test_value_13',
|
||||||
|
'streaming-content-bypass': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('icap', '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_icap_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',
|
||||||
|
'icap_profile': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'methods': 'delete',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'replacemsg_group': 'test_value_5',
|
||||||
|
'request': 'disable',
|
||||||
|
'request_failure': 'error',
|
||||||
|
'request_path': 'test_value_8',
|
||||||
|
'request_server': 'test_value_9',
|
||||||
|
'response': 'disable',
|
||||||
|
'response_failure': 'error',
|
||||||
|
'response_path': 'test_value_12',
|
||||||
|
'response_server': 'test_value_13',
|
||||||
|
'streaming_content_bypass': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_icap_profile.fortios_icap(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'methods': 'delete',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
'replacemsg-group': 'test_value_5',
|
||||||
|
'request': 'disable',
|
||||||
|
'request-failure': 'error',
|
||||||
|
'request-path': 'test_value_8',
|
||||||
|
'request-server': 'test_value_9',
|
||||||
|
'response': 'disable',
|
||||||
|
'response-failure': 'error',
|
||||||
|
'response-path': 'test_value_12',
|
||||||
|
'response-server': 'test_value_13',
|
||||||
|
'streaming-content-bypass': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('icap', 'profile', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,249 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_icap_server
|
||||||
|
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_icap_server.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_icap_server_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',
|
||||||
|
'icap_server': {
|
||||||
|
'ip_address': 'test_value_3',
|
||||||
|
'ip_version': '4',
|
||||||
|
'ip6_address': 'test_value_5',
|
||||||
|
'max_connections': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'port': '8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_icap_server.fortios_icap(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'ip-address': 'test_value_3',
|
||||||
|
'ip-version': '4',
|
||||||
|
'ip6-address': 'test_value_5',
|
||||||
|
'max-connections': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'port': '8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('icap', 'server', 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_icap_server_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',
|
||||||
|
'icap_server': {
|
||||||
|
'ip_address': 'test_value_3',
|
||||||
|
'ip_version': '4',
|
||||||
|
'ip6_address': 'test_value_5',
|
||||||
|
'max_connections': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'port': '8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_icap_server.fortios_icap(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'ip-address': 'test_value_3',
|
||||||
|
'ip-version': '4',
|
||||||
|
'ip6-address': 'test_value_5',
|
||||||
|
'max-connections': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'port': '8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('icap', 'server', 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_icap_server_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',
|
||||||
|
'icap_server': {
|
||||||
|
'ip_address': 'test_value_3',
|
||||||
|
'ip_version': '4',
|
||||||
|
'ip6_address': 'test_value_5',
|
||||||
|
'max_connections': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'port': '8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_icap_server.fortios_icap(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('icap', 'server', 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_icap_server_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',
|
||||||
|
'icap_server': {
|
||||||
|
'ip_address': 'test_value_3',
|
||||||
|
'ip_version': '4',
|
||||||
|
'ip6_address': 'test_value_5',
|
||||||
|
'max_connections': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'port': '8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_icap_server.fortios_icap(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('icap', 'server', 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_icap_server_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',
|
||||||
|
'icap_server': {
|
||||||
|
'ip_address': 'test_value_3',
|
||||||
|
'ip_version': '4',
|
||||||
|
'ip6_address': 'test_value_5',
|
||||||
|
'max_connections': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'port': '8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_icap_server.fortios_icap(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'ip-address': 'test_value_3',
|
||||||
|
'ip-version': '4',
|
||||||
|
'ip6-address': 'test_value_5',
|
||||||
|
'max-connections': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'port': '8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('icap', 'server', 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_icap_server_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',
|
||||||
|
'icap_server': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'ip_address': 'test_value_3',
|
||||||
|
'ip_version': '4',
|
||||||
|
'ip6_address': 'test_value_5',
|
||||||
|
'max_connections': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'port': '8'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_icap_server.fortios_icap(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'ip-address': 'test_value_3',
|
||||||
|
'ip-version': '4',
|
||||||
|
'ip6-address': 'test_value_5',
|
||||||
|
'max-connections': '6',
|
||||||
|
'name': 'default_name_7',
|
||||||
|
'port': '8'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('icap', 'server', 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,329 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_ips_custom
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_ips_custom.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_custom_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_custom': {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'location': 'test_value_6',
|
||||||
|
'log': 'disable',
|
||||||
|
'log_packet': 'disable',
|
||||||
|
'os': 'test_value_9',
|
||||||
|
'protocol': 'test_value_10',
|
||||||
|
'rule_id': '11',
|
||||||
|
'severity': 'test_value_12',
|
||||||
|
'sig_name': 'test_value_13',
|
||||||
|
'signature': 'test_value_14',
|
||||||
|
'status': 'disable',
|
||||||
|
'tag': 'test_value_16'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_custom.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'location': 'test_value_6',
|
||||||
|
'log': 'disable',
|
||||||
|
'log-packet': 'disable',
|
||||||
|
'os': 'test_value_9',
|
||||||
|
'protocol': 'test_value_10',
|
||||||
|
'rule-id': '11',
|
||||||
|
'severity': 'test_value_12',
|
||||||
|
'sig-name': 'test_value_13',
|
||||||
|
'signature': 'test_value_14',
|
||||||
|
'status': 'disable',
|
||||||
|
'tag': 'test_value_16'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'custom', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_custom_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_custom': {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'location': 'test_value_6',
|
||||||
|
'log': 'disable',
|
||||||
|
'log_packet': 'disable',
|
||||||
|
'os': 'test_value_9',
|
||||||
|
'protocol': 'test_value_10',
|
||||||
|
'rule_id': '11',
|
||||||
|
'severity': 'test_value_12',
|
||||||
|
'sig_name': 'test_value_13',
|
||||||
|
'signature': 'test_value_14',
|
||||||
|
'status': 'disable',
|
||||||
|
'tag': 'test_value_16'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_custom.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'location': 'test_value_6',
|
||||||
|
'log': 'disable',
|
||||||
|
'log-packet': 'disable',
|
||||||
|
'os': 'test_value_9',
|
||||||
|
'protocol': 'test_value_10',
|
||||||
|
'rule-id': '11',
|
||||||
|
'severity': 'test_value_12',
|
||||||
|
'sig-name': 'test_value_13',
|
||||||
|
'signature': 'test_value_14',
|
||||||
|
'status': 'disable',
|
||||||
|
'tag': 'test_value_16'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'custom', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_custom_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'ips_custom': {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'location': 'test_value_6',
|
||||||
|
'log': 'disable',
|
||||||
|
'log_packet': 'disable',
|
||||||
|
'os': 'test_value_9',
|
||||||
|
'protocol': 'test_value_10',
|
||||||
|
'rule_id': '11',
|
||||||
|
'severity': 'test_value_12',
|
||||||
|
'sig_name': 'test_value_13',
|
||||||
|
'signature': 'test_value_14',
|
||||||
|
'status': 'disable',
|
||||||
|
'tag': 'test_value_16'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_custom.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('ips', 'custom', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_custom_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'ips_custom': {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'location': 'test_value_6',
|
||||||
|
'log': 'disable',
|
||||||
|
'log_packet': 'disable',
|
||||||
|
'os': 'test_value_9',
|
||||||
|
'protocol': 'test_value_10',
|
||||||
|
'rule_id': '11',
|
||||||
|
'severity': 'test_value_12',
|
||||||
|
'sig_name': 'test_value_13',
|
||||||
|
'signature': 'test_value_14',
|
||||||
|
'status': 'disable',
|
||||||
|
'tag': 'test_value_16'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_custom.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('ips', 'custom', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_custom_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_custom': {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'location': 'test_value_6',
|
||||||
|
'log': 'disable',
|
||||||
|
'log_packet': 'disable',
|
||||||
|
'os': 'test_value_9',
|
||||||
|
'protocol': 'test_value_10',
|
||||||
|
'rule_id': '11',
|
||||||
|
'severity': 'test_value_12',
|
||||||
|
'sig_name': 'test_value_13',
|
||||||
|
'signature': 'test_value_14',
|
||||||
|
'status': 'disable',
|
||||||
|
'tag': 'test_value_16'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_custom.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'location': 'test_value_6',
|
||||||
|
'log': 'disable',
|
||||||
|
'log-packet': 'disable',
|
||||||
|
'os': 'test_value_9',
|
||||||
|
'protocol': 'test_value_10',
|
||||||
|
'rule-id': '11',
|
||||||
|
'severity': 'test_value_12',
|
||||||
|
'sig-name': 'test_value_13',
|
||||||
|
'signature': 'test_value_14',
|
||||||
|
'status': 'disable',
|
||||||
|
'tag': 'test_value_16'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'custom', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_custom_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_custom': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'location': 'test_value_6',
|
||||||
|
'log': 'disable',
|
||||||
|
'log_packet': 'disable',
|
||||||
|
'os': 'test_value_9',
|
||||||
|
'protocol': 'test_value_10',
|
||||||
|
'rule_id': '11',
|
||||||
|
'severity': 'test_value_12',
|
||||||
|
'sig_name': 'test_value_13',
|
||||||
|
'signature': 'test_value_14',
|
||||||
|
'status': 'disable',
|
||||||
|
'tag': 'test_value_16'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_custom.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'location': 'test_value_6',
|
||||||
|
'log': 'disable',
|
||||||
|
'log-packet': 'disable',
|
||||||
|
'os': 'test_value_9',
|
||||||
|
'protocol': 'test_value_10',
|
||||||
|
'rule-id': '11',
|
||||||
|
'severity': 'test_value_12',
|
||||||
|
'sig-name': 'test_value_13',
|
||||||
|
'signature': 'test_value_14',
|
||||||
|
'status': 'disable',
|
||||||
|
'tag': 'test_value_16'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'custom', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,209 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_ips_decoder
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_ips_decoder.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_decoder_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_decoder': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_decoder.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'decoder', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_decoder_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_decoder': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_decoder.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'decoder', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_decoder_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'ips_decoder': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_decoder.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('ips', 'decoder', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_decoder_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'ips_decoder': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_decoder.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('ips', 'decoder', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_decoder_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_decoder': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_decoder.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'decoder', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_decoder_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_decoder': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'name': 'default_name_3',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_decoder.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'decoder', 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_ips_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_ips_global.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_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',
|
||||||
|
'ips_global': {
|
||||||
|
'anomaly_mode': 'periodical',
|
||||||
|
'database': 'regular',
|
||||||
|
'deep_app_insp_db_limit': '5',
|
||||||
|
'deep_app_insp_timeout': '6',
|
||||||
|
'engine_count': '7',
|
||||||
|
'exclude_signatures': 'none',
|
||||||
|
'fail_open': 'enable',
|
||||||
|
'intelligent_mode': 'enable',
|
||||||
|
'session_limit_mode': 'accurate',
|
||||||
|
'skype_client_public_ipaddr': 'test_value_12',
|
||||||
|
'socket_size': '13',
|
||||||
|
'sync_session_ttl': 'enable',
|
||||||
|
'traffic_submit': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_global.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly-mode': 'periodical',
|
||||||
|
'database': 'regular',
|
||||||
|
'deep-app-insp-db-limit': '5',
|
||||||
|
'deep-app-insp-timeout': '6',
|
||||||
|
'engine-count': '7',
|
||||||
|
'exclude-signatures': 'none',
|
||||||
|
'fail-open': 'enable',
|
||||||
|
'intelligent-mode': 'enable',
|
||||||
|
'session-limit-mode': 'accurate',
|
||||||
|
'skype-client-public-ipaddr': 'test_value_12',
|
||||||
|
'socket-size': '13',
|
||||||
|
'sync-session-ttl': 'enable',
|
||||||
|
'traffic-submit': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', '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_ips_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',
|
||||||
|
'ips_global': {
|
||||||
|
'anomaly_mode': 'periodical',
|
||||||
|
'database': 'regular',
|
||||||
|
'deep_app_insp_db_limit': '5',
|
||||||
|
'deep_app_insp_timeout': '6',
|
||||||
|
'engine_count': '7',
|
||||||
|
'exclude_signatures': 'none',
|
||||||
|
'fail_open': 'enable',
|
||||||
|
'intelligent_mode': 'enable',
|
||||||
|
'session_limit_mode': 'accurate',
|
||||||
|
'skype_client_public_ipaddr': 'test_value_12',
|
||||||
|
'socket_size': '13',
|
||||||
|
'sync_session_ttl': 'enable',
|
||||||
|
'traffic_submit': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_global.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly-mode': 'periodical',
|
||||||
|
'database': 'regular',
|
||||||
|
'deep-app-insp-db-limit': '5',
|
||||||
|
'deep-app-insp-timeout': '6',
|
||||||
|
'engine-count': '7',
|
||||||
|
'exclude-signatures': 'none',
|
||||||
|
'fail-open': 'enable',
|
||||||
|
'intelligent-mode': 'enable',
|
||||||
|
'session-limit-mode': 'accurate',
|
||||||
|
'skype-client-public-ipaddr': 'test_value_12',
|
||||||
|
'socket-size': '13',
|
||||||
|
'sync-session-ttl': 'enable',
|
||||||
|
'traffic-submit': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', '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_ips_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',
|
||||||
|
'ips_global': {
|
||||||
|
'anomaly_mode': 'periodical',
|
||||||
|
'database': 'regular',
|
||||||
|
'deep_app_insp_db_limit': '5',
|
||||||
|
'deep_app_insp_timeout': '6',
|
||||||
|
'engine_count': '7',
|
||||||
|
'exclude_signatures': 'none',
|
||||||
|
'fail_open': 'enable',
|
||||||
|
'intelligent_mode': 'enable',
|
||||||
|
'session_limit_mode': 'accurate',
|
||||||
|
'skype_client_public_ipaddr': 'test_value_12',
|
||||||
|
'socket_size': '13',
|
||||||
|
'sync_session_ttl': 'enable',
|
||||||
|
'traffic_submit': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_global.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly-mode': 'periodical',
|
||||||
|
'database': 'regular',
|
||||||
|
'deep-app-insp-db-limit': '5',
|
||||||
|
'deep-app-insp-timeout': '6',
|
||||||
|
'engine-count': '7',
|
||||||
|
'exclude-signatures': 'none',
|
||||||
|
'fail-open': 'enable',
|
||||||
|
'intelligent-mode': 'enable',
|
||||||
|
'session-limit-mode': 'accurate',
|
||||||
|
'skype-client-public-ipaddr': 'test_value_12',
|
||||||
|
'socket-size': '13',
|
||||||
|
'sync-session-ttl': 'enable',
|
||||||
|
'traffic-submit': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', '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_ips_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',
|
||||||
|
'ips_global': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'anomaly_mode': 'periodical',
|
||||||
|
'database': 'regular',
|
||||||
|
'deep_app_insp_db_limit': '5',
|
||||||
|
'deep_app_insp_timeout': '6',
|
||||||
|
'engine_count': '7',
|
||||||
|
'exclude_signatures': 'none',
|
||||||
|
'fail_open': 'enable',
|
||||||
|
'intelligent_mode': 'enable',
|
||||||
|
'session_limit_mode': 'accurate',
|
||||||
|
'skype_client_public_ipaddr': 'test_value_12',
|
||||||
|
'socket_size': '13',
|
||||||
|
'sync_session_ttl': 'enable',
|
||||||
|
'traffic_submit': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_global.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'anomaly-mode': 'periodical',
|
||||||
|
'database': 'regular',
|
||||||
|
'deep-app-insp-db-limit': '5',
|
||||||
|
'deep-app-insp-timeout': '6',
|
||||||
|
'engine-count': '7',
|
||||||
|
'exclude-signatures': 'none',
|
||||||
|
'fail-open': 'enable',
|
||||||
|
'intelligent-mode': 'enable',
|
||||||
|
'session-limit-mode': 'accurate',
|
||||||
|
'skype-client-public-ipaddr': 'test_value_12',
|
||||||
|
'socket-size': '13',
|
||||||
|
'sync-session-ttl': 'enable',
|
||||||
|
'traffic-submit': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', '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,329 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_ips_rule
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_ips_rule.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_rule_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_rule': {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'date': '5',
|
||||||
|
'group': 'test_value_6',
|
||||||
|
'location': 'test_value_7,',
|
||||||
|
'log': 'disable',
|
||||||
|
'log_packet': 'disable',
|
||||||
|
'name': 'default_name_10',
|
||||||
|
'os': 'test_value_11',
|
||||||
|
'rev': '12',
|
||||||
|
'rule_id': '13',
|
||||||
|
'service': 'test_value_14',
|
||||||
|
'severity': 'test_value_15,',
|
||||||
|
'status': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_rule.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'date': '5',
|
||||||
|
'group': 'test_value_6',
|
||||||
|
'location': 'test_value_7,',
|
||||||
|
'log': 'disable',
|
||||||
|
'log-packet': 'disable',
|
||||||
|
'name': 'default_name_10',
|
||||||
|
'os': 'test_value_11',
|
||||||
|
'rev': '12',
|
||||||
|
'rule-id': '13',
|
||||||
|
'service': 'test_value_14',
|
||||||
|
'severity': 'test_value_15,',
|
||||||
|
'status': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'rule', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_rule_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_rule': {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'date': '5',
|
||||||
|
'group': 'test_value_6',
|
||||||
|
'location': 'test_value_7,',
|
||||||
|
'log': 'disable',
|
||||||
|
'log_packet': 'disable',
|
||||||
|
'name': 'default_name_10',
|
||||||
|
'os': 'test_value_11',
|
||||||
|
'rev': '12',
|
||||||
|
'rule_id': '13',
|
||||||
|
'service': 'test_value_14',
|
||||||
|
'severity': 'test_value_15,',
|
||||||
|
'status': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_rule.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'date': '5',
|
||||||
|
'group': 'test_value_6',
|
||||||
|
'location': 'test_value_7,',
|
||||||
|
'log': 'disable',
|
||||||
|
'log-packet': 'disable',
|
||||||
|
'name': 'default_name_10',
|
||||||
|
'os': 'test_value_11',
|
||||||
|
'rev': '12',
|
||||||
|
'rule-id': '13',
|
||||||
|
'service': 'test_value_14',
|
||||||
|
'severity': 'test_value_15,',
|
||||||
|
'status': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'rule', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_rule_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'ips_rule': {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'date': '5',
|
||||||
|
'group': 'test_value_6',
|
||||||
|
'location': 'test_value_7,',
|
||||||
|
'log': 'disable',
|
||||||
|
'log_packet': 'disable',
|
||||||
|
'name': 'default_name_10',
|
||||||
|
'os': 'test_value_11',
|
||||||
|
'rev': '12',
|
||||||
|
'rule_id': '13',
|
||||||
|
'service': 'test_value_14',
|
||||||
|
'severity': 'test_value_15,',
|
||||||
|
'status': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_rule.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('ips', 'rule', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_rule_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'ips_rule': {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'date': '5',
|
||||||
|
'group': 'test_value_6',
|
||||||
|
'location': 'test_value_7,',
|
||||||
|
'log': 'disable',
|
||||||
|
'log_packet': 'disable',
|
||||||
|
'name': 'default_name_10',
|
||||||
|
'os': 'test_value_11',
|
||||||
|
'rev': '12',
|
||||||
|
'rule_id': '13',
|
||||||
|
'service': 'test_value_14',
|
||||||
|
'severity': 'test_value_15,',
|
||||||
|
'status': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_rule.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('ips', 'rule', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_rule_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_rule': {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'date': '5',
|
||||||
|
'group': 'test_value_6',
|
||||||
|
'location': 'test_value_7,',
|
||||||
|
'log': 'disable',
|
||||||
|
'log_packet': 'disable',
|
||||||
|
'name': 'default_name_10',
|
||||||
|
'os': 'test_value_11',
|
||||||
|
'rev': '12',
|
||||||
|
'rule_id': '13',
|
||||||
|
'service': 'test_value_14',
|
||||||
|
'severity': 'test_value_15,',
|
||||||
|
'status': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_rule.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'date': '5',
|
||||||
|
'group': 'test_value_6',
|
||||||
|
'location': 'test_value_7,',
|
||||||
|
'log': 'disable',
|
||||||
|
'log-packet': 'disable',
|
||||||
|
'name': 'default_name_10',
|
||||||
|
'os': 'test_value_11',
|
||||||
|
'rev': '12',
|
||||||
|
'rule-id': '13',
|
||||||
|
'service': 'test_value_14',
|
||||||
|
'severity': 'test_value_15,',
|
||||||
|
'status': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'rule', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_rule_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_rule': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'date': '5',
|
||||||
|
'group': 'test_value_6',
|
||||||
|
'location': 'test_value_7,',
|
||||||
|
'log': 'disable',
|
||||||
|
'log_packet': 'disable',
|
||||||
|
'name': 'default_name_10',
|
||||||
|
'os': 'test_value_11',
|
||||||
|
'rev': '12',
|
||||||
|
'rule_id': '13',
|
||||||
|
'service': 'test_value_14',
|
||||||
|
'severity': 'test_value_15,',
|
||||||
|
'status': 'disable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_rule.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'pass',
|
||||||
|
'application': 'test_value_4',
|
||||||
|
'date': '5',
|
||||||
|
'group': 'test_value_6',
|
||||||
|
'location': 'test_value_7,',
|
||||||
|
'log': 'disable',
|
||||||
|
'log-packet': 'disable',
|
||||||
|
'name': 'default_name_10',
|
||||||
|
'os': 'test_value_11',
|
||||||
|
'rev': '12',
|
||||||
|
'rule-id': '13',
|
||||||
|
'service': 'test_value_14',
|
||||||
|
'severity': 'test_value_15,',
|
||||||
|
'status': 'disable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'rule', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,199 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_ips_rule_settings
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_ips_rule_settings.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_rule_settings_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_rule_settings': {
|
||||||
|
'id': '3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_rule_settings.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'id': '3'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'rule-settings', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_rule_settings_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_rule_settings': {
|
||||||
|
'id': '3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_rule_settings.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'id': '3'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'rule-settings', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_rule_settings_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'ips_rule_settings': {
|
||||||
|
'id': '3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_rule_settings.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('ips', 'rule-settings', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_rule_settings_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'ips_rule_settings': {
|
||||||
|
'id': '3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_rule_settings.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('ips', 'rule-settings', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_rule_settings_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_rule_settings': {
|
||||||
|
'id': '3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_rule_settings.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'id': '3'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'rule-settings', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_ips_rule_settings_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'ips_rule_settings': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'id': '3'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_ips_rule_settings.fortios_ips(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'id': '3'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('ips', 'rule-settings', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
Loading…
Reference in New Issue