FortiManager Web Filter Security Profile (#47150)
* 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 * Initial commit for FMG Security Profile Web Application Firewall * adding extra line at bottom for pep8 conditions * Adding descriptions to documentation * Fixing more pep8 issues * New commit for new PR * Removing todo in documentation * Changing module name in documentation to match actual module name * Fixing yaml syntax for long choices list * Fixing yaml syntax for long choices list * Initial commit for fmgr web filter security profile * Fixing pep8 syntax issues * Fixing documentation yaml syntax errors with choices on new lines * Fixing documentation yaml syntax errors, removing Todo comments * Fixing choices additional tab * Fixing choices on multiple lines * Fixing choices on multiple lines * Adding yaml block scalar for multiline choices * Changing YAML syntax for multiline to YAML sequence for choices * Fixing all sanity test errors * Fixing review changes * Adding @ in author names per @Gundalow's request per Ansible's guidelines
This commit is contained in:
parent
199cd1bc77
commit
a171b80a0c
3 changed files with 1604 additions and 0 deletions
1233
lib/ansible/modules/network/fortimanager/fmgr_secprof_web.py
Normal file
1233
lib/ansible/modules/network/fortimanager/fmgr_secprof_web.py
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,214 @@
|
|||
{
|
||||
"fmgr_webfilter_profile_addsetdelete": [
|
||||
{
|
||||
"paramgram_used": {
|
||||
"comment": null,
|
||||
"web-extended-all-action-log": null,
|
||||
"url-extraction": {
|
||||
"status": null,
|
||||
"redirect-url": null,
|
||||
"server-fqdn": null,
|
||||
"redirect-header": null,
|
||||
"redirect-no-content": null
|
||||
},
|
||||
"ftgd-wf": {
|
||||
"filters": {
|
||||
"category": null,
|
||||
"log": null,
|
||||
"override-replacemsg": null,
|
||||
"warning-duration-type": null,
|
||||
"warn-duration": null,
|
||||
"auth-usr-grp": null,
|
||||
"action": null,
|
||||
"warning-prompt": null
|
||||
},
|
||||
"ovrd": null,
|
||||
"rate-image-urls": null,
|
||||
"quota": {
|
||||
"category": null,
|
||||
"value": null,
|
||||
"override-replacemsg": null,
|
||||
"duration": null,
|
||||
"type": null,
|
||||
"unit": null
|
||||
},
|
||||
"options": null,
|
||||
"rate-javascript-urls": null,
|
||||
"max-quota-timeout": null,
|
||||
"rate-css-urls": null,
|
||||
"exempt-quota": null,
|
||||
"rate-crl-urls": null
|
||||
},
|
||||
"log-all-url": null,
|
||||
"extended-log": null,
|
||||
"web-filter-cookie-removal-log": null,
|
||||
"https-replacemsg": null,
|
||||
"web": {
|
||||
"log-search": null,
|
||||
"bword-threshold": null,
|
||||
"bword-table": null,
|
||||
"whitelist": null,
|
||||
"youtube-restrict": null,
|
||||
"safe-search": null,
|
||||
"blacklist": null,
|
||||
"keyword-match": null,
|
||||
"urlfilter-table": null,
|
||||
"content-header-list": null
|
||||
},
|
||||
"wisp": null,
|
||||
"web-filter-vbs-log": null,
|
||||
"youtube-channel-filter": {
|
||||
"comment": null,
|
||||
"channel-id": null
|
||||
},
|
||||
"override": {
|
||||
"profile": null,
|
||||
"ovrd-scope": null,
|
||||
"ovrd-dur-mode": null,
|
||||
"profile-attribute": null,
|
||||
"ovrd-dur": null,
|
||||
"profile-type": null,
|
||||
"ovrd-user-group": null,
|
||||
"ovrd-cookie": null
|
||||
},
|
||||
"ovrd-perm": null,
|
||||
"mode": "delete",
|
||||
"web-content-log": null,
|
||||
"web-invalid-domain-log": null,
|
||||
"adom": "root",
|
||||
"web-filter-referer-log": null,
|
||||
"inspection-mode": null,
|
||||
"post-action": null,
|
||||
"name": "Ansible_Web_Filter_Profile",
|
||||
"web-filter-command-block-log": null,
|
||||
"web-filter-applet-log": null,
|
||||
"web-ftgd-err-log": null,
|
||||
"replacemsg-group": null,
|
||||
"web-filter-jscript-log": null,
|
||||
"web-filter-activex-log": null,
|
||||
"web-filter-js-log": null,
|
||||
"web-ftgd-quota-usage": null,
|
||||
"web-filter-unknown-log": null,
|
||||
"web-filter-cookie-log": null,
|
||||
"youtube-channel-status": null,
|
||||
"web-url-log": null,
|
||||
"options": null,
|
||||
"wisp-servers": null,
|
||||
"wisp-algorithm": null
|
||||
},
|
||||
"raw_response": {
|
||||
"status": {
|
||||
"message": "OK",
|
||||
"code": 0
|
||||
},
|
||||
"url": "/pm/config/adom/root/obj/webfilter/profile/Ansible_Web_Filter_Profile"
|
||||
},
|
||||
"post_method": "delete"
|
||||
},
|
||||
{
|
||||
"raw_response": {
|
||||
"status": {
|
||||
"message": "OK",
|
||||
"code": 0
|
||||
},
|
||||
"url": "/pm/config/adom/root/obj/webfilter/profile"
|
||||
},
|
||||
"paramgram_used": {
|
||||
"comment": "Created by Ansible Module TEST",
|
||||
"web-filter-command-block-log": "enable",
|
||||
"web-invalid-domain-log": "enable",
|
||||
"web-extended-all-action-log": "enable",
|
||||
"adom": "root",
|
||||
"ftgd-wf": {
|
||||
"rate-javascript-urls": null,
|
||||
"quota": {
|
||||
"category": null,
|
||||
"value": null,
|
||||
"override-replacemsg": null,
|
||||
"duration": null,
|
||||
"type": null,
|
||||
"unit": null
|
||||
},
|
||||
"rate-image-urls": null,
|
||||
"filters": {
|
||||
"category": null,
|
||||
"auth-usr-grp": null,
|
||||
"log": null,
|
||||
"warning-prompt": null,
|
||||
"override-replacemsg": null,
|
||||
"action": null,
|
||||
"warn-duration": null,
|
||||
"warning-duration-type": null
|
||||
},
|
||||
"rate-css-urls": null,
|
||||
"ovrd": null,
|
||||
"exempt-quota": null,
|
||||
"max-quota-timeout": null,
|
||||
"rate-crl-urls": null,
|
||||
"options": null
|
||||
},
|
||||
"web-content-log": "enable",
|
||||
"web-filter-referer-log": "enable",
|
||||
"log-all-url": "enable",
|
||||
"extended-log": "enable",
|
||||
"inspection-mode": "proxy",
|
||||
"web-filter-cookie-removal-log": "enable",
|
||||
"post-action": "block",
|
||||
"web-filter-activex-log": "enable",
|
||||
"web-filter-cookie-log": "enable",
|
||||
"web": {
|
||||
"blacklist": null,
|
||||
"log-search": null,
|
||||
"keyword-match": null,
|
||||
"urlfilter-table": null,
|
||||
"bword-table": null,
|
||||
"safe-search": null,
|
||||
"whitelist": null,
|
||||
"content-header-list": null,
|
||||
"youtube-restrict": null,
|
||||
"bword-threshold": null
|
||||
},
|
||||
"web-filter-applet-log": "enable",
|
||||
"web-ftgd-err-log": "enable",
|
||||
"replacemsg-group": null,
|
||||
"web-filter-jscript-log": "enable",
|
||||
"web-ftgd-quota-usage": "enable",
|
||||
"url-extraction": {
|
||||
"status": null,
|
||||
"server-fqdn": null,
|
||||
"redirect-url": null,
|
||||
"redirect-header": null,
|
||||
"redirect-no-content": null
|
||||
},
|
||||
"web-filter-js-log": "enable",
|
||||
"youtube-channel-filter": {
|
||||
"comment": null,
|
||||
"channel-id": null
|
||||
},
|
||||
"name": "Ansible_Web_Filter_Profile",
|
||||
"wisp": "enable",
|
||||
"web-filter-vbs-log": "enable",
|
||||
"web-filter-unknown-log": "enable",
|
||||
"mode": "set",
|
||||
"youtube-channel-status": "blacklist",
|
||||
"override": {
|
||||
"profile": null,
|
||||
"ovrd-user-group": null,
|
||||
"ovrd-scope": null,
|
||||
"ovrd-cookie": null,
|
||||
"ovrd-dur-mode": null,
|
||||
"profile-attribute": null,
|
||||
"ovrd-dur": null,
|
||||
"profile-type": null
|
||||
},
|
||||
"web-url-log": "enable",
|
||||
"ovrd-perm": "bannedword-override",
|
||||
"https-replacemsg": null,
|
||||
"options": "js",
|
||||
"wisp-servers": null,
|
||||
"wisp-algorithm": "auto-learning"
|
||||
},
|
||||
"post_method": "set"
|
||||
}
|
||||
]
|
||||
}
|
157
test/units/modules/network/fortimanager/test_fmgr_secprof_web.py
Normal file
157
test/units/modules/network/fortimanager/test_fmgr_secprof_web.py
Normal file
|
@ -0,0 +1,157 @@
|
|||
# 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_web
|
||||
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_webfilter_profile_addsetdelete(fixture_data, mocker):
|
||||
mocker.patch("pyFMG.fortimgr.FortiManager._post_request", side_effect=fixture_data)
|
||||
# Fixture sets used:###########################
|
||||
|
||||
##################################################
|
||||
# comment: None
|
||||
# web-extended-all-action-log: None
|
||||
# url-extraction: {'status': None, 'redirect-url': None, 'server-fqdn': None, 'redirect-header': None,
|
||||
# 'redirect-no-content': None}
|
||||
# ftgd-wf: {'filters': {'category': None, 'log': None, 'override-replacemsg': None, 'warning-duration-type': None,
|
||||
# 'warn-duration': None, 'auth-usr-grp': None, 'action': None, 'warning-prompt': None}, 'ovrd': None,
|
||||
# 'rate-image-urls': None, 'quota': {'category': None, 'value': None, 'override-replacemsg': None,
|
||||
# 'duration': None, 'type': None, 'unit': None}, 'options': None, 'rate-javascript-urls': None,
|
||||
# 'max-quota-timeout': None, 'rate-css-urls': None, 'exempt-quota': None, 'rate-crl-urls': None}
|
||||
# log-all-url: None
|
||||
# extended-log: None
|
||||
# web-filter-cookie-removal-log: None
|
||||
# https-replacemsg: None
|
||||
# web: {'log-search': None, 'bword-threshold': None, 'bword-table': None, 'whitelist': None,
|
||||
# 'youtube-restrict': None, 'safe-search': None, 'blacklist': None, 'keyword-match': None,
|
||||
# 'urlfilter-table': None, 'content-header-list': None}
|
||||
# wisp: None
|
||||
# web-filter-vbs-log: None
|
||||
# youtube-channel-filter: {'comment': None, 'channel-id': None}
|
||||
# override: {'profile': None, 'ovrd-scope': None, 'ovrd-dur-mode': None, 'profile-attribute': None,
|
||||
# 'ovrd-dur': None, 'profile-type': None, 'ovrd-user-group': None, 'ovrd-cookie': None}
|
||||
# ovrd-perm: None
|
||||
# mode: delete
|
||||
# web-content-log: None
|
||||
# web-invalid-domain-log: None
|
||||
# adom: root
|
||||
# web-filter-referer-log: None
|
||||
# inspection-mode: None
|
||||
# post-action: None
|
||||
# name: Ansible_Web_Filter_Profile
|
||||
# web-filter-command-block-log: None
|
||||
# web-filter-applet-log: None
|
||||
# web-ftgd-err-log: None
|
||||
# replacemsg-group: None
|
||||
# web-filter-jscript-log: None
|
||||
# web-filter-activex-log: None
|
||||
# web-filter-js-log: None
|
||||
# web-ftgd-quota-usage: None
|
||||
# web-filter-unknown-log: None
|
||||
# web-filter-cookie-log: None
|
||||
# youtube-channel-status: None
|
||||
# web-url-log: None
|
||||
# options: None
|
||||
# wisp-servers: None
|
||||
# wisp-algorithm: None
|
||||
##################################################
|
||||
##################################################
|
||||
# comment: Created by Ansible Module TEST
|
||||
# web-filter-command-block-log: enable
|
||||
# web-invalid-domain-log: enable
|
||||
# web-extended-all-action-log: enable
|
||||
# adom: root
|
||||
# ftgd-wf: {'rate-javascript-urls': None, 'quota': {'category': None, 'value': None, 'override-replacemsg': None,
|
||||
# 'duration': None, 'type': None, 'unit': None}, 'rate-image-urls': None, 'filters': {'category': None,
|
||||
# 'auth-usr-grp': None, 'log': None, 'warning-prompt': None, 'override-replacemsg': None, 'action': None,
|
||||
# 'warn-duration': None, 'warning-duration-type': None}, 'rate-css-urls': None, 'ovrd': None,
|
||||
# 'exempt-quota': None, 'max-quota-timeout': None, 'rate-crl-urls': None, 'options': None}
|
||||
# web-content-log: enable
|
||||
# web-filter-referer-log: enable
|
||||
# log-all-url: enable
|
||||
# extended-log: enable
|
||||
# inspection-mode: proxy
|
||||
# web-filter-cookie-removal-log: enable
|
||||
# post-action: block
|
||||
# web-filter-activex-log: enable
|
||||
# web-filter-cookie-log: enable
|
||||
# web: {'blacklist': None, 'log-search': None, 'keyword-match': None, 'urlfilter-table': None, 'bword-table': None,
|
||||
# 'safe-search': None, 'whitelist': None, 'content-header-list': None, 'youtube-restrict': None,
|
||||
# 'bword-threshold': None}
|
||||
# web-filter-applet-log: enable
|
||||
# web-ftgd-err-log: enable
|
||||
# replacemsg-group: None
|
||||
# web-filter-jscript-log: enable
|
||||
# web-ftgd-quota-usage: enable
|
||||
# url-extraction: {'status': None, 'server-fqdn': None, 'redirect-url': None, 'redirect-header': None,
|
||||
# 'redirect-no-content': None}
|
||||
# web-filter-js-log: enable
|
||||
# youtube-channel-filter: {'comment': None, 'channel-id': None}
|
||||
# name: Ansible_Web_Filter_Profile
|
||||
# wisp: enable
|
||||
# web-filter-vbs-log: enable
|
||||
# web-filter-unknown-log: enable
|
||||
# mode: set
|
||||
# youtube-channel-status: blacklist
|
||||
# override: {'profile': None, 'ovrd-user-group': None, 'ovrd-scope': None, 'ovrd-cookie': None,
|
||||
# 'ovrd-dur-mode': None, 'profile-attribute': None, 'ovrd-dur': None, 'profile-type': None}
|
||||
# web-url-log: enable
|
||||
# ovrd-perm: bannedword-override
|
||||
# https-replacemsg: None
|
||||
# options: js
|
||||
# wisp-servers: None
|
||||
# wisp-algorithm: auto-learning
|
||||
##################################################
|
||||
|
||||
# Test using fixture 1 #
|
||||
output = fmgr_secprof_web.fmgr_webfilter_profile_addsetdelete(fmg_instance, fixture_data[0]['paramgram_used'])
|
||||
assert output['raw_response']['status']['code'] == 0
|
||||
# Test using fixture 2 #
|
||||
output = fmgr_secprof_web.fmgr_webfilter_profile_addsetdelete(fmg_instance, fixture_data[1]['paramgram_used'])
|
||||
assert output['raw_response']['status']['code'] == 0
|
Loading…
Reference in a new issue