mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
New FortiManager Module: fmgr_secprof_proxy (#53029)
* Auto Commit for: fmgr_secprof_proxy * Auto Commit for: fmgr_secprof_proxy * Auto Commit for: fmgr_secprof_proxy
This commit is contained in:
committed by
Nilashish Chakraborty
parent
421a5c4c91
commit
29657bdda5
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"fmgr_web_proxy_profile_modify": [
|
||||
{
|
||||
"paramgram_used": {
|
||||
"header-via-request": null,
|
||||
"name": "Ansible_Web_Proxy_Profile",
|
||||
"header-front-end-https": null,
|
||||
"log-header-change": null,
|
||||
"adom": "root",
|
||||
"headers": {
|
||||
"action": null,
|
||||
"content": null,
|
||||
"name": null
|
||||
},
|
||||
"mode": "delete",
|
||||
"header-via-response": null,
|
||||
"header-x-authenticated-user": null,
|
||||
"strip-encoding": null,
|
||||
"header-x-forwarded-for": null,
|
||||
"header-x-authenticated-groups": null,
|
||||
"header-client-ip": null
|
||||
},
|
||||
"datagram_sent": {},
|
||||
"raw_response": {
|
||||
"status": {
|
||||
"message": "OK",
|
||||
"code": 0
|
||||
},
|
||||
"url": "/pm/config/adom/root/obj/web-proxy/profile/Ansible_Web_Proxy_Profile"
|
||||
},
|
||||
"post_method": "delete"
|
||||
},
|
||||
{
|
||||
"raw_response": {
|
||||
"status": {
|
||||
"message": "OK",
|
||||
"code": 0
|
||||
},
|
||||
"url": "/pm/config/adom/root/obj/web-proxy/profile"
|
||||
},
|
||||
"datagram_sent": {
|
||||
"header-via-request": "remove",
|
||||
"name": "Ansible_Web_Proxy_Profile",
|
||||
"header-front-end-https": "add",
|
||||
"log-header-change": "enable",
|
||||
"headers": {
|
||||
"action": "add-to-request",
|
||||
"content": "test",
|
||||
"name": "test_header"
|
||||
},
|
||||
"header-via-response": "pass",
|
||||
"header-x-authenticated-user": "remove",
|
||||
"strip-encoding": "enable",
|
||||
"header-x-forwarded-for": "pass",
|
||||
"header-x-authenticated-groups": "add",
|
||||
"header-client-ip": "pass"
|
||||
},
|
||||
"paramgram_used": {
|
||||
"header-via-request": "remove",
|
||||
"header-client-ip": "pass",
|
||||
"header-front-end-https": "add",
|
||||
"header-x-authenticated-groups": "add",
|
||||
"name": "Ansible_Web_Proxy_Profile",
|
||||
"log-header-change": "enable",
|
||||
"adom": "root",
|
||||
"headers": {
|
||||
"action": "add-to-request",
|
||||
"content": "test",
|
||||
"name": "test_header"
|
||||
},
|
||||
"mode": "set",
|
||||
"header-via-response": "pass",
|
||||
"header-x-authenticated-user": "remove",
|
||||
"strip-encoding": "enable",
|
||||
"header-x-forwarded-for": "pass"
|
||||
},
|
||||
"post_method": "set"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
# Copyright 2018 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
|
||||
from ansible.module_utils.network.fortimanager.fortimanager import FortiManagerHandler
|
||||
import pytest
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortimanager import fmgr_secprof_proxy
|
||||
except ImportError:
|
||||
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||
|
||||
|
||||
def load_fixtures():
|
||||
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures') + "/{filename}.json".format(
|
||||
filename=os.path.splitext(os.path.basename(__file__))[0])
|
||||
try:
|
||||
with open(fixture_path, "r") as fixture_file:
|
||||
fixture_data = json.load(fixture_file)
|
||||
except IOError:
|
||||
return []
|
||||
return [fixture_data]
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def module_mock(mocker):
|
||||
connection_class_mock = mocker.patch('ansible.module_utils.basic.AnsibleModule')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def connection_mock(mocker):
|
||||
connection_class_mock = mocker.patch('ansible.modules.network.fortimanager.fmgr_secprof_proxy.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
@pytest.fixture(scope="function", params=load_fixtures())
|
||||
def fixture_data(request):
|
||||
func_name = request.function.__name__.replace("test_", "")
|
||||
return request.param.get(func_name, None)
|
||||
|
||||
|
||||
fmg_instance = FortiManagerHandler(connection_mock, module_mock)
|
||||
|
||||
|
||||
def test_fmgr_web_proxy_profile_modify(fixture_data, mocker):
|
||||
mocker.patch("ansible.module_utils.network.fortimanager.fortimanager.FortiManagerHandler.process_request",
|
||||
side_effect=fixture_data)
|
||||
|
||||
# Test using fixture 1 #
|
||||
output = fmgr_secprof_proxy.fmgr_web_proxy_profile_modify(fmg_instance, fixture_data[0]['paramgram_used'])
|
||||
assert output['raw_response']['status']['code'] == 0
|
||||
# Test using fixture 2 #
|
||||
output = fmgr_secprof_proxy.fmgr_web_proxy_profile_modify(fmg_instance, fixture_data[1]['paramgram_used'])
|
||||
assert output['raw_response']['status']['code'] == 0
|
||||
Reference in New Issue
Block a user