mirror of https://github.com/ansible/ansible.git
FortiOS modules for 2.9 - 4 (#60806)
* FortiOS modules for 2.9 - 4 * Update ignore.txt * Updates from maintainers to legacy modules * Update fortios_firewall_ssl_setting.py * Update fortios_firewall_ssl_server.pypull/60963/head
parent
2b103a2e54
commit
3cd70f53cc
@ -0,0 +1,349 @@
|
|||||||
|
# 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_proxy_address
|
||||||
|
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_proxy_address.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_proxy_address_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_proxy_address': {
|
||||||
|
'case_sensitivity': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'header': 'test_value_6',
|
||||||
|
'header_name': 'test_value_7',
|
||||||
|
'host': 'myhostname8',
|
||||||
|
'host_regex': 'myhostname9',
|
||||||
|
'method': 'get',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'path': 'test_value_12',
|
||||||
|
'query': 'test_value_13',
|
||||||
|
'referrer': 'enable',
|
||||||
|
'type': 'host-regex',
|
||||||
|
'ua': 'chrome',
|
||||||
|
'uuid': 'test_value_17',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_address.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'case-sensitivity': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'header': 'test_value_6',
|
||||||
|
'header-name': 'test_value_7',
|
||||||
|
'host': 'myhostname8',
|
||||||
|
'host-regex': 'myhostname9',
|
||||||
|
'method': 'get',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'path': 'test_value_12',
|
||||||
|
'query': 'test_value_13',
|
||||||
|
'referrer': 'enable',
|
||||||
|
'type': 'host-regex',
|
||||||
|
'ua': 'chrome',
|
||||||
|
'uuid': 'test_value_17',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'proxy-address', 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_proxy_address_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_proxy_address': {
|
||||||
|
'case_sensitivity': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'header': 'test_value_6',
|
||||||
|
'header_name': 'test_value_7',
|
||||||
|
'host': 'myhostname8',
|
||||||
|
'host_regex': 'myhostname9',
|
||||||
|
'method': 'get',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'path': 'test_value_12',
|
||||||
|
'query': 'test_value_13',
|
||||||
|
'referrer': 'enable',
|
||||||
|
'type': 'host-regex',
|
||||||
|
'ua': 'chrome',
|
||||||
|
'uuid': 'test_value_17',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_address.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'case-sensitivity': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'header': 'test_value_6',
|
||||||
|
'header-name': 'test_value_7',
|
||||||
|
'host': 'myhostname8',
|
||||||
|
'host-regex': 'myhostname9',
|
||||||
|
'method': 'get',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'path': 'test_value_12',
|
||||||
|
'query': 'test_value_13',
|
||||||
|
'referrer': 'enable',
|
||||||
|
'type': 'host-regex',
|
||||||
|
'ua': 'chrome',
|
||||||
|
'uuid': 'test_value_17',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'proxy-address', 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_proxy_address_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_proxy_address': {
|
||||||
|
'case_sensitivity': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'header': 'test_value_6',
|
||||||
|
'header_name': 'test_value_7',
|
||||||
|
'host': 'myhostname8',
|
||||||
|
'host_regex': 'myhostname9',
|
||||||
|
'method': 'get',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'path': 'test_value_12',
|
||||||
|
'query': 'test_value_13',
|
||||||
|
'referrer': 'enable',
|
||||||
|
'type': 'host-regex',
|
||||||
|
'ua': 'chrome',
|
||||||
|
'uuid': 'test_value_17',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_address.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'proxy-address', 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_proxy_address_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_proxy_address': {
|
||||||
|
'case_sensitivity': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'header': 'test_value_6',
|
||||||
|
'header_name': 'test_value_7',
|
||||||
|
'host': 'myhostname8',
|
||||||
|
'host_regex': 'myhostname9',
|
||||||
|
'method': 'get',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'path': 'test_value_12',
|
||||||
|
'query': 'test_value_13',
|
||||||
|
'referrer': 'enable',
|
||||||
|
'type': 'host-regex',
|
||||||
|
'ua': 'chrome',
|
||||||
|
'uuid': 'test_value_17',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_address.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'proxy-address', 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_proxy_address_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_proxy_address': {
|
||||||
|
'case_sensitivity': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'header': 'test_value_6',
|
||||||
|
'header_name': 'test_value_7',
|
||||||
|
'host': 'myhostname8',
|
||||||
|
'host_regex': 'myhostname9',
|
||||||
|
'method': 'get',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'path': 'test_value_12',
|
||||||
|
'query': 'test_value_13',
|
||||||
|
'referrer': 'enable',
|
||||||
|
'type': 'host-regex',
|
||||||
|
'ua': 'chrome',
|
||||||
|
'uuid': 'test_value_17',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_address.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'case-sensitivity': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'header': 'test_value_6',
|
||||||
|
'header-name': 'test_value_7',
|
||||||
|
'host': 'myhostname8',
|
||||||
|
'host-regex': 'myhostname9',
|
||||||
|
'method': 'get',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'path': 'test_value_12',
|
||||||
|
'query': 'test_value_13',
|
||||||
|
'referrer': 'enable',
|
||||||
|
'type': 'host-regex',
|
||||||
|
'ua': 'chrome',
|
||||||
|
'uuid': 'test_value_17',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'proxy-address', 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_proxy_address_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_proxy_address': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'case_sensitivity': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'header': 'test_value_6',
|
||||||
|
'header_name': 'test_value_7',
|
||||||
|
'host': 'myhostname8',
|
||||||
|
'host_regex': 'myhostname9',
|
||||||
|
'method': 'get',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'path': 'test_value_12',
|
||||||
|
'query': 'test_value_13',
|
||||||
|
'referrer': 'enable',
|
||||||
|
'type': 'host-regex',
|
||||||
|
'ua': 'chrome',
|
||||||
|
'uuid': 'test_value_17',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_address.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'case-sensitivity': 'disable',
|
||||||
|
'color': '4',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'header': 'test_value_6',
|
||||||
|
'header-name': 'test_value_7',
|
||||||
|
'host': 'myhostname8',
|
||||||
|
'host-regex': 'myhostname9',
|
||||||
|
'method': 'get',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'path': 'test_value_12',
|
||||||
|
'query': 'test_value_13',
|
||||||
|
'referrer': 'enable',
|
||||||
|
'type': 'host-regex',
|
||||||
|
'ua': 'chrome',
|
||||||
|
'uuid': 'test_value_17',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'proxy-address', 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_proxy_addrgrp
|
||||||
|
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_proxy_addrgrp.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_proxy_addrgrp_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_proxy_addrgrp': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'type': 'src',
|
||||||
|
'uuid': 'test_value_7',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_addrgrp.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'type': 'src',
|
||||||
|
'uuid': 'test_value_7',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'proxy-addrgrp', 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_proxy_addrgrp_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_proxy_addrgrp': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'type': 'src',
|
||||||
|
'uuid': 'test_value_7',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_addrgrp.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'type': 'src',
|
||||||
|
'uuid': 'test_value_7',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'proxy-addrgrp', 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_proxy_addrgrp_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_proxy_addrgrp': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'type': 'src',
|
||||||
|
'uuid': 'test_value_7',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_addrgrp.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'proxy-addrgrp', 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_proxy_addrgrp_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_proxy_addrgrp': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'type': 'src',
|
||||||
|
'uuid': 'test_value_7',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_addrgrp.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'proxy-addrgrp', 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_proxy_addrgrp_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_proxy_addrgrp': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'type': 'src',
|
||||||
|
'uuid': 'test_value_7',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_addrgrp.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'type': 'src',
|
||||||
|
'uuid': 'test_value_7',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'proxy-addrgrp', 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_proxy_addrgrp_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_proxy_addrgrp': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'type': 'src',
|
||||||
|
'uuid': 'test_value_7',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_addrgrp.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'type': 'src',
|
||||||
|
'uuid': 'test_value_7',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'proxy-addrgrp', 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,599 @@
|
|||||||
|
# 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_proxy_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_proxy_policy.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_proxy_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_proxy_policy': {
|
||||||
|
'action': 'accept',
|
||||||
|
'application_list': 'test_value_4',
|
||||||
|
'av_profile': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'disclaimer': 'disable',
|
||||||
|
'dlp_sensor': 'test_value_8',
|
||||||
|
'dstaddr_negate': 'enable',
|
||||||
|
'global_label': 'test_value_10',
|
||||||
|
'http_tunnel_auth': 'enable',
|
||||||
|
'icap_profile': 'test_value_12',
|
||||||
|
'internet_service': 'enable',
|
||||||
|
'internet_service_negate': 'enable',
|
||||||
|
'ips_sensor': 'test_value_15',
|
||||||
|
'label': 'test_value_16',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'logtraffic_start': 'enable',
|
||||||
|
'policyid': '19',
|
||||||
|
'profile_group': 'test_value_20',
|
||||||
|
'profile_protocol_options': 'test_value_21',
|
||||||
|
'profile_type': 'single',
|
||||||
|
'proxy': 'explicit-web',
|
||||||
|
'redirect_url': 'test_value_24',
|
||||||
|
'replacemsg_override_group': 'test_value_25',
|
||||||
|
'scan_botnet_connections': 'disable',
|
||||||
|
'schedule': 'test_value_27',
|
||||||
|
'service_negate': 'enable',
|
||||||
|
'session_ttl': '29',
|
||||||
|
'spamfilter_profile': 'test_value_30',
|
||||||
|
'srcaddr_negate': 'enable',
|
||||||
|
'ssh_filter_profile': 'test_value_32',
|
||||||
|
'ssl_ssh_profile': 'test_value_33',
|
||||||
|
'status': 'enable',
|
||||||
|
'transparent': 'enable',
|
||||||
|
'utm_status': 'enable',
|
||||||
|
'uuid': 'test_value_37',
|
||||||
|
'waf_profile': 'test_value_38',
|
||||||
|
'webcache': 'enable',
|
||||||
|
'webcache_https': 'disable',
|
||||||
|
'webfilter_profile': 'test_value_41',
|
||||||
|
'webproxy_forward_server': 'test_value_42',
|
||||||
|
'webproxy_profile': 'test_value_43'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'accept',
|
||||||
|
'application-list': 'test_value_4',
|
||||||
|
'av-profile': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'disclaimer': 'disable',
|
||||||
|
'dlp-sensor': 'test_value_8',
|
||||||
|
'dstaddr-negate': 'enable',
|
||||||
|
'global-label': 'test_value_10',
|
||||||
|
'http-tunnel-auth': 'enable',
|
||||||
|
'icap-profile': 'test_value_12',
|
||||||
|
'internet-service': 'enable',
|
||||||
|
'internet-service-negate': 'enable',
|
||||||
|
'ips-sensor': 'test_value_15',
|
||||||
|
'label': 'test_value_16',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'logtraffic-start': 'enable',
|
||||||
|
'policyid': '19',
|
||||||
|
'profile-group': 'test_value_20',
|
||||||
|
'profile-protocol-options': 'test_value_21',
|
||||||
|
'profile-type': 'single',
|
||||||
|
'proxy': 'explicit-web',
|
||||||
|
'redirect-url': 'test_value_24',
|
||||||
|
'replacemsg-override-group': 'test_value_25',
|
||||||
|
'scan-botnet-connections': 'disable',
|
||||||
|
'schedule': 'test_value_27',
|
||||||
|
'service-negate': 'enable',
|
||||||
|
'session-ttl': '29',
|
||||||
|
'spamfilter-profile': 'test_value_30',
|
||||||
|
'srcaddr-negate': 'enable',
|
||||||
|
'ssh-filter-profile': 'test_value_32',
|
||||||
|
'ssl-ssh-profile': 'test_value_33',
|
||||||
|
'status': 'enable',
|
||||||
|
'transparent': 'enable',
|
||||||
|
'utm-status': 'enable',
|
||||||
|
'uuid': 'test_value_37',
|
||||||
|
'waf-profile': 'test_value_38',
|
||||||
|
'webcache': 'enable',
|
||||||
|
'webcache-https': 'disable',
|
||||||
|
'webfilter-profile': 'test_value_41',
|
||||||
|
'webproxy-forward-server': 'test_value_42',
|
||||||
|
'webproxy-profile': 'test_value_43'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'proxy-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_proxy_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_proxy_policy': {
|
||||||
|
'action': 'accept',
|
||||||
|
'application_list': 'test_value_4',
|
||||||
|
'av_profile': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'disclaimer': 'disable',
|
||||||
|
'dlp_sensor': 'test_value_8',
|
||||||
|
'dstaddr_negate': 'enable',
|
||||||
|
'global_label': 'test_value_10',
|
||||||
|
'http_tunnel_auth': 'enable',
|
||||||
|
'icap_profile': 'test_value_12',
|
||||||
|
'internet_service': 'enable',
|
||||||
|
'internet_service_negate': 'enable',
|
||||||
|
'ips_sensor': 'test_value_15',
|
||||||
|
'label': 'test_value_16',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'logtraffic_start': 'enable',
|
||||||
|
'policyid': '19',
|
||||||
|
'profile_group': 'test_value_20',
|
||||||
|
'profile_protocol_options': 'test_value_21',
|
||||||
|
'profile_type': 'single',
|
||||||
|
'proxy': 'explicit-web',
|
||||||
|
'redirect_url': 'test_value_24',
|
||||||
|
'replacemsg_override_group': 'test_value_25',
|
||||||
|
'scan_botnet_connections': 'disable',
|
||||||
|
'schedule': 'test_value_27',
|
||||||
|
'service_negate': 'enable',
|
||||||
|
'session_ttl': '29',
|
||||||
|
'spamfilter_profile': 'test_value_30',
|
||||||
|
'srcaddr_negate': 'enable',
|
||||||
|
'ssh_filter_profile': 'test_value_32',
|
||||||
|
'ssl_ssh_profile': 'test_value_33',
|
||||||
|
'status': 'enable',
|
||||||
|
'transparent': 'enable',
|
||||||
|
'utm_status': 'enable',
|
||||||
|
'uuid': 'test_value_37',
|
||||||
|
'waf_profile': 'test_value_38',
|
||||||
|
'webcache': 'enable',
|
||||||
|
'webcache_https': 'disable',
|
||||||
|
'webfilter_profile': 'test_value_41',
|
||||||
|
'webproxy_forward_server': 'test_value_42',
|
||||||
|
'webproxy_profile': 'test_value_43'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'accept',
|
||||||
|
'application-list': 'test_value_4',
|
||||||
|
'av-profile': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'disclaimer': 'disable',
|
||||||
|
'dlp-sensor': 'test_value_8',
|
||||||
|
'dstaddr-negate': 'enable',
|
||||||
|
'global-label': 'test_value_10',
|
||||||
|
'http-tunnel-auth': 'enable',
|
||||||
|
'icap-profile': 'test_value_12',
|
||||||
|
'internet-service': 'enable',
|
||||||
|
'internet-service-negate': 'enable',
|
||||||
|
'ips-sensor': 'test_value_15',
|
||||||
|
'label': 'test_value_16',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'logtraffic-start': 'enable',
|
||||||
|
'policyid': '19',
|
||||||
|
'profile-group': 'test_value_20',
|
||||||
|
'profile-protocol-options': 'test_value_21',
|
||||||
|
'profile-type': 'single',
|
||||||
|
'proxy': 'explicit-web',
|
||||||
|
'redirect-url': 'test_value_24',
|
||||||
|
'replacemsg-override-group': 'test_value_25',
|
||||||
|
'scan-botnet-connections': 'disable',
|
||||||
|
'schedule': 'test_value_27',
|
||||||
|
'service-negate': 'enable',
|
||||||
|
'session-ttl': '29',
|
||||||
|
'spamfilter-profile': 'test_value_30',
|
||||||
|
'srcaddr-negate': 'enable',
|
||||||
|
'ssh-filter-profile': 'test_value_32',
|
||||||
|
'ssl-ssh-profile': 'test_value_33',
|
||||||
|
'status': 'enable',
|
||||||
|
'transparent': 'enable',
|
||||||
|
'utm-status': 'enable',
|
||||||
|
'uuid': 'test_value_37',
|
||||||
|
'waf-profile': 'test_value_38',
|
||||||
|
'webcache': 'enable',
|
||||||
|
'webcache-https': 'disable',
|
||||||
|
'webfilter-profile': 'test_value_41',
|
||||||
|
'webproxy-forward-server': 'test_value_42',
|
||||||
|
'webproxy-profile': 'test_value_43'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'proxy-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_proxy_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_proxy_policy': {
|
||||||
|
'action': 'accept',
|
||||||
|
'application_list': 'test_value_4',
|
||||||
|
'av_profile': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'disclaimer': 'disable',
|
||||||
|
'dlp_sensor': 'test_value_8',
|
||||||
|
'dstaddr_negate': 'enable',
|
||||||
|
'global_label': 'test_value_10',
|
||||||
|
'http_tunnel_auth': 'enable',
|
||||||
|
'icap_profile': 'test_value_12',
|
||||||
|
'internet_service': 'enable',
|
||||||
|
'internet_service_negate': 'enable',
|
||||||
|
'ips_sensor': 'test_value_15',
|
||||||
|
'label': 'test_value_16',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'logtraffic_start': 'enable',
|
||||||
|
'policyid': '19',
|
||||||
|
'profile_group': 'test_value_20',
|
||||||
|
'profile_protocol_options': 'test_value_21',
|
||||||
|
'profile_type': 'single',
|
||||||
|
'proxy': 'explicit-web',
|
||||||
|
'redirect_url': 'test_value_24',
|
||||||
|
'replacemsg_override_group': 'test_value_25',
|
||||||
|
'scan_botnet_connections': 'disable',
|
||||||
|
'schedule': 'test_value_27',
|
||||||
|
'service_negate': 'enable',
|
||||||
|
'session_ttl': '29',
|
||||||
|
'spamfilter_profile': 'test_value_30',
|
||||||
|
'srcaddr_negate': 'enable',
|
||||||
|
'ssh_filter_profile': 'test_value_32',
|
||||||
|
'ssl_ssh_profile': 'test_value_33',
|
||||||
|
'status': 'enable',
|
||||||
|
'transparent': 'enable',
|
||||||
|
'utm_status': 'enable',
|
||||||
|
'uuid': 'test_value_37',
|
||||||
|
'waf_profile': 'test_value_38',
|
||||||
|
'webcache': 'enable',
|
||||||
|
'webcache_https': 'disable',
|
||||||
|
'webfilter_profile': 'test_value_41',
|
||||||
|
'webproxy_forward_server': 'test_value_42',
|
||||||
|
'webproxy_profile': 'test_value_43'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'proxy-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_proxy_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_proxy_policy': {
|
||||||
|
'action': 'accept',
|
||||||
|
'application_list': 'test_value_4',
|
||||||
|
'av_profile': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'disclaimer': 'disable',
|
||||||
|
'dlp_sensor': 'test_value_8',
|
||||||
|
'dstaddr_negate': 'enable',
|
||||||
|
'global_label': 'test_value_10',
|
||||||
|
'http_tunnel_auth': 'enable',
|
||||||
|
'icap_profile': 'test_value_12',
|
||||||
|
'internet_service': 'enable',
|
||||||
|
'internet_service_negate': 'enable',
|
||||||
|
'ips_sensor': 'test_value_15',
|
||||||
|
'label': 'test_value_16',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'logtraffic_start': 'enable',
|
||||||
|
'policyid': '19',
|
||||||
|
'profile_group': 'test_value_20',
|
||||||
|
'profile_protocol_options': 'test_value_21',
|
||||||
|
'profile_type': 'single',
|
||||||
|
'proxy': 'explicit-web',
|
||||||
|
'redirect_url': 'test_value_24',
|
||||||
|
'replacemsg_override_group': 'test_value_25',
|
||||||
|
'scan_botnet_connections': 'disable',
|
||||||
|
'schedule': 'test_value_27',
|
||||||
|
'service_negate': 'enable',
|
||||||
|
'session_ttl': '29',
|
||||||
|
'spamfilter_profile': 'test_value_30',
|
||||||
|
'srcaddr_negate': 'enable',
|
||||||
|
'ssh_filter_profile': 'test_value_32',
|
||||||
|
'ssl_ssh_profile': 'test_value_33',
|
||||||
|
'status': 'enable',
|
||||||
|
'transparent': 'enable',
|
||||||
|
'utm_status': 'enable',
|
||||||
|
'uuid': 'test_value_37',
|
||||||
|
'waf_profile': 'test_value_38',
|
||||||
|
'webcache': 'enable',
|
||||||
|
'webcache_https': 'disable',
|
||||||
|
'webfilter_profile': 'test_value_41',
|
||||||
|
'webproxy_forward_server': 'test_value_42',
|
||||||
|
'webproxy_profile': 'test_value_43'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'proxy-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_proxy_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_proxy_policy': {
|
||||||
|
'action': 'accept',
|
||||||
|
'application_list': 'test_value_4',
|
||||||
|
'av_profile': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'disclaimer': 'disable',
|
||||||
|
'dlp_sensor': 'test_value_8',
|
||||||
|
'dstaddr_negate': 'enable',
|
||||||
|
'global_label': 'test_value_10',
|
||||||
|
'http_tunnel_auth': 'enable',
|
||||||
|
'icap_profile': 'test_value_12',
|
||||||
|
'internet_service': 'enable',
|
||||||
|
'internet_service_negate': 'enable',
|
||||||
|
'ips_sensor': 'test_value_15',
|
||||||
|
'label': 'test_value_16',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'logtraffic_start': 'enable',
|
||||||
|
'policyid': '19',
|
||||||
|
'profile_group': 'test_value_20',
|
||||||
|
'profile_protocol_options': 'test_value_21',
|
||||||
|
'profile_type': 'single',
|
||||||
|
'proxy': 'explicit-web',
|
||||||
|
'redirect_url': 'test_value_24',
|
||||||
|
'replacemsg_override_group': 'test_value_25',
|
||||||
|
'scan_botnet_connections': 'disable',
|
||||||
|
'schedule': 'test_value_27',
|
||||||
|
'service_negate': 'enable',
|
||||||
|
'session_ttl': '29',
|
||||||
|
'spamfilter_profile': 'test_value_30',
|
||||||
|
'srcaddr_negate': 'enable',
|
||||||
|
'ssh_filter_profile': 'test_value_32',
|
||||||
|
'ssl_ssh_profile': 'test_value_33',
|
||||||
|
'status': 'enable',
|
||||||
|
'transparent': 'enable',
|
||||||
|
'utm_status': 'enable',
|
||||||
|
'uuid': 'test_value_37',
|
||||||
|
'waf_profile': 'test_value_38',
|
||||||
|
'webcache': 'enable',
|
||||||
|
'webcache_https': 'disable',
|
||||||
|
'webfilter_profile': 'test_value_41',
|
||||||
|
'webproxy_forward_server': 'test_value_42',
|
||||||
|
'webproxy_profile': 'test_value_43'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'accept',
|
||||||
|
'application-list': 'test_value_4',
|
||||||
|
'av-profile': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'disclaimer': 'disable',
|
||||||
|
'dlp-sensor': 'test_value_8',
|
||||||
|
'dstaddr-negate': 'enable',
|
||||||
|
'global-label': 'test_value_10',
|
||||||
|
'http-tunnel-auth': 'enable',
|
||||||
|
'icap-profile': 'test_value_12',
|
||||||
|
'internet-service': 'enable',
|
||||||
|
'internet-service-negate': 'enable',
|
||||||
|
'ips-sensor': 'test_value_15',
|
||||||
|
'label': 'test_value_16',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'logtraffic-start': 'enable',
|
||||||
|
'policyid': '19',
|
||||||
|
'profile-group': 'test_value_20',
|
||||||
|
'profile-protocol-options': 'test_value_21',
|
||||||
|
'profile-type': 'single',
|
||||||
|
'proxy': 'explicit-web',
|
||||||
|
'redirect-url': 'test_value_24',
|
||||||
|
'replacemsg-override-group': 'test_value_25',
|
||||||
|
'scan-botnet-connections': 'disable',
|
||||||
|
'schedule': 'test_value_27',
|
||||||
|
'service-negate': 'enable',
|
||||||
|
'session-ttl': '29',
|
||||||
|
'spamfilter-profile': 'test_value_30',
|
||||||
|
'srcaddr-negate': 'enable',
|
||||||
|
'ssh-filter-profile': 'test_value_32',
|
||||||
|
'ssl-ssh-profile': 'test_value_33',
|
||||||
|
'status': 'enable',
|
||||||
|
'transparent': 'enable',
|
||||||
|
'utm-status': 'enable',
|
||||||
|
'uuid': 'test_value_37',
|
||||||
|
'waf-profile': 'test_value_38',
|
||||||
|
'webcache': 'enable',
|
||||||
|
'webcache-https': 'disable',
|
||||||
|
'webfilter-profile': 'test_value_41',
|
||||||
|
'webproxy-forward-server': 'test_value_42',
|
||||||
|
'webproxy-profile': 'test_value_43'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'proxy-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_proxy_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_proxy_policy': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'action': 'accept',
|
||||||
|
'application_list': 'test_value_4',
|
||||||
|
'av_profile': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'disclaimer': 'disable',
|
||||||
|
'dlp_sensor': 'test_value_8',
|
||||||
|
'dstaddr_negate': 'enable',
|
||||||
|
'global_label': 'test_value_10',
|
||||||
|
'http_tunnel_auth': 'enable',
|
||||||
|
'icap_profile': 'test_value_12',
|
||||||
|
'internet_service': 'enable',
|
||||||
|
'internet_service_negate': 'enable',
|
||||||
|
'ips_sensor': 'test_value_15',
|
||||||
|
'label': 'test_value_16',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'logtraffic_start': 'enable',
|
||||||
|
'policyid': '19',
|
||||||
|
'profile_group': 'test_value_20',
|
||||||
|
'profile_protocol_options': 'test_value_21',
|
||||||
|
'profile_type': 'single',
|
||||||
|
'proxy': 'explicit-web',
|
||||||
|
'redirect_url': 'test_value_24',
|
||||||
|
'replacemsg_override_group': 'test_value_25',
|
||||||
|
'scan_botnet_connections': 'disable',
|
||||||
|
'schedule': 'test_value_27',
|
||||||
|
'service_negate': 'enable',
|
||||||
|
'session_ttl': '29',
|
||||||
|
'spamfilter_profile': 'test_value_30',
|
||||||
|
'srcaddr_negate': 'enable',
|
||||||
|
'ssh_filter_profile': 'test_value_32',
|
||||||
|
'ssl_ssh_profile': 'test_value_33',
|
||||||
|
'status': 'enable',
|
||||||
|
'transparent': 'enable',
|
||||||
|
'utm_status': 'enable',
|
||||||
|
'uuid': 'test_value_37',
|
||||||
|
'waf_profile': 'test_value_38',
|
||||||
|
'webcache': 'enable',
|
||||||
|
'webcache_https': 'disable',
|
||||||
|
'webfilter_profile': 'test_value_41',
|
||||||
|
'webproxy_forward_server': 'test_value_42',
|
||||||
|
'webproxy_profile': 'test_value_43'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_proxy_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'accept',
|
||||||
|
'application-list': 'test_value_4',
|
||||||
|
'av-profile': 'test_value_5',
|
||||||
|
'comments': 'test_value_6',
|
||||||
|
'disclaimer': 'disable',
|
||||||
|
'dlp-sensor': 'test_value_8',
|
||||||
|
'dstaddr-negate': 'enable',
|
||||||
|
'global-label': 'test_value_10',
|
||||||
|
'http-tunnel-auth': 'enable',
|
||||||
|
'icap-profile': 'test_value_12',
|
||||||
|
'internet-service': 'enable',
|
||||||
|
'internet-service-negate': 'enable',
|
||||||
|
'ips-sensor': 'test_value_15',
|
||||||
|
'label': 'test_value_16',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'logtraffic-start': 'enable',
|
||||||
|
'policyid': '19',
|
||||||
|
'profile-group': 'test_value_20',
|
||||||
|
'profile-protocol-options': 'test_value_21',
|
||||||
|
'profile-type': 'single',
|
||||||
|
'proxy': 'explicit-web',
|
||||||
|
'redirect-url': 'test_value_24',
|
||||||
|
'replacemsg-override-group': 'test_value_25',
|
||||||
|
'scan-botnet-connections': 'disable',
|
||||||
|
'schedule': 'test_value_27',
|
||||||
|
'service-negate': 'enable',
|
||||||
|
'session-ttl': '29',
|
||||||
|
'spamfilter-profile': 'test_value_30',
|
||||||
|
'srcaddr-negate': 'enable',
|
||||||
|
'ssh-filter-profile': 'test_value_32',
|
||||||
|
'ssl-ssh-profile': 'test_value_33',
|
||||||
|
'status': 'enable',
|
||||||
|
'transparent': 'enable',
|
||||||
|
'utm-status': 'enable',
|
||||||
|
'uuid': 'test_value_37',
|
||||||
|
'waf-profile': 'test_value_38',
|
||||||
|
'webcache': 'enable',
|
||||||
|
'webcache-https': 'disable',
|
||||||
|
'webfilter-profile': 'test_value_41',
|
||||||
|
'webproxy-forward-server': 'test_value_42',
|
||||||
|
'webproxy-profile': 'test_value_43'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'proxy-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,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_firewall_schedule_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_schedule_group.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_schedule_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_schedule_group': {
|
||||||
|
'color': '3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_group.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.schedule', '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_schedule_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_schedule_group': {
|
||||||
|
'color': '3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_group.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.schedule', '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_schedule_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_schedule_group': {
|
||||||
|
'color': '3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_group.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.schedule', '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_schedule_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_schedule_group': {
|
||||||
|
'color': '3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_group.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.schedule', '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_schedule_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_schedule_group': {
|
||||||
|
'color': '3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_group.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.schedule', '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_schedule_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_schedule_group': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'color': '3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_group.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.schedule', '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,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_schedule_onetime
|
||||||
|
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_schedule_onetime.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_schedule_onetime_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_schedule_onetime': {
|
||||||
|
'color': '3',
|
||||||
|
'end': 'test_value_4',
|
||||||
|
'expiration_days': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_onetime.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'end': 'test_value_4',
|
||||||
|
'expiration-days': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.schedule', 'onetime', 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_schedule_onetime_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_schedule_onetime': {
|
||||||
|
'color': '3',
|
||||||
|
'end': 'test_value_4',
|
||||||
|
'expiration_days': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_onetime.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'end': 'test_value_4',
|
||||||
|
'expiration-days': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.schedule', 'onetime', 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_schedule_onetime_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_schedule_onetime': {
|
||||||
|
'color': '3',
|
||||||
|
'end': 'test_value_4',
|
||||||
|
'expiration_days': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_onetime.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.schedule', 'onetime', 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_schedule_onetime_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_schedule_onetime': {
|
||||||
|
'color': '3',
|
||||||
|
'end': 'test_value_4',
|
||||||
|
'expiration_days': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_onetime.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.schedule', 'onetime', 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_schedule_onetime_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_schedule_onetime': {
|
||||||
|
'color': '3',
|
||||||
|
'end': 'test_value_4',
|
||||||
|
'expiration_days': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_onetime.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'end': 'test_value_4',
|
||||||
|
'expiration-days': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.schedule', 'onetime', 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_schedule_onetime_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_schedule_onetime': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'color': '3',
|
||||||
|
'end': 'test_value_4',
|
||||||
|
'expiration_days': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_onetime.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'end': 'test_value_4',
|
||||||
|
'expiration-days': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.schedule', 'onetime', 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_schedule_recurring
|
||||||
|
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_schedule_recurring.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_schedule_recurring_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_schedule_recurring': {
|
||||||
|
'color': '3',
|
||||||
|
'day': 'sunday',
|
||||||
|
'end': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_recurring.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'day': 'sunday',
|
||||||
|
'end': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.schedule', 'recurring', 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_schedule_recurring_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_schedule_recurring': {
|
||||||
|
'color': '3',
|
||||||
|
'day': 'sunday',
|
||||||
|
'end': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_recurring.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'day': 'sunday',
|
||||||
|
'end': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.schedule', 'recurring', 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_schedule_recurring_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_schedule_recurring': {
|
||||||
|
'color': '3',
|
||||||
|
'day': 'sunday',
|
||||||
|
'end': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_recurring.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.schedule', 'recurring', 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_schedule_recurring_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_schedule_recurring': {
|
||||||
|
'color': '3',
|
||||||
|
'day': 'sunday',
|
||||||
|
'end': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_recurring.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.schedule', 'recurring', 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_schedule_recurring_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_schedule_recurring': {
|
||||||
|
'color': '3',
|
||||||
|
'day': 'sunday',
|
||||||
|
'end': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_recurring.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'day': 'sunday',
|
||||||
|
'end': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.schedule', 'recurring', 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_schedule_recurring_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_schedule_recurring': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'color': '3',
|
||||||
|
'day': 'sunday',
|
||||||
|
'end': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_schedule_recurring.fortios_firewall_schedule(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'day': 'sunday',
|
||||||
|
'end': 'test_value_5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'start': 'test_value_7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.schedule', 'recurring', 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_firewall_service_category
|
||||||
|
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_service_category.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_service_category_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_service_category': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_category.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.service', 'category', 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_service_category_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_service_category': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_category.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.service', 'category', 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_service_category_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_service_category': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_category.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.service', 'category', 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_service_category_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_service_category': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_category.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.service', 'category', 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_service_category_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_service_category': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_category.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.service', 'category', 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_service_category_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_service_category': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_category.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.service', 'category', 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,409 @@
|
|||||||
|
# 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_service_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_service_custom.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_service_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_service_custom': {'app_service_type': 'disable',
|
||||||
|
'category': 'test_value_4',
|
||||||
|
'check_reset_range': 'disable',
|
||||||
|
'color': '6',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'fqdn': 'test_value_8',
|
||||||
|
'helper': 'auto',
|
||||||
|
'icmpcode': '10',
|
||||||
|
'icmptype': '11',
|
||||||
|
'iprange': 'test_value_12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'protocol': 'TCP/UDP/SCTP',
|
||||||
|
'protocol_number': '15',
|
||||||
|
'proxy': 'enable',
|
||||||
|
'sctp_portrange': 'test_value_17',
|
||||||
|
'session_ttl': '18',
|
||||||
|
'tcp_halfclose_timer': '19',
|
||||||
|
'tcp_halfopen_timer': '20',
|
||||||
|
'tcp_portrange': 'test_value_21',
|
||||||
|
'tcp_timewait_timer': '22',
|
||||||
|
'udp_idle_timer': '23',
|
||||||
|
'udp_portrange': 'test_value_24',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_custom.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'app-service-type': 'disable',
|
||||||
|
'category': 'test_value_4',
|
||||||
|
'check-reset-range': 'disable',
|
||||||
|
'color': '6',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'fqdn': 'test_value_8',
|
||||||
|
'helper': 'auto',
|
||||||
|
'icmpcode': '10',
|
||||||
|
'icmptype': '11',
|
||||||
|
'iprange': 'test_value_12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'protocol': 'TCP/UDP/SCTP',
|
||||||
|
'protocol-number': '15',
|
||||||
|
'proxy': 'enable',
|
||||||
|
'sctp-portrange': 'test_value_17',
|
||||||
|
'session-ttl': '18',
|
||||||
|
'tcp-halfclose-timer': '19',
|
||||||
|
'tcp-halfopen-timer': '20',
|
||||||
|
'tcp-portrange': 'test_value_21',
|
||||||
|
'tcp-timewait-timer': '22',
|
||||||
|
'udp-idle-timer': '23',
|
||||||
|
'udp-portrange': 'test_value_24',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.service', '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_service_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_service_custom': {'app_service_type': 'disable',
|
||||||
|
'category': 'test_value_4',
|
||||||
|
'check_reset_range': 'disable',
|
||||||
|
'color': '6',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'fqdn': 'test_value_8',
|
||||||
|
'helper': 'auto',
|
||||||
|
'icmpcode': '10',
|
||||||
|
'icmptype': '11',
|
||||||
|
'iprange': 'test_value_12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'protocol': 'TCP/UDP/SCTP',
|
||||||
|
'protocol_number': '15',
|
||||||
|
'proxy': 'enable',
|
||||||
|
'sctp_portrange': 'test_value_17',
|
||||||
|
'session_ttl': '18',
|
||||||
|
'tcp_halfclose_timer': '19',
|
||||||
|
'tcp_halfopen_timer': '20',
|
||||||
|
'tcp_portrange': 'test_value_21',
|
||||||
|
'tcp_timewait_timer': '22',
|
||||||
|
'udp_idle_timer': '23',
|
||||||
|
'udp_portrange': 'test_value_24',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_custom.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'app-service-type': 'disable',
|
||||||
|
'category': 'test_value_4',
|
||||||
|
'check-reset-range': 'disable',
|
||||||
|
'color': '6',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'fqdn': 'test_value_8',
|
||||||
|
'helper': 'auto',
|
||||||
|
'icmpcode': '10',
|
||||||
|
'icmptype': '11',
|
||||||
|
'iprange': 'test_value_12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'protocol': 'TCP/UDP/SCTP',
|
||||||
|
'protocol-number': '15',
|
||||||
|
'proxy': 'enable',
|
||||||
|
'sctp-portrange': 'test_value_17',
|
||||||
|
'session-ttl': '18',
|
||||||
|
'tcp-halfclose-timer': '19',
|
||||||
|
'tcp-halfopen-timer': '20',
|
||||||
|
'tcp-portrange': 'test_value_21',
|
||||||
|
'tcp-timewait-timer': '22',
|
||||||
|
'udp-idle-timer': '23',
|
||||||
|
'udp-portrange': 'test_value_24',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.service', '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_service_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_service_custom': {'app_service_type': 'disable',
|
||||||
|
'category': 'test_value_4',
|
||||||
|
'check_reset_range': 'disable',
|
||||||
|
'color': '6',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'fqdn': 'test_value_8',
|
||||||
|
'helper': 'auto',
|
||||||
|
'icmpcode': '10',
|
||||||
|
'icmptype': '11',
|
||||||
|
'iprange': 'test_value_12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'protocol': 'TCP/UDP/SCTP',
|
||||||
|
'protocol_number': '15',
|
||||||
|
'proxy': 'enable',
|
||||||
|
'sctp_portrange': 'test_value_17',
|
||||||
|
'session_ttl': '18',
|
||||||
|
'tcp_halfclose_timer': '19',
|
||||||
|
'tcp_halfopen_timer': '20',
|
||||||
|
'tcp_portrange': 'test_value_21',
|
||||||
|
'tcp_timewait_timer': '22',
|
||||||
|
'udp_idle_timer': '23',
|
||||||
|
'udp_portrange': 'test_value_24',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_custom.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.service', '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_service_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_service_custom': {'app_service_type': 'disable',
|
||||||
|
'category': 'test_value_4',
|
||||||
|
'check_reset_range': 'disable',
|
||||||
|
'color': '6',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'fqdn': 'test_value_8',
|
||||||
|
'helper': 'auto',
|
||||||
|
'icmpcode': '10',
|
||||||
|
'icmptype': '11',
|
||||||
|
'iprange': 'test_value_12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'protocol': 'TCP/UDP/SCTP',
|
||||||
|
'protocol_number': '15',
|
||||||
|
'proxy': 'enable',
|
||||||
|
'sctp_portrange': 'test_value_17',
|
||||||
|
'session_ttl': '18',
|
||||||
|
'tcp_halfclose_timer': '19',
|
||||||
|
'tcp_halfopen_timer': '20',
|
||||||
|
'tcp_portrange': 'test_value_21',
|
||||||
|
'tcp_timewait_timer': '22',
|
||||||
|
'udp_idle_timer': '23',
|
||||||
|
'udp_portrange': 'test_value_24',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_custom.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.service', '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_service_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_service_custom': {'app_service_type': 'disable',
|
||||||
|
'category': 'test_value_4',
|
||||||
|
'check_reset_range': 'disable',
|
||||||
|
'color': '6',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'fqdn': 'test_value_8',
|
||||||
|
'helper': 'auto',
|
||||||
|
'icmpcode': '10',
|
||||||
|
'icmptype': '11',
|
||||||
|
'iprange': 'test_value_12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'protocol': 'TCP/UDP/SCTP',
|
||||||
|
'protocol_number': '15',
|
||||||
|
'proxy': 'enable',
|
||||||
|
'sctp_portrange': 'test_value_17',
|
||||||
|
'session_ttl': '18',
|
||||||
|
'tcp_halfclose_timer': '19',
|
||||||
|
'tcp_halfopen_timer': '20',
|
||||||
|
'tcp_portrange': 'test_value_21',
|
||||||
|
'tcp_timewait_timer': '22',
|
||||||
|
'udp_idle_timer': '23',
|
||||||
|
'udp_portrange': 'test_value_24',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_custom.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'app-service-type': 'disable',
|
||||||
|
'category': 'test_value_4',
|
||||||
|
'check-reset-range': 'disable',
|
||||||
|
'color': '6',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'fqdn': 'test_value_8',
|
||||||
|
'helper': 'auto',
|
||||||
|
'icmpcode': '10',
|
||||||
|
'icmptype': '11',
|
||||||
|
'iprange': 'test_value_12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'protocol': 'TCP/UDP/SCTP',
|
||||||
|
'protocol-number': '15',
|
||||||
|
'proxy': 'enable',
|
||||||
|
'sctp-portrange': 'test_value_17',
|
||||||
|
'session-ttl': '18',
|
||||||
|
'tcp-halfclose-timer': '19',
|
||||||
|
'tcp-halfopen-timer': '20',
|
||||||
|
'tcp-portrange': 'test_value_21',
|
||||||
|
'tcp-timewait-timer': '22',
|
||||||
|
'udp-idle-timer': '23',
|
||||||
|
'udp-portrange': 'test_value_24',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.service', '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_service_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_service_custom': {
|
||||||
|
'random_attribute_not_valid': 'tag', 'app_service_type': 'disable',
|
||||||
|
'category': 'test_value_4',
|
||||||
|
'check_reset_range': 'disable',
|
||||||
|
'color': '6',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'fqdn': 'test_value_8',
|
||||||
|
'helper': 'auto',
|
||||||
|
'icmpcode': '10',
|
||||||
|
'icmptype': '11',
|
||||||
|
'iprange': 'test_value_12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'protocol': 'TCP/UDP/SCTP',
|
||||||
|
'protocol_number': '15',
|
||||||
|
'proxy': 'enable',
|
||||||
|
'sctp_portrange': 'test_value_17',
|
||||||
|
'session_ttl': '18',
|
||||||
|
'tcp_halfclose_timer': '19',
|
||||||
|
'tcp_halfopen_timer': '20',
|
||||||
|
'tcp_portrange': 'test_value_21',
|
||||||
|
'tcp_timewait_timer': '22',
|
||||||
|
'udp_idle_timer': '23',
|
||||||
|
'udp_portrange': 'test_value_24',
|
||||||
|
'visibility': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_custom.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'app-service-type': 'disable',
|
||||||
|
'category': 'test_value_4',
|
||||||
|
'check-reset-range': 'disable',
|
||||||
|
'color': '6',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'fqdn': 'test_value_8',
|
||||||
|
'helper': 'auto',
|
||||||
|
'icmpcode': '10',
|
||||||
|
'icmptype': '11',
|
||||||
|
'iprange': 'test_value_12',
|
||||||
|
'name': 'default_name_13',
|
||||||
|
'protocol': 'TCP/UDP/SCTP',
|
||||||
|
'protocol-number': '15',
|
||||||
|
'proxy': 'enable',
|
||||||
|
'sctp-portrange': 'test_value_17',
|
||||||
|
'session-ttl': '18',
|
||||||
|
'tcp-halfclose-timer': '19',
|
||||||
|
'tcp-halfopen-timer': '20',
|
||||||
|
'tcp-portrange': 'test_value_21',
|
||||||
|
'tcp-timewait-timer': '22',
|
||||||
|
'udp-idle-timer': '23',
|
||||||
|
'udp-portrange': 'test_value_24',
|
||||||
|
'visibility': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.service', '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,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_service_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_service_group.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_service_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_service_group': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'proxy': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_group.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'proxy': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.service', '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_service_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_service_group': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'proxy': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_group.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'proxy': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.service', '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_service_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_service_group': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'proxy': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_group.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.service', '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_service_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_service_group': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'proxy': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_group.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.service', '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_service_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_service_group': {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'proxy': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_group.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'proxy': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.service', '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_service_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_service_group': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'proxy': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_service_group.fortios_firewall_service(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'color': '3',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'proxy': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.service', '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,269 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_firewall_shaper_per_ip_shaper
|
||||||
|
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_shaper_per_ip_shaper.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_shaper_per_ip_shaper_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_shaper_per_ip_shaper': {
|
||||||
|
'bandwidth_unit': 'kbps',
|
||||||
|
'diffserv_forward': 'enable',
|
||||||
|
'diffserv_reverse': 'enable',
|
||||||
|
'diffservcode_forward': 'test_value_6',
|
||||||
|
'diffservcode_rev': 'test_value_7',
|
||||||
|
'max_bandwidth': '8',
|
||||||
|
'max_concurrent_session': '9',
|
||||||
|
'name': 'default_name_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaper_per_ip_shaper.fortios_firewall_shaper(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bandwidth-unit': 'kbps',
|
||||||
|
'diffserv-forward': 'enable',
|
||||||
|
'diffserv-reverse': 'enable',
|
||||||
|
'diffservcode-forward': 'test_value_6',
|
||||||
|
'diffservcode-rev': 'test_value_7',
|
||||||
|
'max-bandwidth': '8',
|
||||||
|
'max-concurrent-session': '9',
|
||||||
|
'name': 'default_name_10'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.shaper', 'per-ip-shaper', 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_shaper_per_ip_shaper_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_shaper_per_ip_shaper': {
|
||||||
|
'bandwidth_unit': 'kbps',
|
||||||
|
'diffserv_forward': 'enable',
|
||||||
|
'diffserv_reverse': 'enable',
|
||||||
|
'diffservcode_forward': 'test_value_6',
|
||||||
|
'diffservcode_rev': 'test_value_7',
|
||||||
|
'max_bandwidth': '8',
|
||||||
|
'max_concurrent_session': '9',
|
||||||
|
'name': 'default_name_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaper_per_ip_shaper.fortios_firewall_shaper(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bandwidth-unit': 'kbps',
|
||||||
|
'diffserv-forward': 'enable',
|
||||||
|
'diffserv-reverse': 'enable',
|
||||||
|
'diffservcode-forward': 'test_value_6',
|
||||||
|
'diffservcode-rev': 'test_value_7',
|
||||||
|
'max-bandwidth': '8',
|
||||||
|
'max-concurrent-session': '9',
|
||||||
|
'name': 'default_name_10'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.shaper', 'per-ip-shaper', 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_shaper_per_ip_shaper_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_shaper_per_ip_shaper': {
|
||||||
|
'bandwidth_unit': 'kbps',
|
||||||
|
'diffserv_forward': 'enable',
|
||||||
|
'diffserv_reverse': 'enable',
|
||||||
|
'diffservcode_forward': 'test_value_6',
|
||||||
|
'diffservcode_rev': 'test_value_7',
|
||||||
|
'max_bandwidth': '8',
|
||||||
|
'max_concurrent_session': '9',
|
||||||
|
'name': 'default_name_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaper_per_ip_shaper.fortios_firewall_shaper(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.shaper', 'per-ip-shaper', 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_shaper_per_ip_shaper_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_shaper_per_ip_shaper': {
|
||||||
|
'bandwidth_unit': 'kbps',
|
||||||
|
'diffserv_forward': 'enable',
|
||||||
|
'diffserv_reverse': 'enable',
|
||||||
|
'diffservcode_forward': 'test_value_6',
|
||||||
|
'diffservcode_rev': 'test_value_7',
|
||||||
|
'max_bandwidth': '8',
|
||||||
|
'max_concurrent_session': '9',
|
||||||
|
'name': 'default_name_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaper_per_ip_shaper.fortios_firewall_shaper(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.shaper', 'per-ip-shaper', 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_shaper_per_ip_shaper_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_shaper_per_ip_shaper': {
|
||||||
|
'bandwidth_unit': 'kbps',
|
||||||
|
'diffserv_forward': 'enable',
|
||||||
|
'diffserv_reverse': 'enable',
|
||||||
|
'diffservcode_forward': 'test_value_6',
|
||||||
|
'diffservcode_rev': 'test_value_7',
|
||||||
|
'max_bandwidth': '8',
|
||||||
|
'max_concurrent_session': '9',
|
||||||
|
'name': 'default_name_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaper_per_ip_shaper.fortios_firewall_shaper(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bandwidth-unit': 'kbps',
|
||||||
|
'diffserv-forward': 'enable',
|
||||||
|
'diffserv-reverse': 'enable',
|
||||||
|
'diffservcode-forward': 'test_value_6',
|
||||||
|
'diffservcode-rev': 'test_value_7',
|
||||||
|
'max-bandwidth': '8',
|
||||||
|
'max-concurrent-session': '9',
|
||||||
|
'name': 'default_name_10'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.shaper', 'per-ip-shaper', 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_shaper_per_ip_shaper_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_shaper_per_ip_shaper': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'bandwidth_unit': 'kbps',
|
||||||
|
'diffserv_forward': 'enable',
|
||||||
|
'diffserv_reverse': 'enable',
|
||||||
|
'diffservcode_forward': 'test_value_6',
|
||||||
|
'diffservcode_rev': 'test_value_7',
|
||||||
|
'max_bandwidth': '8',
|
||||||
|
'max_concurrent_session': '9',
|
||||||
|
'name': 'default_name_10'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaper_per_ip_shaper.fortios_firewall_shaper(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bandwidth-unit': 'kbps',
|
||||||
|
'diffserv-forward': 'enable',
|
||||||
|
'diffserv-reverse': 'enable',
|
||||||
|
'diffservcode-forward': 'test_value_6',
|
||||||
|
'diffservcode-rev': 'test_value_7',
|
||||||
|
'max-bandwidth': '8',
|
||||||
|
'max-concurrent-session': '9',
|
||||||
|
'name': 'default_name_10'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.shaper', 'per-ip-shaper', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,269 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_firewall_shaper_traffic_shaper
|
||||||
|
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_shaper_traffic_shaper.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_shaper_traffic_shaper_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_shaper_traffic_shaper': {
|
||||||
|
'bandwidth_unit': 'kbps',
|
||||||
|
'diffserv': 'enable',
|
||||||
|
'diffservcode': 'test_value_5',
|
||||||
|
'guaranteed_bandwidth': '6',
|
||||||
|
'maximum_bandwidth': '7',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'per_policy': 'disable',
|
||||||
|
'priority': 'low'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaper_traffic_shaper.fortios_firewall_shaper(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bandwidth-unit': 'kbps',
|
||||||
|
'diffserv': 'enable',
|
||||||
|
'diffservcode': 'test_value_5',
|
||||||
|
'guaranteed-bandwidth': '6',
|
||||||
|
'maximum-bandwidth': '7',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'per-policy': 'disable',
|
||||||
|
'priority': 'low'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.shaper', 'traffic-shaper', 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_shaper_traffic_shaper_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_shaper_traffic_shaper': {
|
||||||
|
'bandwidth_unit': 'kbps',
|
||||||
|
'diffserv': 'enable',
|
||||||
|
'diffservcode': 'test_value_5',
|
||||||
|
'guaranteed_bandwidth': '6',
|
||||||
|
'maximum_bandwidth': '7',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'per_policy': 'disable',
|
||||||
|
'priority': 'low'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaper_traffic_shaper.fortios_firewall_shaper(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bandwidth-unit': 'kbps',
|
||||||
|
'diffserv': 'enable',
|
||||||
|
'diffservcode': 'test_value_5',
|
||||||
|
'guaranteed-bandwidth': '6',
|
||||||
|
'maximum-bandwidth': '7',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'per-policy': 'disable',
|
||||||
|
'priority': 'low'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.shaper', 'traffic-shaper', 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_shaper_traffic_shaper_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_shaper_traffic_shaper': {
|
||||||
|
'bandwidth_unit': 'kbps',
|
||||||
|
'diffserv': 'enable',
|
||||||
|
'diffservcode': 'test_value_5',
|
||||||
|
'guaranteed_bandwidth': '6',
|
||||||
|
'maximum_bandwidth': '7',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'per_policy': 'disable',
|
||||||
|
'priority': 'low'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaper_traffic_shaper.fortios_firewall_shaper(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.shaper', 'traffic-shaper', 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_shaper_traffic_shaper_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_shaper_traffic_shaper': {
|
||||||
|
'bandwidth_unit': 'kbps',
|
||||||
|
'diffserv': 'enable',
|
||||||
|
'diffservcode': 'test_value_5',
|
||||||
|
'guaranteed_bandwidth': '6',
|
||||||
|
'maximum_bandwidth': '7',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'per_policy': 'disable',
|
||||||
|
'priority': 'low'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaper_traffic_shaper.fortios_firewall_shaper(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.shaper', 'traffic-shaper', 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_shaper_traffic_shaper_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_shaper_traffic_shaper': {
|
||||||
|
'bandwidth_unit': 'kbps',
|
||||||
|
'diffserv': 'enable',
|
||||||
|
'diffservcode': 'test_value_5',
|
||||||
|
'guaranteed_bandwidth': '6',
|
||||||
|
'maximum_bandwidth': '7',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'per_policy': 'disable',
|
||||||
|
'priority': 'low'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaper_traffic_shaper.fortios_firewall_shaper(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bandwidth-unit': 'kbps',
|
||||||
|
'diffserv': 'enable',
|
||||||
|
'diffservcode': 'test_value_5',
|
||||||
|
'guaranteed-bandwidth': '6',
|
||||||
|
'maximum-bandwidth': '7',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'per-policy': 'disable',
|
||||||
|
'priority': 'low'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.shaper', 'traffic-shaper', 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_shaper_traffic_shaper_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_shaper_traffic_shaper': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'bandwidth_unit': 'kbps',
|
||||||
|
'diffserv': 'enable',
|
||||||
|
'diffservcode': 'test_value_5',
|
||||||
|
'guaranteed_bandwidth': '6',
|
||||||
|
'maximum_bandwidth': '7',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'per_policy': 'disable',
|
||||||
|
'priority': 'low'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaper_traffic_shaper.fortios_firewall_shaper(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bandwidth-unit': 'kbps',
|
||||||
|
'diffserv': 'enable',
|
||||||
|
'diffservcode': 'test_value_5',
|
||||||
|
'guaranteed-bandwidth': '6',
|
||||||
|
'maximum-bandwidth': '7',
|
||||||
|
'name': 'default_name_8',
|
||||||
|
'per-policy': 'disable',
|
||||||
|
'priority': 'low'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.shaper', 'traffic-shaper', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,299 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_firewall_shaping_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_shaping_policy.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_shaping_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_shaping_policy': {'class_id': '3',
|
||||||
|
'comment': 'Comments.',
|
||||||
|
'id': '5',
|
||||||
|
'internet_service': 'enable',
|
||||||
|
'internet_service_src': 'enable',
|
||||||
|
'ip_version': '4',
|
||||||
|
'per_ip_shaper': 'test_value_9',
|
||||||
|
'schedule': 'test_value_10',
|
||||||
|
'status': 'enable',
|
||||||
|
'traffic_shaper': 'test_value_12',
|
||||||
|
'traffic_shaper_reverse': 'test_value_13',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaping_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'class-id': '3',
|
||||||
|
'comment': 'Comments.',
|
||||||
|
'id': '5',
|
||||||
|
'internet-service': 'enable',
|
||||||
|
'internet-service-src': 'enable',
|
||||||
|
'ip-version': '4',
|
||||||
|
'per-ip-shaper': 'test_value_9',
|
||||||
|
'schedule': 'test_value_10',
|
||||||
|
'status': 'enable',
|
||||||
|
'traffic-shaper': 'test_value_12',
|
||||||
|
'traffic-shaper-reverse': 'test_value_13',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'shaping-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_shaping_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_shaping_policy': {'class_id': '3',
|
||||||
|
'comment': 'Comments.',
|
||||||
|
'id': '5',
|
||||||
|
'internet_service': 'enable',
|
||||||
|
'internet_service_src': 'enable',
|
||||||
|
'ip_version': '4',
|
||||||
|
'per_ip_shaper': 'test_value_9',
|
||||||
|
'schedule': 'test_value_10',
|
||||||
|
'status': 'enable',
|
||||||
|
'traffic_shaper': 'test_value_12',
|
||||||
|
'traffic_shaper_reverse': 'test_value_13',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaping_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'class-id': '3',
|
||||||
|
'comment': 'Comments.',
|
||||||
|
'id': '5',
|
||||||
|
'internet-service': 'enable',
|
||||||
|
'internet-service-src': 'enable',
|
||||||
|
'ip-version': '4',
|
||||||
|
'per-ip-shaper': 'test_value_9',
|
||||||
|
'schedule': 'test_value_10',
|
||||||
|
'status': 'enable',
|
||||||
|
'traffic-shaper': 'test_value_12',
|
||||||
|
'traffic-shaper-reverse': 'test_value_13',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'shaping-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_shaping_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_shaping_policy': {'class_id': '3',
|
||||||
|
'comment': 'Comments.',
|
||||||
|
'id': '5',
|
||||||
|
'internet_service': 'enable',
|
||||||
|
'internet_service_src': 'enable',
|
||||||
|
'ip_version': '4',
|
||||||
|
'per_ip_shaper': 'test_value_9',
|
||||||
|
'schedule': 'test_value_10',
|
||||||
|
'status': 'enable',
|
||||||
|
'traffic_shaper': 'test_value_12',
|
||||||
|
'traffic_shaper_reverse': 'test_value_13',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaping_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'shaping-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_shaping_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_shaping_policy': {'class_id': '3',
|
||||||
|
'comment': 'Comments.',
|
||||||
|
'id': '5',
|
||||||
|
'internet_service': 'enable',
|
||||||
|
'internet_service_src': 'enable',
|
||||||
|
'ip_version': '4',
|
||||||
|
'per_ip_shaper': 'test_value_9',
|
||||||
|
'schedule': 'test_value_10',
|
||||||
|
'status': 'enable',
|
||||||
|
'traffic_shaper': 'test_value_12',
|
||||||
|
'traffic_shaper_reverse': 'test_value_13',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaping_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'shaping-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_shaping_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_shaping_policy': {'class_id': '3',
|
||||||
|
'comment': 'Comments.',
|
||||||
|
'id': '5',
|
||||||
|
'internet_service': 'enable',
|
||||||
|
'internet_service_src': 'enable',
|
||||||
|
'ip_version': '4',
|
||||||
|
'per_ip_shaper': 'test_value_9',
|
||||||
|
'schedule': 'test_value_10',
|
||||||
|
'status': 'enable',
|
||||||
|
'traffic_shaper': 'test_value_12',
|
||||||
|
'traffic_shaper_reverse': 'test_value_13',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaping_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'class-id': '3',
|
||||||
|
'comment': 'Comments.',
|
||||||
|
'id': '5',
|
||||||
|
'internet-service': 'enable',
|
||||||
|
'internet-service-src': 'enable',
|
||||||
|
'ip-version': '4',
|
||||||
|
'per-ip-shaper': 'test_value_9',
|
||||||
|
'schedule': 'test_value_10',
|
||||||
|
'status': 'enable',
|
||||||
|
'traffic-shaper': 'test_value_12',
|
||||||
|
'traffic-shaper-reverse': 'test_value_13',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'shaping-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_shaping_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_shaping_policy': {
|
||||||
|
'random_attribute_not_valid': 'tag', 'class_id': '3',
|
||||||
|
'comment': 'Comments.',
|
||||||
|
'id': '5',
|
||||||
|
'internet_service': 'enable',
|
||||||
|
'internet_service_src': 'enable',
|
||||||
|
'ip_version': '4',
|
||||||
|
'per_ip_shaper': 'test_value_9',
|
||||||
|
'schedule': 'test_value_10',
|
||||||
|
'status': 'enable',
|
||||||
|
'traffic_shaper': 'test_value_12',
|
||||||
|
'traffic_shaper_reverse': 'test_value_13',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaping_policy.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'class-id': '3',
|
||||||
|
'comment': 'Comments.',
|
||||||
|
'id': '5',
|
||||||
|
'internet-service': 'enable',
|
||||||
|
'internet-service-src': 'enable',
|
||||||
|
'ip-version': '4',
|
||||||
|
'per-ip-shaper': 'test_value_9',
|
||||||
|
'schedule': 'test_value_10',
|
||||||
|
'status': 'enable',
|
||||||
|
'traffic-shaper': 'test_value_12',
|
||||||
|
'traffic-shaper-reverse': 'test_value_13',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'shaping-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,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_shaping_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_shaping_profile.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_shaping_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_shaping_profile': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'default_class_id': '4',
|
||||||
|
'profile_name': 'test_value_5',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaping_profile.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'default-class-id': '4',
|
||||||
|
'profile-name': 'test_value_5',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'shaping-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_shaping_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_shaping_profile': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'default_class_id': '4',
|
||||||
|
'profile_name': 'test_value_5',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaping_profile.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'default-class-id': '4',
|
||||||
|
'profile-name': 'test_value_5',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'shaping-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_shaping_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_shaping_profile': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'default_class_id': '4',
|
||||||
|
'profile_name': 'test_value_5',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaping_profile.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'shaping-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_shaping_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_shaping_profile': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'default_class_id': '4',
|
||||||
|
'profile_name': 'test_value_5',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaping_profile.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'shaping-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_shaping_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_shaping_profile': {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'default_class_id': '4',
|
||||||
|
'profile_name': 'test_value_5',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaping_profile.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'default-class-id': '4',
|
||||||
|
'profile-name': 'test_value_5',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'shaping-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_shaping_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_shaping_profile': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'default_class_id': '4',
|
||||||
|
'profile_name': 'test_value_5',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_shaping_profile.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comment': 'Comment.',
|
||||||
|
'default-class-id': '4',
|
||||||
|
'profile-name': 'test_value_5',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'shaping-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,439 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_firewall_sniffer
|
||||||
|
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_sniffer.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_sniffer_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_sniffer': {'application_list': 'test_value_3',
|
||||||
|
'application_list_status': 'enable',
|
||||||
|
'av_profile': 'test_value_5',
|
||||||
|
'av_profile_status': 'enable',
|
||||||
|
'dlp_sensor': 'test_value_7',
|
||||||
|
'dlp_sensor_status': 'enable',
|
||||||
|
'dsri': 'enable',
|
||||||
|
'host': 'myhostname10',
|
||||||
|
'id': '11',
|
||||||
|
'interface': 'test_value_12',
|
||||||
|
'ips_dos_status': 'enable',
|
||||||
|
'ips_sensor': 'test_value_14',
|
||||||
|
'ips_sensor_status': 'enable',
|
||||||
|
'ipv6': 'enable',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'max_packet_count': '18',
|
||||||
|
'non_ip': 'enable',
|
||||||
|
'port': 'test_value_20',
|
||||||
|
'protocol': 'test_value_21',
|
||||||
|
'scan_botnet_connections': 'disable',
|
||||||
|
'spamfilter_profile': 'test_value_23',
|
||||||
|
'spamfilter_profile_status': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'vlan': 'test_value_26',
|
||||||
|
'webfilter_profile': 'test_value_27',
|
||||||
|
'webfilter_profile_status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_sniffer.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'application-list': 'test_value_3',
|
||||||
|
'application-list-status': 'enable',
|
||||||
|
'av-profile': 'test_value_5',
|
||||||
|
'av-profile-status': 'enable',
|
||||||
|
'dlp-sensor': 'test_value_7',
|
||||||
|
'dlp-sensor-status': 'enable',
|
||||||
|
'dsri': 'enable',
|
||||||
|
'host': 'myhostname10',
|
||||||
|
'id': '11',
|
||||||
|
'interface': 'test_value_12',
|
||||||
|
'ips-dos-status': 'enable',
|
||||||
|
'ips-sensor': 'test_value_14',
|
||||||
|
'ips-sensor-status': 'enable',
|
||||||
|
'ipv6': 'enable',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'max-packet-count': '18',
|
||||||
|
'non-ip': 'enable',
|
||||||
|
'port': 'test_value_20',
|
||||||
|
'protocol': 'test_value_21',
|
||||||
|
'scan-botnet-connections': 'disable',
|
||||||
|
'spamfilter-profile': 'test_value_23',
|
||||||
|
'spamfilter-profile-status': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'vlan': 'test_value_26',
|
||||||
|
'webfilter-profile': 'test_value_27',
|
||||||
|
'webfilter-profile-status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'sniffer', 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_sniffer_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_sniffer': {'application_list': 'test_value_3',
|
||||||
|
'application_list_status': 'enable',
|
||||||
|
'av_profile': 'test_value_5',
|
||||||
|
'av_profile_status': 'enable',
|
||||||
|
'dlp_sensor': 'test_value_7',
|
||||||
|
'dlp_sensor_status': 'enable',
|
||||||
|
'dsri': 'enable',
|
||||||
|
'host': 'myhostname10',
|
||||||
|
'id': '11',
|
||||||
|
'interface': 'test_value_12',
|
||||||
|
'ips_dos_status': 'enable',
|
||||||
|
'ips_sensor': 'test_value_14',
|
||||||
|
'ips_sensor_status': 'enable',
|
||||||
|
'ipv6': 'enable',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'max_packet_count': '18',
|
||||||
|
'non_ip': 'enable',
|
||||||
|
'port': 'test_value_20',
|
||||||
|
'protocol': 'test_value_21',
|
||||||
|
'scan_botnet_connections': 'disable',
|
||||||
|
'spamfilter_profile': 'test_value_23',
|
||||||
|
'spamfilter_profile_status': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'vlan': 'test_value_26',
|
||||||
|
'webfilter_profile': 'test_value_27',
|
||||||
|
'webfilter_profile_status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_sniffer.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'application-list': 'test_value_3',
|
||||||
|
'application-list-status': 'enable',
|
||||||
|
'av-profile': 'test_value_5',
|
||||||
|
'av-profile-status': 'enable',
|
||||||
|
'dlp-sensor': 'test_value_7',
|
||||||
|
'dlp-sensor-status': 'enable',
|
||||||
|
'dsri': 'enable',
|
||||||
|
'host': 'myhostname10',
|
||||||
|
'id': '11',
|
||||||
|
'interface': 'test_value_12',
|
||||||
|
'ips-dos-status': 'enable',
|
||||||
|
'ips-sensor': 'test_value_14',
|
||||||
|
'ips-sensor-status': 'enable',
|
||||||
|
'ipv6': 'enable',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'max-packet-count': '18',
|
||||||
|
'non-ip': 'enable',
|
||||||
|
'port': 'test_value_20',
|
||||||
|
'protocol': 'test_value_21',
|
||||||
|
'scan-botnet-connections': 'disable',
|
||||||
|
'spamfilter-profile': 'test_value_23',
|
||||||
|
'spamfilter-profile-status': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'vlan': 'test_value_26',
|
||||||
|
'webfilter-profile': 'test_value_27',
|
||||||
|
'webfilter-profile-status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'sniffer', 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_sniffer_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_sniffer': {'application_list': 'test_value_3',
|
||||||
|
'application_list_status': 'enable',
|
||||||
|
'av_profile': 'test_value_5',
|
||||||
|
'av_profile_status': 'enable',
|
||||||
|
'dlp_sensor': 'test_value_7',
|
||||||
|
'dlp_sensor_status': 'enable',
|
||||||
|
'dsri': 'enable',
|
||||||
|
'host': 'myhostname10',
|
||||||
|
'id': '11',
|
||||||
|
'interface': 'test_value_12',
|
||||||
|
'ips_dos_status': 'enable',
|
||||||
|
'ips_sensor': 'test_value_14',
|
||||||
|
'ips_sensor_status': 'enable',
|
||||||
|
'ipv6': 'enable',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'max_packet_count': '18',
|
||||||
|
'non_ip': 'enable',
|
||||||
|
'port': 'test_value_20',
|
||||||
|
'protocol': 'test_value_21',
|
||||||
|
'scan_botnet_connections': 'disable',
|
||||||
|
'spamfilter_profile': 'test_value_23',
|
||||||
|
'spamfilter_profile_status': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'vlan': 'test_value_26',
|
||||||
|
'webfilter_profile': 'test_value_27',
|
||||||
|
'webfilter_profile_status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_sniffer.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'sniffer', 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_sniffer_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_sniffer': {'application_list': 'test_value_3',
|
||||||
|
'application_list_status': 'enable',
|
||||||
|
'av_profile': 'test_value_5',
|
||||||
|
'av_profile_status': 'enable',
|
||||||
|
'dlp_sensor': 'test_value_7',
|
||||||
|
'dlp_sensor_status': 'enable',
|
||||||
|
'dsri': 'enable',
|
||||||
|
'host': 'myhostname10',
|
||||||
|
'id': '11',
|
||||||
|
'interface': 'test_value_12',
|
||||||
|
'ips_dos_status': 'enable',
|
||||||
|
'ips_sensor': 'test_value_14',
|
||||||
|
'ips_sensor_status': 'enable',
|
||||||
|
'ipv6': 'enable',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'max_packet_count': '18',
|
||||||
|
'non_ip': 'enable',
|
||||||
|
'port': 'test_value_20',
|
||||||
|
'protocol': 'test_value_21',
|
||||||
|
'scan_botnet_connections': 'disable',
|
||||||
|
'spamfilter_profile': 'test_value_23',
|
||||||
|
'spamfilter_profile_status': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'vlan': 'test_value_26',
|
||||||
|
'webfilter_profile': 'test_value_27',
|
||||||
|
'webfilter_profile_status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_sniffer.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'sniffer', 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_sniffer_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_sniffer': {'application_list': 'test_value_3',
|
||||||
|
'application_list_status': 'enable',
|
||||||
|
'av_profile': 'test_value_5',
|
||||||
|
'av_profile_status': 'enable',
|
||||||
|
'dlp_sensor': 'test_value_7',
|
||||||
|
'dlp_sensor_status': 'enable',
|
||||||
|
'dsri': 'enable',
|
||||||
|
'host': 'myhostname10',
|
||||||
|
'id': '11',
|
||||||
|
'interface': 'test_value_12',
|
||||||
|
'ips_dos_status': 'enable',
|
||||||
|
'ips_sensor': 'test_value_14',
|
||||||
|
'ips_sensor_status': 'enable',
|
||||||
|
'ipv6': 'enable',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'max_packet_count': '18',
|
||||||
|
'non_ip': 'enable',
|
||||||
|
'port': 'test_value_20',
|
||||||
|
'protocol': 'test_value_21',
|
||||||
|
'scan_botnet_connections': 'disable',
|
||||||
|
'spamfilter_profile': 'test_value_23',
|
||||||
|
'spamfilter_profile_status': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'vlan': 'test_value_26',
|
||||||
|
'webfilter_profile': 'test_value_27',
|
||||||
|
'webfilter_profile_status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_sniffer.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'application-list': 'test_value_3',
|
||||||
|
'application-list-status': 'enable',
|
||||||
|
'av-profile': 'test_value_5',
|
||||||
|
'av-profile-status': 'enable',
|
||||||
|
'dlp-sensor': 'test_value_7',
|
||||||
|
'dlp-sensor-status': 'enable',
|
||||||
|
'dsri': 'enable',
|
||||||
|
'host': 'myhostname10',
|
||||||
|
'id': '11',
|
||||||
|
'interface': 'test_value_12',
|
||||||
|
'ips-dos-status': 'enable',
|
||||||
|
'ips-sensor': 'test_value_14',
|
||||||
|
'ips-sensor-status': 'enable',
|
||||||
|
'ipv6': 'enable',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'max-packet-count': '18',
|
||||||
|
'non-ip': 'enable',
|
||||||
|
'port': 'test_value_20',
|
||||||
|
'protocol': 'test_value_21',
|
||||||
|
'scan-botnet-connections': 'disable',
|
||||||
|
'spamfilter-profile': 'test_value_23',
|
||||||
|
'spamfilter-profile-status': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'vlan': 'test_value_26',
|
||||||
|
'webfilter-profile': 'test_value_27',
|
||||||
|
'webfilter-profile-status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'sniffer', 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_sniffer_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_sniffer': {
|
||||||
|
'random_attribute_not_valid': 'tag', 'application_list': 'test_value_3',
|
||||||
|
'application_list_status': 'enable',
|
||||||
|
'av_profile': 'test_value_5',
|
||||||
|
'av_profile_status': 'enable',
|
||||||
|
'dlp_sensor': 'test_value_7',
|
||||||
|
'dlp_sensor_status': 'enable',
|
||||||
|
'dsri': 'enable',
|
||||||
|
'host': 'myhostname10',
|
||||||
|
'id': '11',
|
||||||
|
'interface': 'test_value_12',
|
||||||
|
'ips_dos_status': 'enable',
|
||||||
|
'ips_sensor': 'test_value_14',
|
||||||
|
'ips_sensor_status': 'enable',
|
||||||
|
'ipv6': 'enable',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'max_packet_count': '18',
|
||||||
|
'non_ip': 'enable',
|
||||||
|
'port': 'test_value_20',
|
||||||
|
'protocol': 'test_value_21',
|
||||||
|
'scan_botnet_connections': 'disable',
|
||||||
|
'spamfilter_profile': 'test_value_23',
|
||||||
|
'spamfilter_profile_status': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'vlan': 'test_value_26',
|
||||||
|
'webfilter_profile': 'test_value_27',
|
||||||
|
'webfilter_profile_status': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_sniffer.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'application-list': 'test_value_3',
|
||||||
|
'application-list-status': 'enable',
|
||||||
|
'av-profile': 'test_value_5',
|
||||||
|
'av-profile-status': 'enable',
|
||||||
|
'dlp-sensor': 'test_value_7',
|
||||||
|
'dlp-sensor-status': 'enable',
|
||||||
|
'dsri': 'enable',
|
||||||
|
'host': 'myhostname10',
|
||||||
|
'id': '11',
|
||||||
|
'interface': 'test_value_12',
|
||||||
|
'ips-dos-status': 'enable',
|
||||||
|
'ips-sensor': 'test_value_14',
|
||||||
|
'ips-sensor-status': 'enable',
|
||||||
|
'ipv6': 'enable',
|
||||||
|
'logtraffic': 'all',
|
||||||
|
'max-packet-count': '18',
|
||||||
|
'non-ip': 'enable',
|
||||||
|
'port': 'test_value_20',
|
||||||
|
'protocol': 'test_value_21',
|
||||||
|
'scan-botnet-connections': 'disable',
|
||||||
|
'spamfilter-profile': 'test_value_23',
|
||||||
|
'spamfilter-profile-status': 'enable',
|
||||||
|
'status': 'enable',
|
||||||
|
'vlan': 'test_value_26',
|
||||||
|
'webfilter-profile': 'test_value_27',
|
||||||
|
'webfilter-profile-status': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'sniffer', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,269 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_firewall_ssh_host_key
|
||||||
|
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_ssh_host_key.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ssh_host_key_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_ssh_host_key': {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'nid': '256',
|
||||||
|
'port': '7',
|
||||||
|
'public_key': 'test_value_8',
|
||||||
|
'status': 'trusted',
|
||||||
|
'type': 'RSA'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_host_key.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'nid': '256',
|
||||||
|
'port': '7',
|
||||||
|
'public-key': 'test_value_8',
|
||||||
|
'status': 'trusted',
|
||||||
|
'type': 'RSA'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'host-key', 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_ssh_host_key_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_ssh_host_key': {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'nid': '256',
|
||||||
|
'port': '7',
|
||||||
|
'public_key': 'test_value_8',
|
||||||
|
'status': 'trusted',
|
||||||
|
'type': 'RSA'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_host_key.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'nid': '256',
|
||||||
|
'port': '7',
|
||||||
|
'public-key': 'test_value_8',
|
||||||
|
'status': 'trusted',
|
||||||
|
'type': 'RSA'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'host-key', 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_ssh_host_key_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_ssh_host_key': {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'nid': '256',
|
||||||
|
'port': '7',
|
||||||
|
'public_key': 'test_value_8',
|
||||||
|
'status': 'trusted',
|
||||||
|
'type': 'RSA'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_host_key.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.ssh', 'host-key', 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_ssh_host_key_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_ssh_host_key': {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'nid': '256',
|
||||||
|
'port': '7',
|
||||||
|
'public_key': 'test_value_8',
|
||||||
|
'status': 'trusted',
|
||||||
|
'type': 'RSA'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_host_key.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.ssh', 'host-key', 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_ssh_host_key_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_ssh_host_key': {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'nid': '256',
|
||||||
|
'port': '7',
|
||||||
|
'public_key': 'test_value_8',
|
||||||
|
'status': 'trusted',
|
||||||
|
'type': 'RSA'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_host_key.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'nid': '256',
|
||||||
|
'port': '7',
|
||||||
|
'public-key': 'test_value_8',
|
||||||
|
'status': 'trusted',
|
||||||
|
'type': 'RSA'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'host-key', 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_ssh_host_key_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_ssh_host_key': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'nid': '256',
|
||||||
|
'port': '7',
|
||||||
|
'public_key': 'test_value_8',
|
||||||
|
'status': 'trusted',
|
||||||
|
'type': 'RSA'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_host_key.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'name': 'default_name_5',
|
||||||
|
'nid': '256',
|
||||||
|
'port': '7',
|
||||||
|
'public-key': 'test_value_8',
|
||||||
|
'status': 'trusted',
|
||||||
|
'type': 'RSA'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'host-key', 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_ssh_local_ca
|
||||||
|
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_ssh_local_ca.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ssh_local_ca_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_ssh_local_ca': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private_key': 'test_value_5',
|
||||||
|
'public_key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_local_ca.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private-key': 'test_value_5',
|
||||||
|
'public-key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'local-ca', 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_ssh_local_ca_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_ssh_local_ca': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private_key': 'test_value_5',
|
||||||
|
'public_key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_local_ca.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private-key': 'test_value_5',
|
||||||
|
'public-key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'local-ca', 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_ssh_local_ca_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_ssh_local_ca': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private_key': 'test_value_5',
|
||||||
|
'public_key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_local_ca.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.ssh', 'local-ca', 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_ssh_local_ca_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_ssh_local_ca': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private_key': 'test_value_5',
|
||||||
|
'public_key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_local_ca.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.ssh', 'local-ca', 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_ssh_local_ca_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_ssh_local_ca': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private_key': 'test_value_5',
|
||||||
|
'public_key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_local_ca.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private-key': 'test_value_5',
|
||||||
|
'public-key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'local-ca', 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_ssh_local_ca_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_ssh_local_ca': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private_key': 'test_value_5',
|
||||||
|
'public_key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_local_ca.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private-key': 'test_value_5',
|
||||||
|
'public-key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'local-ca', 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_ssh_local_key
|
||||||
|
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_ssh_local_key.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ssh_local_key_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_ssh_local_key': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private_key': 'test_value_5',
|
||||||
|
'public_key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_local_key.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private-key': 'test_value_5',
|
||||||
|
'public-key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'local-key', 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_ssh_local_key_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_ssh_local_key': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private_key': 'test_value_5',
|
||||||
|
'public_key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_local_key.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private-key': 'test_value_5',
|
||||||
|
'public-key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'local-key', 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_ssh_local_key_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_ssh_local_key': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private_key': 'test_value_5',
|
||||||
|
'public_key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_local_key.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.ssh', 'local-key', 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_ssh_local_key_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_ssh_local_key': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private_key': 'test_value_5',
|
||||||
|
'public_key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_local_key.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall.ssh', 'local-key', 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_ssh_local_key_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_ssh_local_key': {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private_key': 'test_value_5',
|
||||||
|
'public_key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_local_key.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private-key': 'test_value_5',
|
||||||
|
'public-key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'local-key', 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_ssh_local_key_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_ssh_local_key': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private_key': 'test_value_5',
|
||||||
|
'public_key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_local_key.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'name': 'default_name_3',
|
||||||
|
'password': 'test_value_4',
|
||||||
|
'private-key': 'test_value_5',
|
||||||
|
'public-key': 'test_value_6',
|
||||||
|
'source': 'built-in'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'local-key', 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,215 @@
|
|||||||
|
# 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_ssh_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_firewall_ssh_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ssh_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_ssh_setting': {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'host_trusted_checking': 'enable',
|
||||||
|
'hostkey_dsa1024': 'myhostname5',
|
||||||
|
'hostkey_ecdsa256': 'myhostname6',
|
||||||
|
'hostkey_ecdsa384': 'myhostname7',
|
||||||
|
'hostkey_ecdsa521': 'myhostname8',
|
||||||
|
'hostkey_ed25519': 'myhostname9',
|
||||||
|
'hostkey_rsa2048': 'myhostname10',
|
||||||
|
'untrusted_caname': 'test_value_11'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_setting.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'host-trusted-checking': 'enable',
|
||||||
|
'hostkey-dsa1024': 'myhostname5',
|
||||||
|
'hostkey-ecdsa256': 'myhostname6',
|
||||||
|
'hostkey-ecdsa384': 'myhostname7',
|
||||||
|
'hostkey-ecdsa521': 'myhostname8',
|
||||||
|
'hostkey-ed25519': 'myhostname9',
|
||||||
|
'hostkey-rsa2048': 'myhostname10',
|
||||||
|
'untrusted-caname': 'test_value_11'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ssh_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_ssh_setting': {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'host_trusted_checking': 'enable',
|
||||||
|
'hostkey_dsa1024': 'myhostname5',
|
||||||
|
'hostkey_ecdsa256': 'myhostname6',
|
||||||
|
'hostkey_ecdsa384': 'myhostname7',
|
||||||
|
'hostkey_ecdsa521': 'myhostname8',
|
||||||
|
'hostkey_ed25519': 'myhostname9',
|
||||||
|
'hostkey_rsa2048': 'myhostname10',
|
||||||
|
'untrusted_caname': 'test_value_11'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_setting.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'host-trusted-checking': 'enable',
|
||||||
|
'hostkey-dsa1024': 'myhostname5',
|
||||||
|
'hostkey-ecdsa256': 'myhostname6',
|
||||||
|
'hostkey-ecdsa384': 'myhostname7',
|
||||||
|
'hostkey-ecdsa521': 'myhostname8',
|
||||||
|
'hostkey-ed25519': 'myhostname9',
|
||||||
|
'hostkey-rsa2048': 'myhostname10',
|
||||||
|
'untrusted-caname': 'test_value_11'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ssh_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_ssh_setting': {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'host_trusted_checking': 'enable',
|
||||||
|
'hostkey_dsa1024': 'myhostname5',
|
||||||
|
'hostkey_ecdsa256': 'myhostname6',
|
||||||
|
'hostkey_ecdsa384': 'myhostname7',
|
||||||
|
'hostkey_ecdsa521': 'myhostname8',
|
||||||
|
'hostkey_ed25519': 'myhostname9',
|
||||||
|
'hostkey_rsa2048': 'myhostname10',
|
||||||
|
'untrusted_caname': 'test_value_11'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_setting.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'host-trusted-checking': 'enable',
|
||||||
|
'hostkey-dsa1024': 'myhostname5',
|
||||||
|
'hostkey-ecdsa256': 'myhostname6',
|
||||||
|
'hostkey-ecdsa384': 'myhostname7',
|
||||||
|
'hostkey-ecdsa521': 'myhostname8',
|
||||||
|
'hostkey-ed25519': 'myhostname9',
|
||||||
|
'hostkey-rsa2048': 'myhostname10',
|
||||||
|
'untrusted-caname': 'test_value_11'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ssh_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_ssh_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'host_trusted_checking': 'enable',
|
||||||
|
'hostkey_dsa1024': 'myhostname5',
|
||||||
|
'hostkey_ecdsa256': 'myhostname6',
|
||||||
|
'hostkey_ecdsa384': 'myhostname7',
|
||||||
|
'hostkey_ecdsa521': 'myhostname8',
|
||||||
|
'hostkey_ed25519': 'myhostname9',
|
||||||
|
'hostkey_rsa2048': 'myhostname10',
|
||||||
|
'untrusted_caname': 'test_value_11'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssh_setting.fortios_firewall_ssh(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'caname': 'test_value_3',
|
||||||
|
'host-trusted-checking': 'enable',
|
||||||
|
'hostkey-dsa1024': 'myhostname5',
|
||||||
|
'hostkey-ecdsa256': 'myhostname6',
|
||||||
|
'hostkey-ecdsa384': 'myhostname7',
|
||||||
|
'hostkey-ecdsa521': 'myhostname8',
|
||||||
|
'hostkey-ed25519': 'myhostname9',
|
||||||
|
'hostkey-rsa2048': 'myhostname10',
|
||||||
|
'untrusted-caname': 'test_value_11'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssh', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,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_firewall_ssl_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_firewall_ssl_server.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ssl_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',
|
||||||
|
'firewall_ssl_server': {
|
||||||
|
'add_header_x_forwarded_proto': 'enable',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'mapped_port': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'port': '7',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_cert': 'test_value_9',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_max_version': 'tls-1.0',
|
||||||
|
'ssl_min_version': 'tls-1.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'url_rewrite': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_server.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'add-header-x-forwarded-proto': 'enable',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'mapped-port': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'port': '7',
|
||||||
|
'ssl-algorithm': 'high',
|
||||||
|
'ssl-cert': 'test_value_9',
|
||||||
|
'ssl-client-renegotiation': 'allow',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-max-version': 'tls-1.0',
|
||||||
|
'ssl-min-version': 'tls-1.0',
|
||||||
|
'ssl-mode': 'half',
|
||||||
|
'ssl-send-empty-frags': 'enable',
|
||||||
|
'url-rewrite': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'ssl-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_firewall_ssl_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',
|
||||||
|
'firewall_ssl_server': {
|
||||||
|
'add_header_x_forwarded_proto': 'enable',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'mapped_port': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'port': '7',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_cert': 'test_value_9',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_max_version': 'tls-1.0',
|
||||||
|
'ssl_min_version': 'tls-1.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'url_rewrite': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_server.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'add-header-x-forwarded-proto': 'enable',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'mapped-port': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'port': '7',
|
||||||
|
'ssl-algorithm': 'high',
|
||||||
|
'ssl-cert': 'test_value_9',
|
||||||
|
'ssl-client-renegotiation': 'allow',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-max-version': 'tls-1.0',
|
||||||
|
'ssl-min-version': 'tls-1.0',
|
||||||
|
'ssl-mode': 'half',
|
||||||
|
'ssl-send-empty-frags': 'enable',
|
||||||
|
'url-rewrite': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'ssl-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_firewall_ssl_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',
|
||||||
|
'firewall_ssl_server': {
|
||||||
|
'add_header_x_forwarded_proto': 'enable',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'mapped_port': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'port': '7',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_cert': 'test_value_9',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_max_version': 'tls-1.0',
|
||||||
|
'ssl_min_version': 'tls-1.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'url_rewrite': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_server.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'ssl-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_firewall_ssl_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',
|
||||||
|
'firewall_ssl_server': {
|
||||||
|
'add_header_x_forwarded_proto': 'enable',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'mapped_port': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'port': '7',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_cert': 'test_value_9',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_max_version': 'tls-1.0',
|
||||||
|
'ssl_min_version': 'tls-1.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'url_rewrite': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_server.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('firewall', 'ssl-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_firewall_ssl_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',
|
||||||
|
'firewall_ssl_server': {
|
||||||
|
'add_header_x_forwarded_proto': 'enable',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'mapped_port': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'port': '7',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_cert': 'test_value_9',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_max_version': 'tls-1.0',
|
||||||
|
'ssl_min_version': 'tls-1.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'url_rewrite': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_server.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'add-header-x-forwarded-proto': 'enable',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'mapped-port': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'port': '7',
|
||||||
|
'ssl-algorithm': 'high',
|
||||||
|
'ssl-cert': 'test_value_9',
|
||||||
|
'ssl-client-renegotiation': 'allow',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-max-version': 'tls-1.0',
|
||||||
|
'ssl-min-version': 'tls-1.0',
|
||||||
|
'ssl-mode': 'half',
|
||||||
|
'ssl-send-empty-frags': 'enable',
|
||||||
|
'url-rewrite': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'ssl-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_firewall_ssl_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',
|
||||||
|
'firewall_ssl_server': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'add_header_x_forwarded_proto': 'enable',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'mapped_port': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'port': '7',
|
||||||
|
'ssl_algorithm': 'high',
|
||||||
|
'ssl_cert': 'test_value_9',
|
||||||
|
'ssl_client_renegotiation': 'allow',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_max_version': 'tls-1.0',
|
||||||
|
'ssl_min_version': 'tls-1.0',
|
||||||
|
'ssl_mode': 'half',
|
||||||
|
'ssl_send_empty_frags': 'enable',
|
||||||
|
'url_rewrite': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_server.fortios_firewall(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'add-header-x-forwarded-proto': 'enable',
|
||||||
|
'ip': 'test_value_4',
|
||||||
|
'mapped-port': '5',
|
||||||
|
'name': 'default_name_6',
|
||||||
|
'port': '7',
|
||||||
|
'ssl-algorithm': 'high',
|
||||||
|
'ssl-cert': 'test_value_9',
|
||||||
|
'ssl-client-renegotiation': 'allow',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-max-version': 'tls-1.0',
|
||||||
|
'ssl-min-version': 'tls-1.0',
|
||||||
|
'ssl-mode': 'half',
|
||||||
|
'ssl-send-empty-frags': 'enable',
|
||||||
|
'url-rewrite': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall', 'ssl-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,231 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_firewall_ssl_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_firewall_ssl_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ssl_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_ssl_setting': {
|
||||||
|
'abbreviate_handshake': 'enable',
|
||||||
|
'cert_cache_capacity': '4',
|
||||||
|
'cert_cache_timeout': '5',
|
||||||
|
'kxp_queue_threshold': '6',
|
||||||
|
'no_matching_cipher_action': 'bypass',
|
||||||
|
'proxy_connect_timeout': '8',
|
||||||
|
'session_cache_capacity': '9',
|
||||||
|
'session_cache_timeout': '10',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_queue_threshold': '12',
|
||||||
|
'ssl_send_empty_frags': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_setting.fortios_firewall_ssl(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'abbreviate-handshake': 'enable',
|
||||||
|
'cert-cache-capacity': '4',
|
||||||
|
'cert-cache-timeout': '5',
|
||||||
|
'kxp-queue-threshold': '6',
|
||||||
|
'no-matching-cipher-action': 'bypass',
|
||||||
|
'proxy-connect-timeout': '8',
|
||||||
|
'session-cache-capacity': '9',
|
||||||
|
'session-cache-timeout': '10',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-queue-threshold': '12',
|
||||||
|
'ssl-send-empty-frags': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssl', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ssl_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_ssl_setting': {
|
||||||
|
'abbreviate_handshake': 'enable',
|
||||||
|
'cert_cache_capacity': '4',
|
||||||
|
'cert_cache_timeout': '5',
|
||||||
|
'kxp_queue_threshold': '6',
|
||||||
|
'no_matching_cipher_action': 'bypass',
|
||||||
|
'proxy_connect_timeout': '8',
|
||||||
|
'session_cache_capacity': '9',
|
||||||
|
'session_cache_timeout': '10',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_queue_threshold': '12',
|
||||||
|
'ssl_send_empty_frags': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_setting.fortios_firewall_ssl(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'abbreviate-handshake': 'enable',
|
||||||
|
'cert-cache-capacity': '4',
|
||||||
|
'cert-cache-timeout': '5',
|
||||||
|
'kxp-queue-threshold': '6',
|
||||||
|
'no-matching-cipher-action': 'bypass',
|
||||||
|
'proxy-connect-timeout': '8',
|
||||||
|
'session-cache-capacity': '9',
|
||||||
|
'session-cache-timeout': '10',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-queue-threshold': '12',
|
||||||
|
'ssl-send-empty-frags': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssl', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ssl_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_ssl_setting': {
|
||||||
|
'abbreviate_handshake': 'enable',
|
||||||
|
'cert_cache_capacity': '4',
|
||||||
|
'cert_cache_timeout': '5',
|
||||||
|
'kxp_queue_threshold': '6',
|
||||||
|
'no_matching_cipher_action': 'bypass',
|
||||||
|
'proxy_connect_timeout': '8',
|
||||||
|
'session_cache_capacity': '9',
|
||||||
|
'session_cache_timeout': '10',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_queue_threshold': '12',
|
||||||
|
'ssl_send_empty_frags': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_setting.fortios_firewall_ssl(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'abbreviate-handshake': 'enable',
|
||||||
|
'cert-cache-capacity': '4',
|
||||||
|
'cert-cache-timeout': '5',
|
||||||
|
'kxp-queue-threshold': '6',
|
||||||
|
'no-matching-cipher-action': 'bypass',
|
||||||
|
'proxy-connect-timeout': '8',
|
||||||
|
'session-cache-capacity': '9',
|
||||||
|
'session-cache-timeout': '10',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-queue-threshold': '12',
|
||||||
|
'ssl-send-empty-frags': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssl', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_firewall_ssl_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'firewall_ssl_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'abbreviate_handshake': 'enable',
|
||||||
|
'cert_cache_capacity': '4',
|
||||||
|
'cert_cache_timeout': '5',
|
||||||
|
'kxp_queue_threshold': '6',
|
||||||
|
'no_matching_cipher_action': 'bypass',
|
||||||
|
'proxy_connect_timeout': '8',
|
||||||
|
'session_cache_capacity': '9',
|
||||||
|
'session_cache_timeout': '10',
|
||||||
|
'ssl_dh_bits': '768',
|
||||||
|
'ssl_queue_threshold': '12',
|
||||||
|
'ssl_send_empty_frags': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_firewall_ssl_setting.fortios_firewall_ssl(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'abbreviate-handshake': 'enable',
|
||||||
|
'cert-cache-capacity': '4',
|
||||||
|
'cert-cache-timeout': '5',
|
||||||
|
'kxp-queue-threshold': '6',
|
||||||
|
'no-matching-cipher-action': 'bypass',
|
||||||
|
'proxy-connect-timeout': '8',
|
||||||
|
'session-cache-capacity': '9',
|
||||||
|
'session-cache-timeout': '10',
|
||||||
|
'ssl-dh-bits': '768',
|
||||||
|
'ssl-queue-threshold': '12',
|
||||||
|
'ssl-send-empty-frags': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('firewall.ssl', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
Loading…
Reference in New Issue