FortiManager security profile group module (#46220)

* Initial Commit

* Initial Commit

* Initial Commit

* Fixing syntax errors

* After running sanity tests, fixed pylint and pep8 errors

* After running sanity tests, fixed pylint and pep8 errors

* Fixing more syntax issues

* Fixing more syntax issues

* Adding username to doc block

* PR candidate

* PR candidate

* fixed pep8 and docs issues

* fixed 2.6 function issues

* fixed 2.6 function issues part duex

* Initial commit for security profile group module

* Adding better playbook example to module

* Adding another commit to test shippable tests

* Fixing shippable errors, pep8 in unit test file and doc block problem in main module

* Fixing documentation module error

* Fixing pep8 line too long in unit test

* Fixing utility function with nested dictionaries

* Fixing utility function with pep8 issue

* Adding change to allow for multiple list of dictionaries to be submitted via a single playbook

* Fixing review changes

* Adding @ in author names per @Gundalow's request per Ansible's guidelines
This commit is contained in:
ftntcorecse 2018-11-20 22:48:19 -07:00 committed by Sumit Jaiswal
commit 4862a4aeb4
4 changed files with 963 additions and 0 deletions

View file

@ -0,0 +1,371 @@
{
"fmgr_antivirus_profile_addSetDelete": [
{
"raw_response": {
"status": {
"message": "Object does not exist",
"code": -3
},
"url": "/pm/config/adom/root/obj/antivirus/profile/Ansible_AV_Profile"
},
"paramgram_used": {
"comment": null,
"av-block-log": null,
"extended-log": null,
"analytics-db": null,
"analytics-wl-filetype": null,
"av-virus-log": null,
"content-disarm": {
"pdf-act-movie": null,
"pdf-act-gotor": null,
"pdf-act-java": null,
"original-file-destination": null,
"office-hylink": null,
"pdf-act-sound": null,
"detect-only": null,
"office-embed": null,
"office-linked": null,
"pdf-javacode": null,
"pdf-hyperlink": null,
"pdf-embedfile": null,
"office-macro": null,
"pdf-act-form": null,
"pdf-act-launch": null,
"cover-page": null
},
"ftp": {
"outbreak-prevention": null,
"options": null,
"archive-log": null,
"emulator": null,
"archive-block": null
},
"mapi": {
"executables": null,
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"options": null
},
"analytics-max-upload": null,
"nntp": {
"outbreak-prevention": null,
"options": null,
"archive-log": null,
"emulator": null,
"archive-block": null
},
"smb": {
"outbreak-prevention": null,
"options": null,
"archive-log": null,
"emulator": null,
"archive-block": null
},
"analytics-bl-filetype": null,
"http": {
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"content-disarm": null,
"options": null
},
"adom": "root",
"smtp": {
"executables": null,
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"content-disarm": null,
"options": null
},
"pop3": {
"executables": null,
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"content-disarm": null,
"options": null
},
"inspection-mode": null,
"ftgd-analytics": null,
"imap": {
"executables": null,
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"content-disarm": null,
"options": null
},
"name": "Ansible_AV_Profile",
"replacemsg-group": null,
"scan-mode": null,
"nac-quar": {
"infected": null,
"log": null,
"expiry": null
},
"mode": "delete",
"mobile-malware-db": null
},
"post_method": "delete"
},
{
"paramgram_used": {
"comment": "Created by Ansible Module TEST",
"name": "Ansible_AV_Profile",
"scan-mode": "full",
"av-block-log": "enable",
"inspection-mode": "proxy",
"av-virus-log": "enable",
"ftgd-analytics": "everything",
"mobile-malware-db": "enable",
"mode": "delete",
"adom": "root"
},
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/root/obj/antivirus/profile"
},
"post_method": "set"
},
{
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/root/obj/antivirus/profile/Ansible_AV_Profile"
},
"paramgram_used": {
"comment": null,
"av-block-log": null,
"extended-log": null,
"analytics-db": null,
"analytics-wl-filetype": null,
"av-virus-log": null,
"content-disarm": {
"pdf-act-movie": null,
"pdf-act-gotor": null,
"office-macro": null,
"pdf-act-java": null,
"original-file-destination": null,
"office-hylink": null,
"pdf-act-sound": null,
"detect-only": null,
"office-embed": null,
"office-linked": null,
"pdf-javacode": null,
"pdf-hyperlink": null,
"cover-page": null,
"pdf-embedfile": null,
"pdf-act-form": null,
"pdf-act-launch": null
},
"ftp": {
"outbreak-prevention": null,
"options": null,
"archive-log": null,
"emulator": null,
"archive-block": null
},
"mapi": {
"executables": null,
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"options": null
},
"analytics-max-upload": null,
"nntp": {
"outbreak-prevention": null,
"options": null,
"archive-log": null,
"emulator": null,
"archive-block": null
},
"smb": {
"outbreak-prevention": null,
"options": null,
"archive-log": null,
"emulator": null,
"archive-block": null
},
"analytics-bl-filetype": null,
"http": {
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"content-disarm": null,
"options": null
},
"adom": "root",
"smtp": {
"executables": null,
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"content-disarm": null,
"options": null
},
"pop3": {
"executables": null,
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"content-disarm": null,
"options": null
},
"inspection-mode": null,
"ftgd-analytics": null,
"imap": {
"executables": null,
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"content-disarm": null,
"options": null
},
"name": "Ansible_AV_Profile",
"replacemsg-group": null,
"scan-mode": null,
"nac-quar": {
"infected": null,
"log": null,
"expiry": null
},
"mode": "delete",
"mobile-malware-db": null
},
"post_method": "delete"
},
{
"raw_response": {
"status": {
"message": "used",
"code": -10015
},
"url": "/pm/config/adom/root/obj/antivirus/profile/Ansible_AV_Profile"
},
"paramgram_used": {
"comment": null,
"av-block-log": null,
"extended-log": null,
"analytics-db": null,
"analytics-wl-filetype": null,
"av-virus-log": null,
"content-disarm": {
"pdf-act-movie": null,
"pdf-act-gotor": null,
"pdf-act-java": null,
"original-file-destination": null,
"cover-page": null,
"pdf-act-sound": null,
"detect-only": null,
"office-embed": null,
"pdf-embedfile": null,
"office-linked": null,
"pdf-javacode": null,
"pdf-hyperlink": null,
"office-hylink": null,
"office-macro": null,
"pdf-act-form": null,
"pdf-act-launch": null
},
"ftp": {
"outbreak-prevention": null,
"options": null,
"archive-log": null,
"emulator": null,
"archive-block": null
},
"smtp": {
"executables": null,
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"content-disarm": null,
"options": null
},
"mapi": {
"executables": null,
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"options": null
},
"analytics-max-upload": null,
"nntp": {
"outbreak-prevention": null,
"options": null,
"archive-log": null,
"emulator": null,
"archive-block": null
},
"smb": {
"outbreak-prevention": null,
"options": null,
"archive-log": null,
"emulator": null,
"archive-block": null
},
"analytics-bl-filetype": null,
"http": {
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"content-disarm": null,
"options": null
},
"adom": "root",
"scan-mode": null,
"pop3": {
"executables": null,
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"content-disarm": null,
"options": null
},
"inspection-mode": null,
"ftgd-analytics": null,
"imap": {
"executables": null,
"archive-log": null,
"outbreak-prevention": null,
"emulator": null,
"archive-block": null,
"content-disarm": null,
"options": null
},
"name": "Ansible_AV_Profile",
"replacemsg-group": null,
"nac-quar": {
"infected": null,
"log": null,
"expiry": null
},
"mode": "delete",
"mobile-malware-db": null
},
"post_method": "delete"
}
]
}

