New FortiManager Module: fmgr_secprof_appctrl (#53028)

* Auto Commit for: fmgr_secprof_appctrl

* Auto Commit for: fmgr_secprof_appctrl
This commit is contained in:
ftntcorecse 2019-03-04 06:09:48 -05:00 committed by Nilashish Chakraborty
parent 29657bdda5
commit 340aa26edf
3 changed files with 849 additions and 0 deletions

View file

@ -0,0 +1,250 @@
{
"fmgr_application_list_modify": [
{
"paramgram_used": {
"comment": "Created by Ansible Module TEST",
"other-application-log": null,
"replacemsg-group": null,
"adom": "ansible",
"unknown-application-log": null,
"p2p-black-list": null,
"unknown-application-action": null,
"extended-log": null,
"deep-app-inspection": null,
"mode": "delete",
"other-application-action": null,
"entries": {
"behavior": null,
"rate-duration": null,
"sub-category": null,
"session-ttl": null,
"per-ip-shaper": null,
"category": null,
"log": null,
"parameters": {
"value": null
},
"technology": null,
"quarantine-expiry": null,
"application": null,
"protocols": null,
"log-packet": null,
"quarantine-log": null,
"vendor": null,
"risk": null,
"rate-count": null,
"quarantine": null,
"popularity": null,
"shaper": null,
"shaper-reverse": null,
"rate-track": null,
"rate-mode": null,
"action": null
},
"options": null,
"app-replacemsg": null,
"name": "Ansible_Application_Control_Profile"
},
"datagram_sent": {},
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/ansible/obj/application/list/Ansible_Application_Control_Profile"
},
"post_method": "delete"
},
{
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/ansible/obj/application/list"
},
"datagram_sent": {
"comment": "Created by Ansible Module TEST",
"name": "Ansible_Application_Control_Profile",
"entries": [
{
"quarantine-log": "enable",
"log": "enable",
"quarantine": "attacker",
"action": "block",
"log-packet": "enable",
"protocols": [
"1"
]
},
{
"action": "pass",
"category": [
"2",
"3",
"4"
]
}
]
},
"paramgram_used": {
"comment": "Created by Ansible Module TEST",
"other-application-log": null,
"replacemsg-group": null,
"p2p-black-list": null,
"unknown-application-log": null,
"adom": "ansible",
"unknown-application-action": null,
"extended-log": null,
"deep-app-inspection": null,
"mode": "set",
"other-application-action": null,
"entries": [
{
"quarantine-log": "enable",
"log": "enable",
"quarantine": "attacker",
"action": "block",
"log-packet": "enable",
"protocols": [
"1"
]
},
{
"action": "pass",
"category": [
"2",
"3",
"4"
]
}
],
"options": null,
"app-replacemsg": null,
"name": "Ansible_Application_Control_Profile"
},
"post_method": "set"
},
{
"paramgram_used": {
"comment": "Created by Ansible Module TEST",
"other-application-log": null,
"replacemsg-group": null,
"adom": "ansible",
"unknown-application-log": null,
"p2p-black-list": null,
"unknown-application-action": null,
"extended-log": null,
"options": null,
"deep-app-inspection": null,
"mode": "delete",
"other-application-action": null,
"entries": {
"behavior": null,
"rate-duration": null,
"sub-category": null,
"session-ttl": null,
"per-ip-shaper": null,
"category": null,
"log": null,
"parameters": {
"value": null
},
"technology": null,
"quarantine-expiry": null,
"application": null,
"protocols": null,
"log-packet": null,
"quarantine-log": null,
"vendor": null,
"risk": null,
"rate-count": null,
"quarantine": null,
"popularity": null,
"shaper": null,
"shaper-reverse": null,
"rate-track": null,
"rate-mode": null,
"action": null
},
"app-replacemsg": null,
"name": "Ansible_Application_Ctl_Profile2"
},
"datagram_sent": {},
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/ansible/obj/application/list/Ansible_Application_Ctl_Profile2"
},
"post_method": "delete"
},
{
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/ansible/obj/application/list"
},
"datagram_sent": {
"comment": "Created by Ansible Module TEST",
"name": "Ansible_Application_Ctl_Profile2",
"entries": {
"quarantine-log": "enable",
"log": "enable",
"quarantine": "attacker",
"action": "pass",
"log-packet": "enable",
"protocols": "['1']"
}
},
"paramgram_used": {
"comment": "Created by Ansible Module TEST",
"adom": "ansible",
"unknown-application-log": null,
"extended-log": null,
"other-application-action": null,
"entries": {
"rate-duration": null,
"sub-category": null,
"vendor": null,
"technology": null,
"risk": null,
"category": null,
"log": "enable",
"parameters": {
"value": null
},
"per-ip-shaper": null,
"quarantine-expiry": null,
"application": null,
"protocols": "['1']",
"log-packet": "enable",
"quarantine-log": "enable",
"session-ttl": null,
"behavior": null,
"rate-count": null,
"quarantine": "attacker",
"popularity": null,
"shaper": null,
"shaper-reverse": null,
"rate-track": null,
"rate-mode": null,
"action": "pass"
},
"replacemsg-group": null,
"other-application-log": null,
"name": "Ansible_Application_Ctl_Profile2",
"p2p-black-list": null,
"unknown-application-action": null,
"deep-app-inspection": null,
"mode": "set",
"app-replacemsg": null,
"options": null
},
"post_method": "set"
}
]
}

View file

@ -0,0 +1,78 @@
# 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_appctrl
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_appctrl.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_application_list_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_appctrl.fmgr_application_list_modify(fmg_instance, fixture_data[0]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 2 #
output = fmgr_secprof_appctrl.fmgr_application_list_modify(fmg_instance, fixture_data[1]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 3 #
output = fmgr_secprof_appctrl.fmgr_application_list_modify(fmg_instance, fixture_data[2]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 4 #
output = fmgr_secprof_appctrl.fmgr_application_list_modify(fmg_instance, fixture_data[3]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0