View file

@ -0,0 +1,62 @@
{
"fmgr_firewall_profile_group_addsetdelete": [
{
"paramgram_used": {
"ssl-ssh-profile": null,
"waf-profile": null,
"adom": "root",
"webfilter-profile": null,
"profile-protocol-options": null,
"application-list": null,
"icap-profile": null,
"voip-profile": null,
"ips-sensor": null,
"dnsfilter-profile": null,
"av-profile": null,
"spamfilter-profile": null,
"dlp-sensor": null,
"mode": "delete",
"ssh-filter-profile": null,
"mms-profile": null,
"name": "Ansible_TEST_Profile_Group"
},
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/root/obj/firewall/profile-group/Ansible_TEST_Profile_Group"
},
"post_method": "delete"
},
{
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/root/obj/firewall/profile-group"
},
"paramgram_used": {
"ssl-ssh-profile": null,
"application-list": null,
"waf-profile": null,
"adom": "root",
"webfilter-profile": null,
"ips-sensor": null,
"spamfilter-profile": null,
"icap-profile": null,
"dnsfilter-profile": null,
"name": "Ansible_TEST_Profile_Group",
"voip-profile": null,
"av-profile": "Ansible_AV_Profile",
"mode": "set",
"dlp-sensor": null,
"mms-profile": null,
"ssh-filter-profile": null,
"profile-protocol-options": "default"
},
"post_method": "set"
}
]
}

View file

@ -0,0 +1,100 @@
# 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 pyFMG.fortimgr import FortiManager
import pytest
try:
from ansible.modules.network.fortimanager import fmgr_secprof_profile_group
except ImportError:
pytest.skip("Could not load required modules for testing", allow_module_level=True)
fmg_instance = FortiManager("1.1.1.1", "admin", "")
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(scope="function", params=load_fixtures())
def fixture_data(request):
func_name = request.function.__name__.replace("test_", "")
return request.param.get(func_name, None)
def test_fmgr_firewall_profile_group_addsetdelete(fixture_data, mocker):
mocker.patch("pyFMG.fortimgr.FortiManager._post_request", side_effect=fixture_data)
# Fixture sets used:###########################
##################################################
# ssl-ssh-profile: None
# waf-profile: None
# adom: root
# webfilter-profile: None
# profile-protocol-options: None
# application-list: None
# icap-profile: None
# voip-profile: None
# ips-sensor: None
# dnsfilter-profile: None
# av-profile: None
# spamfilter-profile: None
# dlp-sensor: None
# mode: delete
# ssh-filter-profile: None
# mms-profile: None
# name: Ansible_TEST_Profile_Group
##################################################
##################################################
# ssl-ssh-profile: None
# application-list: None
# waf-profile: None
# adom: root
# webfilter-profile: None
# ips-sensor: None
# spamfilter-profile: None
# icap-profile: None
# dnsfilter-profile: None
# name: Ansible_TEST_Profile_Group
# voip-profile: None
# av-profile: Ansible_AV_Profile
# mode: set
# dlp-sensor: None
# mms-profile: None
# ssh-filter-profile: None
# profile-protocol-options: default
##################################################
# Test using fixture 1 #
output = fmgr_secprof_profile_group.fmgr_firewall_profile_group_addsetdelete(fmg_instance,
fixture_data[0]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 2 #
output = fmgr_secprof_profile_group.fmgr_firewall_profile_group_addsetdelete(fmg_instance,
fixture_data[1]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0