1# Copyright 2019 Fortinet, Inc.
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with Ansible.  If not, see <https://www.gnu.org/licenses/>.
15
16# Make coding more python3-ish
17from __future__ import (absolute_import, division, print_function)
18__metaclass__ = type
19
20import os
21import json
22import pytest
23from mock import ANY
24from ansible.module_utils.network.fortios.fortios import FortiOSHandler
25
26try:
27    from ansible.modules.network.fortios import fortios_system_global
28except ImportError:
29    pytest.skip("Could not load required modules for testing", allow_module_level=True)
30
31
32@pytest.fixture(autouse=True)
33def connection_mock(mocker):
34    connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_system_global.Connection')
35    return connection_class_mock
36
37
38fos_instance = FortiOSHandler(connection_mock)
39
40
41def test_system_global_creation(mocker):
42    schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
43
44    set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
45    set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
46
47    input_data = {
48        'username': 'admin',
49        'state': 'present',
50        'system_global': {
51            'admin_concurrent': 'enable',
52            'admin_console_timeout': '4',
53            'admin_https_pki_required': 'enable',
54            'admin_lockout_duration': '6',
55            'admin_lockout_threshold': '7',
56            'admin_login_max': '8',
57            'admin_maintainer': 'enable',
58            'admin_port': '10',
59            'admin_restrict_local': 'enable',
60            'admin_scp': 'enable',
61            'admin_server_cert': 'test_value_13',
62            'admin_sport': '14',
63            'admin_ssh_grace_time': '15',
64            'admin_ssh_password': 'enable',
65            'admin_ssh_port': '17',
66            'admin_ssh_v1': 'enable',
67            'admin_telnet_port': '19',
68            'admintimeout': '20',
69            'alias': 'test_value_21',
70            'allow_traffic_redirect': 'enable',
71            'anti_replay': 'disable',
72            'arp_max_entry': '24',
73            'asymroute': 'enable',
74            'auth_cert': 'test_value_26',
75            'auth_http_port': '27',
76            'auth_https_port': '28',
77            'auth_keepalive': 'enable',
78            'auth_session_limit': 'block-new',
79            'auto_auth_extension_device': 'enable',
80            'av_affinity': 'test_value_32',
81            'av_failopen': 'pass',
82            'av_failopen_session': 'enable',
83            'batch_cmdb': 'enable',
84            'block_session_timer': '36',
85            'br_fdb_max_entry': '37',
86            'cert_chain_max': '38',
87            'cfg_revert_timeout': '39',
88            'cfg_save': 'automatic',
89            'check_protocol_header': 'loose',
90            'check_reset_range': 'strict',
91            'cli_audit_log': 'enable',
92            'clt_cert_req': 'enable',
93            'compliance_check': 'enable',
94            'compliance_check_time': 'test_value_46',
95            'cpu_use_threshold': '47',
96            'csr_ca_attribute': 'enable',
97            'daily_restart': 'enable',
98            'device_identification_active_scan_delay': '50',
99            'device_idle_timeout': '51',
100            'dh_params': '1024',
101            'dnsproxy_worker_count': '53',
102            'dst': 'enable',
103            'endpoint_control_fds_access': 'enable',
104            'endpoint_control_portal_port': '56',
105            'failtime': '57',
106            'fds_statistics': 'enable',
107            'fds_statistics_period': '59',
108            'fgd_alert_subscription': 'advisory',
109            'fortiextender': 'enable',
110            'fortiextender_data_port': '62',
111            'fortiextender_vlan_mode': 'enable',
112            'fortiservice_port': '64',
113            'gui_certificates': 'enable',
114            'gui_custom_language': 'enable',
115            'gui_date_format': 'yyyy/MM/dd',
116            'gui_device_latitude': 'test_value_68',
117            'gui_device_longitude': 'test_value_69',
118            'gui_display_hostname': 'enable',
119            'gui_ipv6': 'enable',
120            'gui_lines_per_page': '72',
121            'gui_theme': 'green',
122            'gui_wireless_opensecurity': 'enable',
123            'honor_df': 'enable',
124            'hostname': 'myhostname76',
125            'igmp_state_limit': '77',
126            'interval': '78',
127            'ip_src_port_range': 'test_value_79',
128            'ips_affinity': 'test_value_80',
129            'ipsec_asic_offload': 'enable',
130            'ipsec_hmac_offload': 'enable',
131            'ipsec_soft_dec_async': 'enable',
132            'ipv6_accept_dad': '84',
133            'ipv6_allow_anycast_probe': 'enable',
134            'language': 'english',
135            'ldapconntimeout': '87',
136            'lldp_transmission': 'enable',
137            'log_ssl_connection': 'enable',
138            'log_uuid': 'disable',
139            'login_timestamp': 'enable',
140            'long_vdom_name': 'enable',
141            'management_vdom': 'test_value_93',
142            'max_dlpstat_memory': '94',
143            'max_route_cache_size': '95',
144            'mc_ttl_notchange': 'enable',
145            'memory_use_threshold_extreme': '97',
146            'memory_use_threshold_green': '98',
147            'memory_use_threshold_red': '99',
148            'miglog_affinity': 'test_value_100',
149            'miglogd_children': '101',
150            'multi_factor_authentication': 'optional',
151            'multicast_forward': 'enable',
152            'ndp_max_entry': '104',
153            'per_user_bwl': 'enable',
154            'policy_auth_concurrent': '106',
155            'post_login_banner': 'disable',
156            'pre_login_banner': 'enable',
157            'private_data_encryption': 'disable',
158            'proxy_auth_lifetime': 'enable',
159            'proxy_auth_lifetime_timeout': '111',
160            'proxy_auth_timeout': '112',
161            'proxy_cipher_hardware_acceleration': 'disable',
162            'proxy_kxp_hardware_acceleration': 'disable',
163            'proxy_re_authentication_mode': 'session',
164            'proxy_worker_count': '116',
165            'radius_port': '117',
166            'reboot_upon_config_restore': 'enable',
167            'refresh': '119',
168            'remoteauthtimeout': '120',
169            'reset_sessionless_tcp': 'enable',
170            'restart_time': 'test_value_122',
171            'revision_backup_on_logout': 'enable',
172            'revision_image_auto_backup': 'enable',
173            'scanunit_count': '125',
174            'security_rating_result_submission': 'enable',
175            'security_rating_run_on_schedule': 'enable',
176            'send_pmtu_icmp': 'enable',
177            'snat_route_change': 'enable',
178            'special_file_23_support': 'disable',
179            'ssd_trim_date': '131',
180            'ssd_trim_freq': 'never',
181            'ssd_trim_hour': '133',
182            'ssd_trim_min': '134',
183            'ssd_trim_weekday': 'sunday',
184            'ssh_cbc_cipher': 'enable',
185            'ssh_hmac_md5': 'enable',
186            'ssh_kex_sha1': 'enable',
187            'ssl_min_proto_version': 'SSLv3',
188            'ssl_static_key_ciphers': 'enable',
189            'sslvpn_cipher_hardware_acceleration': 'enable',
190            'sslvpn_kxp_hardware_acceleration': 'enable',
191            'sslvpn_max_worker_count': '143',
192            'sslvpn_plugin_version_check': 'enable',
193            'strict_dirty_session_check': 'enable',
194            'strong_crypto': 'enable',
195            'switch_controller': 'disable',
196            'switch_controller_reserved_network': 'test_value_148',
197            'sys_perf_log_interval': '149',
198            'tcp_halfclose_timer': '150',
199            'tcp_halfopen_timer': '151',
200            'tcp_option': 'enable',
201            'tcp_timewait_timer': '153',
202            'tftp': 'enable',
203            'timezone': '01',
204            'tp_mc_skip_policy': 'enable',
205            'traffic_priority': 'tos',
206            'traffic_priority_level': 'low',
207            'two_factor_email_expiry': '159',
208            'two_factor_fac_expiry': '160',
209            'two_factor_ftk_expiry': '161',
210            'two_factor_ftm_expiry': '162',
211            'two_factor_sms_expiry': '163',
212            'udp_idle_timer': '164',
213            'user_server_cert': 'test_value_165',
214            'vdom_admin': 'enable',
215            'vip_arp_range': 'unlimited',
216            'virtual_server_count': '168',
217            'virtual_server_hardware_acceleration': 'disable',
218            'wad_affinity': 'test_value_170',
219            'wad_csvc_cs_count': '171',
220            'wad_csvc_db_count': '172',
221            'wad_source_affinity': 'disable',
222            'wad_worker_count': '174',
223            'wifi_ca_certificate': 'test_value_175',
224            'wifi_certificate': 'test_value_176',
225            'wimax_4g_usb': 'enable',
226            'wireless_controller': 'enable',
227            'wireless_controller_port': '179'
228        },
229        'vdom': 'root'}
230
231    is_error, changed, response = fortios_system_global.fortios_system(input_data, fos_instance)
232
233    expected_data = {
234        'admin-concurrent': 'enable',
235        'admin-console-timeout': '4',
236        'admin-https-pki-required': 'enable',
237        'admin-lockout-duration': '6',
238        'admin-lockout-threshold': '7',
239        'admin-login-max': '8',
240        'admin-maintainer': 'enable',
241        'admin-port': '10',
242        'admin-restrict-local': 'enable',
243        'admin-scp': 'enable',
244        'admin-server-cert': 'test_value_13',
245        'admin-sport': '14',
246        'admin-ssh-grace-time': '15',
247        'admin-ssh-password': 'enable',
248        'admin-ssh-port': '17',
249        'admin-ssh-v1': 'enable',
250        'admin-telnet-port': '19',
251        'admintimeout': '20',
252        'alias': 'test_value_21',
253        'allow-traffic-redirect': 'enable',
254        'anti-replay': 'disable',
255        'arp-max-entry': '24',
256        'asymroute': 'enable',
257        'auth-cert': 'test_value_26',
258        'auth-http-port': '27',
259        'auth-https-port': '28',
260        'auth-keepalive': 'enable',
261        'auth-session-limit': 'block-new',
262        'auto-auth-extension-device': 'enable',
263        'av-affinity': 'test_value_32',
264        'av-failopen': 'pass',
265        'av-failopen-session': 'enable',
266        'batch-cmdb': 'enable',
267        'block-session-timer': '36',
268        'br-fdb-max-entry': '37',
269        'cert-chain-max': '38',
270        'cfg-revert-timeout': '39',
271        'cfg-save': 'automatic',
272        'check-protocol-header': 'loose',
273        'check-reset-range': 'strict',
274        'cli-audit-log': 'enable',
275        'clt-cert-req': 'enable',
276        'compliance-check': 'enable',
277        'compliance-check-time': 'test_value_46',
278        'cpu-use-threshold': '47',
279        'csr-ca-attribute': 'enable',
280        'daily-restart': 'enable',
281        'device-identification-active-scan-delay': '50',
282        'device-idle-timeout': '51',
283        'dh-params': '1024',
284        'dnsproxy-worker-count': '53',
285        'dst': 'enable',
286        'endpoint-control-fds-access': 'enable',
287        'endpoint-control-portal-port': '56',
288        'failtime': '57',
289        'fds-statistics': 'enable',
290        'fds-statistics-period': '59',
291        'fgd-alert-subscription': 'advisory',
292        'fortiextender': 'enable',
293        'fortiextender-data-port': '62',
294        'fortiextender-vlan-mode': 'enable',
295        'fortiservice-port': '64',
296        'gui-certificates': 'enable',
297        'gui-custom-language': 'enable',
298        'gui-date-format': 'yyyy/MM/dd',
299        'gui-device-latitude': 'test_value_68',
300        'gui-device-longitude': 'test_value_69',
301        'gui-display-hostname': 'enable',
302        'gui-ipv6': 'enable',
303        'gui-lines-per-page': '72',
304        'gui-theme': 'green',
305        'gui-wireless-opensecurity': 'enable',
306        'honor-df': 'enable',
307        'hostname': 'myhostname76',
308        'igmp-state-limit': '77',
309        'interval': '78',
310        'ip-src-port-range': 'test_value_79',
311        'ips-affinity': 'test_value_80',
312        'ipsec-asic-offload': 'enable',
313        'ipsec-hmac-offload': 'enable',
314        'ipsec-soft-dec-async': 'enable',
315        'ipv6-accept-dad': '84',
316        'ipv6-allow-anycast-probe': 'enable',
317        'language': 'english',
318        'ldapconntimeout': '87',
319        'lldp-transmission': 'enable',
320        'log-ssl-connection': 'enable',
321        'log-uuid': 'disable',
322        'login-timestamp': 'enable',
323        'long-vdom-name': 'enable',
324        'management-vdom': 'test_value_93',
325        'max-dlpstat-memory': '94',
326        'max-route-cache-size': '95',
327        'mc-ttl-notchange': 'enable',
328        'memory-use-threshold-extreme': '97',
329        'memory-use-threshold-green': '98',
330        'memory-use-threshold-red': '99',
331        'miglog-affinity': 'test_value_100',
332        'miglogd-children': '101',
333        'multi-factor-authentication': 'optional',
334        'multicast-forward': 'enable',
335        'ndp-max-entry': '104',
336        'per-user-bwl': 'enable',
337        'policy-auth-concurrent': '106',
338        'post-login-banner': 'disable',
339        'pre-login-banner': 'enable',
340        'private-data-encryption': 'disable',
341        'proxy-auth-lifetime': 'enable',
342        'proxy-auth-lifetime-timeout': '111',
343        'proxy-auth-timeout': '112',
344        'proxy-cipher-hardware-acceleration': 'disable',
345        'proxy-kxp-hardware-acceleration': 'disable',
346        'proxy-re-authentication-mode': 'session',
347        'proxy-worker-count': '116',
348        'radius-port': '117',
349        'reboot-upon-config-restore': 'enable',
350        'refresh': '119',
351        'remoteauthtimeout': '120',
352        'reset-sessionless-tcp': 'enable',
353        'restart-time': 'test_value_122',
354        'revision-backup-on-logout': 'enable',
355        'revision-image-auto-backup': 'enable',
356        'scanunit-count': '125',
357        'security-rating-result-submission': 'enable',
358        'security-rating-run-on-schedule': 'enable',
359        'send-pmtu-icmp': 'enable',
360        'snat-route-change': 'enable',
361        'special-file-23-support': 'disable',
362        'ssd-trim-date': '131',
363        'ssd-trim-freq': 'never',
364        'ssd-trim-hour': '133',
365        'ssd-trim-min': '134',
366        'ssd-trim-weekday': 'sunday',
367        'ssh-cbc-cipher': 'enable',
368        'ssh-hmac-md5': 'enable',
369        'ssh-kex-sha1': 'enable',
370        'ssl-min-proto-version': 'SSLv3',
371        'ssl-static-key-ciphers': 'enable',
372        'sslvpn-cipher-hardware-acceleration': 'enable',
373        'sslvpn-kxp-hardware-acceleration': 'enable',
374        'sslvpn-max-worker-count': '143',
375        'sslvpn-plugin-version-check': 'enable',
376        'strict-dirty-session-check': 'enable',
377        'strong-crypto': 'enable',
378        'switch-controller': 'disable',
379        'switch-controller-reserved-network': 'test_value_148',
380        'sys-perf-log-interval': '149',
381        'tcp-halfclose-timer': '150',
382        'tcp-halfopen-timer': '151',
383        'tcp-option': 'enable',
384        'tcp-timewait-timer': '153',
385        'tftp': 'enable',
386                'timezone': '01',
387                'tp-mc-skip-policy': 'enable',
388                'traffic-priority': 'tos',
389                'traffic-priority-level': 'low',
390                'two-factor-email-expiry': '159',
391                'two-factor-fac-expiry': '160',
392                'two-factor-ftk-expiry': '161',
393                'two-factor-ftm-expiry': '162',
394                'two-factor-sms-expiry': '163',
395                'udp-idle-timer': '164',
396                'user-server-cert': 'test_value_165',
397                'vdom-admin': 'enable',
398                'vip-arp-range': 'unlimited',
399                'virtual-server-count': '168',
400                'virtual-server-hardware-acceleration': 'disable',
401                'wad-affinity': 'test_value_170',
402                'wad-csvc-cs-count': '171',
403                'wad-csvc-db-count': '172',
404                'wad-source-affinity': 'disable',
405                'wad-worker-count': '174',
406                'wifi-ca-certificate': 'test_value_175',
407                'wifi-certificate': 'test_value_176',
408                'wimax-4g-usb': 'enable',
409                'wireless-controller': 'enable',
410                'wireless-controller-port': '179'
411    }
412
413    set_method_mock.assert_called_with('system', 'global', data=expected_data, vdom='root')
414    schema_method_mock.assert_not_called()
415    assert not is_error
416    assert changed
417    assert response['status'] == 'success'
418    assert response['http_status'] == 200
419
420
421def test_system_global_creation_fails(mocker):
422    schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
423
424    set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
425    set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
426
427    input_data = {
428        'username': 'admin',
429        'state': 'present',
430        'system_global': {
431            'admin_concurrent': 'enable',
432            'admin_console_timeout': '4',
433            'admin_https_pki_required': 'enable',
434            'admin_lockout_duration': '6',
435            'admin_lockout_threshold': '7',
436            'admin_login_max': '8',
437            'admin_maintainer': 'enable',
438            'admin_port': '10',
439            'admin_restrict_local': 'enable',
440            'admin_scp': 'enable',
441            'admin_server_cert': 'test_value_13',
442            'admin_sport': '14',
443            'admin_ssh_grace_time': '15',
444            'admin_ssh_password': 'enable',
445            'admin_ssh_port': '17',
446            'admin_ssh_v1': 'enable',
447            'admin_telnet_port': '19',
448            'admintimeout': '20',
449            'alias': 'test_value_21',
450            'allow_traffic_redirect': 'enable',
451            'anti_replay': 'disable',
452            'arp_max_entry': '24',
453            'asymroute': 'enable',
454            'auth_cert': 'test_value_26',
455            'auth_http_port': '27',
456            'auth_https_port': '28',
457            'auth_keepalive': 'enable',
458            'auth_session_limit': 'block-new',
459            'auto_auth_extension_device': 'enable',
460            'av_affinity': 'test_value_32',
461            'av_failopen': 'pass',
462            'av_failopen_session': 'enable',
463            'batch_cmdb': 'enable',
464            'block_session_timer': '36',
465            'br_fdb_max_entry': '37',
466            'cert_chain_max': '38',
467            'cfg_revert_timeout': '39',
468            'cfg_save': 'automatic',
469            'check_protocol_header': 'loose',
470            'check_reset_range': 'strict',
471            'cli_audit_log': 'enable',
472            'clt_cert_req': 'enable',
473            'compliance_check': 'enable',
474            'compliance_check_time': 'test_value_46',
475            'cpu_use_threshold': '47',
476            'csr_ca_attribute': 'enable',
477            'daily_restart': 'enable',
478            'device_identification_active_scan_delay': '50',
479            'device_idle_timeout': '51',
480            'dh_params': '1024',
481            'dnsproxy_worker_count': '53',
482            'dst': 'enable',
483            'endpoint_control_fds_access': 'enable',
484            'endpoint_control_portal_port': '56',
485            'failtime': '57',
486            'fds_statistics': 'enable',
487            'fds_statistics_period': '59',
488            'fgd_alert_subscription': 'advisory',
489            'fortiextender': 'enable',
490            'fortiextender_data_port': '62',
491            'fortiextender_vlan_mode': 'enable',
492            'fortiservice_port': '64',
493            'gui_certificates': 'enable',
494            'gui_custom_language': 'enable',
495            'gui_date_format': 'yyyy/MM/dd',
496            'gui_device_latitude': 'test_value_68',
497            'gui_device_longitude': 'test_value_69',
498            'gui_display_hostname': 'enable',
499            'gui_ipv6': 'enable',
500            'gui_lines_per_page': '72',
501            'gui_theme': 'green',
502            'gui_wireless_opensecurity': 'enable',
503            'honor_df': 'enable',
504            'hostname': 'myhostname76',
505            'igmp_state_limit': '77',
506            'interval': '78',
507            'ip_src_port_range': 'test_value_79',
508            'ips_affinity': 'test_value_80',
509            'ipsec_asic_offload': 'enable',
510            'ipsec_hmac_offload': 'enable',
511            'ipsec_soft_dec_async': 'enable',
512            'ipv6_accept_dad': '84',
513            'ipv6_allow_anycast_probe': 'enable',
514            'language': 'english',
515            'ldapconntimeout': '87',
516            'lldp_transmission': 'enable',
517            'log_ssl_connection': 'enable',
518            'log_uuid': 'disable',
519            'login_timestamp': 'enable',
520            'long_vdom_name': 'enable',
521            'management_vdom': 'test_value_93',
522            'max_dlpstat_memory': '94',
523            'max_route_cache_size': '95',
524            'mc_ttl_notchange': 'enable',
525            'memory_use_threshold_extreme': '97',
526            'memory_use_threshold_green': '98',
527            'memory_use_threshold_red': '99',
528            'miglog_affinity': 'test_value_100',
529            'miglogd_children': '101',
530            'multi_factor_authentication': 'optional',
531            'multicast_forward': 'enable',
532            'ndp_max_entry': '104',
533            'per_user_bwl': 'enable',
534            'policy_auth_concurrent': '106',
535            'post_login_banner': 'disable',
536            'pre_login_banner': 'enable',
537            'private_data_encryption': 'disable',
538            'proxy_auth_lifetime': 'enable',
539            'proxy_auth_lifetime_timeout': '111',
540            'proxy_auth_timeout': '112',
541            'proxy_cipher_hardware_acceleration': 'disable',
542            'proxy_kxp_hardware_acceleration': 'disable',
543            'proxy_re_authentication_mode': 'session',
544            'proxy_worker_count': '116',
545            'radius_port': '117',
546            'reboot_upon_config_restore': 'enable',
547            'refresh': '119',
548            'remoteauthtimeout': '120',
549            'reset_sessionless_tcp': 'enable',
550            'restart_time': 'test_value_122',
551            'revision_backup_on_logout': 'enable',
552            'revision_image_auto_backup': 'enable',
553            'scanunit_count': '125',
554            'security_rating_result_submission': 'enable',
555            'security_rating_run_on_schedule': 'enable',
556            'send_pmtu_icmp': 'enable',
557            'snat_route_change': 'enable',
558            'special_file_23_support': 'disable',
559            'ssd_trim_date': '131',
560            'ssd_trim_freq': 'never',
561            'ssd_trim_hour': '133',
562            'ssd_trim_min': '134',
563            'ssd_trim_weekday': 'sunday',
564            'ssh_cbc_cipher': 'enable',
565            'ssh_hmac_md5': 'enable',
566            'ssh_kex_sha1': 'enable',
567            'ssl_min_proto_version': 'SSLv3',
568            'ssl_static_key_ciphers': 'enable',
569            'sslvpn_cipher_hardware_acceleration': 'enable',
570            'sslvpn_kxp_hardware_acceleration': 'enable',
571            'sslvpn_max_worker_count': '143',
572            'sslvpn_plugin_version_check': 'enable',
573            'strict_dirty_session_check': 'enable',
574            'strong_crypto': 'enable',
575            'switch_controller': 'disable',
576            'switch_controller_reserved_network': 'test_value_148',
577            'sys_perf_log_interval': '149',
578            'tcp_halfclose_timer': '150',
579            'tcp_halfopen_timer': '151',
580            'tcp_option': 'enable',
581            'tcp_timewait_timer': '153',
582            'tftp': 'enable',
583            'timezone': '01',
584            'tp_mc_skip_policy': 'enable',
585            'traffic_priority': 'tos',
586            'traffic_priority_level': 'low',
587            'two_factor_email_expiry': '159',
588            'two_factor_fac_expiry': '160',
589            'two_factor_ftk_expiry': '161',
590            'two_factor_ftm_expiry': '162',
591            'two_factor_sms_expiry': '163',
592            'udp_idle_timer': '164',
593            'user_server_cert': 'test_value_165',
594            'vdom_admin': 'enable',
595            'vip_arp_range': 'unlimited',
596            'virtual_server_count': '168',
597            'virtual_server_hardware_acceleration': 'disable',
598            'wad_affinity': 'test_value_170',
599            'wad_csvc_cs_count': '171',
600            'wad_csvc_db_count': '172',
601            'wad_source_affinity': 'disable',
602            'wad_worker_count': '174',
603            'wifi_ca_certificate': 'test_value_175',
604            'wifi_certificate': 'test_value_176',
605            'wimax_4g_usb': 'enable',
606            'wireless_controller': 'enable',
607            'wireless_controller_port': '179'
608        },
609        'vdom': 'root'}
610
611    is_error, changed, response = fortios_system_global.fortios_system(input_data, fos_instance)
612
613    expected_data = {
614        'admin-concurrent': 'enable',
615        'admin-console-timeout': '4',
616        'admin-https-pki-required': 'enable',
617        'admin-lockout-duration': '6',
618        'admin-lockout-threshold': '7',
619        'admin-login-max': '8',
620        'admin-maintainer': 'enable',
621        'admin-port': '10',
622        'admin-restrict-local': 'enable',
623        'admin-scp': 'enable',
624        'admin-server-cert': 'test_value_13',
625        'admin-sport': '14',
626        'admin-ssh-grace-time': '15',
627        'admin-ssh-password': 'enable',
628        'admin-ssh-port': '17',
629        'admin-ssh-v1': 'enable',
630        'admin-telnet-port': '19',
631        'admintimeout': '20',
632        'alias': 'test_value_21',
633        'allow-traffic-redirect': 'enable',
634        'anti-replay': 'disable',
635        'arp-max-entry': '24',
636        'asymroute': 'enable',
637        'auth-cert': 'test_value_26',
638        'auth-http-port': '27',
639        'auth-https-port': '28',
640        'auth-keepalive': 'enable',
641        'auth-session-limit': 'block-new',
642        'auto-auth-extension-device': 'enable',
643        'av-affinity': 'test_value_32',
644        'av-failopen': 'pass',
645        'av-failopen-session': 'enable',
646        'batch-cmdb': 'enable',
647        'block-session-timer': '36',
648        'br-fdb-max-entry': '37',
649        'cert-chain-max': '38',
650        'cfg-revert-timeout': '39',
651        'cfg-save': 'automatic',
652        'check-protocol-header': 'loose',
653        'check-reset-range': 'strict',
654        'cli-audit-log': 'enable',
655        'clt-cert-req': 'enable',
656        'compliance-check': 'enable',
657        'compliance-check-time': 'test_value_46',
658        'cpu-use-threshold': '47',
659        'csr-ca-attribute': 'enable',
660        'daily-restart': 'enable',
661        'device-identification-active-scan-delay': '50',
662        'device-idle-timeout': '51',
663        'dh-params': '1024',
664        'dnsproxy-worker-count': '53',
665        'dst': 'enable',
666        'endpoint-control-fds-access': 'enable',
667        'endpoint-control-portal-port': '56',
668        'failtime': '57',
669        'fds-statistics': 'enable',
670        'fds-statistics-period': '59',
671        'fgd-alert-subscription': 'advisory',
672        'fortiextender': 'enable',
673        'fortiextender-data-port': '62',
674        'fortiextender-vlan-mode': 'enable',
675        'fortiservice-port': '64',
676        'gui-certificates': 'enable',
677        'gui-custom-language': 'enable',
678        'gui-date-format': 'yyyy/MM/dd',
679        'gui-device-latitude': 'test_value_68',
680        'gui-device-longitude': 'test_value_69',
681        'gui-display-hostname': 'enable',
682        'gui-ipv6': 'enable',
683        'gui-lines-per-page': '72',
684        'gui-theme': 'green',
685        'gui-wireless-opensecurity': 'enable',
686        'honor-df': 'enable',
687        'hostname': 'myhostname76',
688        'igmp-state-limit': '77',
689        'interval': '78',
690        'ip-src-port-range': 'test_value_79',
691        'ips-affinity': 'test_value_80',
692        'ipsec-asic-offload': 'enable',
693        'ipsec-hmac-offload': 'enable',
694        'ipsec-soft-dec-async': 'enable',
695        'ipv6-accept-dad': '84',
696        'ipv6-allow-anycast-probe': 'enable',
697        'language': 'english',
698        'ldapconntimeout': '87',
699        'lldp-transmission': 'enable',
700        'log-ssl-connection': 'enable',
701        'log-uuid': 'disable',
702        'login-timestamp': 'enable',
703        'long-vdom-name': 'enable',
704        'management-vdom': 'test_value_93',
705        'max-dlpstat-memory': '94',
706        'max-route-cache-size': '95',
707        'mc-ttl-notchange': 'enable',
708        'memory-use-threshold-extreme': '97',
709        'memory-use-threshold-green': '98',
710        'memory-use-threshold-red': '99',
711        'miglog-affinity': 'test_value_100',
712        'miglogd-children': '101',
713        'multi-factor-authentication': 'optional',
714        'multicast-forward': 'enable',
715        'ndp-max-entry': '104',
716        'per-user-bwl': 'enable',
717        'policy-auth-concurrent': '106',
718        'post-login-banner': 'disable',
719        'pre-login-banner': 'enable',
720        'private-data-encryption': 'disable',
721        'proxy-auth-lifetime': 'enable',
722        'proxy-auth-lifetime-timeout': '111',
723        'proxy-auth-timeout': '112',
724        'proxy-cipher-hardware-acceleration': 'disable',
725        'proxy-kxp-hardware-acceleration': 'disable',
726        'proxy-re-authentication-mode': 'session',
727        'proxy-worker-count': '116',
728        'radius-port': '117',
729        'reboot-upon-config-restore': 'enable',
730        'refresh': '119',
731        'remoteauthtimeout': '120',
732        'reset-sessionless-tcp': 'enable',
733        'restart-time': 'test_value_122',
734        'revision-backup-on-logout': 'enable',
735        'revision-image-auto-backup': 'enable',
736        'scanunit-count': '125',
737        'security-rating-result-submission': 'enable',
738        'security-rating-run-on-schedule': 'enable',
739        'send-pmtu-icmp': 'enable',
740        'snat-route-change': 'enable',
741        'special-file-23-support': 'disable',
742        'ssd-trim-date': '131',
743        'ssd-trim-freq': 'never',
744        'ssd-trim-hour': '133',
745        'ssd-trim-min': '134',
746        'ssd-trim-weekday': 'sunday',
747        'ssh-cbc-cipher': 'enable',
748        'ssh-hmac-md5': 'enable',
749        'ssh-kex-sha1': 'enable',
750        'ssl-min-proto-version': 'SSLv3',
751        'ssl-static-key-ciphers': 'enable',
752        'sslvpn-cipher-hardware-acceleration': 'enable',
753        'sslvpn-kxp-hardware-acceleration': 'enable',
754        'sslvpn-max-worker-count': '143',
755        'sslvpn-plugin-version-check': 'enable',
756        'strict-dirty-session-check': 'enable',
757        'strong-crypto': 'enable',
758        'switch-controller': 'disable',
759        'switch-controller-reserved-network': 'test_value_148',
760        'sys-perf-log-interval': '149',
761        'tcp-halfclose-timer': '150',
762        'tcp-halfopen-timer': '151',
763        'tcp-option': 'enable',
764        'tcp-timewait-timer': '153',
765        'tftp': 'enable',
766                'timezone': '01',
767                'tp-mc-skip-policy': 'enable',
768                'traffic-priority': 'tos',
769                'traffic-priority-level': 'low',
770                'two-factor-email-expiry': '159',
771                'two-factor-fac-expiry': '160',
772                'two-factor-ftk-expiry': '161',
773                'two-factor-ftm-expiry': '162',
774                'two-factor-sms-expiry': '163',
775                'udp-idle-timer': '164',
776                'user-server-cert': 'test_value_165',
777                'vdom-admin': 'enable',
778                'vip-arp-range': 'unlimited',
779                'virtual-server-count': '168',
780                'virtual-server-hardware-acceleration': 'disable',
781                'wad-affinity': 'test_value_170',
782                'wad-csvc-cs-count': '171',
783                'wad-csvc-db-count': '172',
784                'wad-source-affinity': 'disable',
785                'wad-worker-count': '174',
786                'wifi-ca-certificate': 'test_value_175',
787                'wifi-certificate': 'test_value_176',
788                'wimax-4g-usb': 'enable',
789                'wireless-controller': 'enable',
790                'wireless-controller-port': '179'
791    }
792
793    set_method_mock.assert_called_with('system', 'global', data=expected_data, vdom='root')
794    schema_method_mock.assert_not_called()
795    assert is_error
796    assert not changed
797    assert response['status'] == 'error'
798    assert response['http_status'] == 500
799
800
801def test_system_global_idempotent(mocker):
802    schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
803
804    set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
805    set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
806
807    input_data = {
808        'username': 'admin',
809        'state': 'present',
810        'system_global': {
811            'admin_concurrent': 'enable',
812            'admin_console_timeout': '4',
813            'admin_https_pki_required': 'enable',
814            'admin_lockout_duration': '6',
815            'admin_lockout_threshold': '7',
816            'admin_login_max': '8',
817            'admin_maintainer': 'enable',
818            'admin_port': '10',
819            'admin_restrict_local': 'enable',
820            'admin_scp': 'enable',
821            'admin_server_cert': 'test_value_13',
822            'admin_sport': '14',
823            'admin_ssh_grace_time': '15',
824            'admin_ssh_password': 'enable',
825            'admin_ssh_port': '17',
826            'admin_ssh_v1': 'enable',
827            'admin_telnet_port': '19',
828            'admintimeout': '20',
829            'alias': 'test_value_21',
830            'allow_traffic_redirect': 'enable',
831            'anti_replay': 'disable',
832            'arp_max_entry': '24',
833            'asymroute': 'enable',
834            'auth_cert': 'test_value_26',
835            'auth_http_port': '27',
836            'auth_https_port': '28',
837            'auth_keepalive': 'enable',
838            'auth_session_limit': 'block-new',
839            'auto_auth_extension_device': 'enable',
840            'av_affinity': 'test_value_32',
841            'av_failopen': 'pass',
842            'av_failopen_session': 'enable',
843            'batch_cmdb': 'enable',
844            'block_session_timer': '36',
845            'br_fdb_max_entry': '37',
846            'cert_chain_max': '38',
847            'cfg_revert_timeout': '39',
848            'cfg_save': 'automatic',
849            'check_protocol_header': 'loose',
850            'check_reset_range': 'strict',
851            'cli_audit_log': 'enable',
852            'clt_cert_req': 'enable',
853            'compliance_check': 'enable',
854            'compliance_check_time': 'test_value_46',
855            'cpu_use_threshold': '47',
856            'csr_ca_attribute': 'enable',
857            'daily_restart': 'enable',
858            'device_identification_active_scan_delay': '50',
859            'device_idle_timeout': '51',
860            'dh_params': '1024',
861            'dnsproxy_worker_count': '53',
862            'dst': 'enable',
863            'endpoint_control_fds_access': 'enable',
864            'endpoint_control_portal_port': '56',
865            'failtime': '57',
866            'fds_statistics': 'enable',
867            'fds_statistics_period': '59',
868            'fgd_alert_subscription': 'advisory',
869            'fortiextender': 'enable',
870            'fortiextender_data_port': '62',
871            'fortiextender_vlan_mode': 'enable',
872            'fortiservice_port': '64',
873            'gui_certificates': 'enable',
874            'gui_custom_language': 'enable',
875            'gui_date_format': 'yyyy/MM/dd',
876            'gui_device_latitude': 'test_value_68',
877            'gui_device_longitude': 'test_value_69',
878            'gui_display_hostname': 'enable',
879            'gui_ipv6': 'enable',
880            'gui_lines_per_page': '72',
881            'gui_theme': 'green',
882            'gui_wireless_opensecurity': 'enable',
883            'honor_df': 'enable',
884            'hostname': 'myhostname76',
885            'igmp_state_limit': '77',
886            'interval': '78',
887            'ip_src_port_range': 'test_value_79',
888            'ips_affinity': 'test_value_80',
889            'ipsec_asic_offload': 'enable',
890            'ipsec_hmac_offload': 'enable',
891            'ipsec_soft_dec_async': 'enable',
892            'ipv6_accept_dad': '84',
893            'ipv6_allow_anycast_probe': 'enable',
894            'language': 'english',
895            'ldapconntimeout': '87',
896            'lldp_transmission': 'enable',
897            'log_ssl_connection': 'enable',
898            'log_uuid': 'disable',
899            'login_timestamp': 'enable',
900            'long_vdom_name': 'enable',
901            'management_vdom': 'test_value_93',
902            'max_dlpstat_memory': '94',
903            'max_route_cache_size': '95',
904            'mc_ttl_notchange': 'enable',
905            'memory_use_threshold_extreme': '97',
906            'memory_use_threshold_green': '98',
907            'memory_use_threshold_red': '99',
908            'miglog_affinity': 'test_value_100',
909            'miglogd_children': '101',
910            'multi_factor_authentication': 'optional',
911            'multicast_forward': 'enable',
912            'ndp_max_entry': '104',
913            'per_user_bwl': 'enable',
914            'policy_auth_concurrent': '106',
915            'post_login_banner': 'disable',
916            'pre_login_banner': 'enable',
917            'private_data_encryption': 'disable',
918            'proxy_auth_lifetime': 'enable',
919            'proxy_auth_lifetime_timeout': '111',
920            'proxy_auth_timeout': '112',
921            'proxy_cipher_hardware_acceleration': 'disable',
922            'proxy_kxp_hardware_acceleration': 'disable',
923            'proxy_re_authentication_mode': 'session',
924            'proxy_worker_count': '116',
925            'radius_port': '117',
926            'reboot_upon_config_restore': 'enable',
927            'refresh': '119',
928            'remoteauthtimeout': '120',
929            'reset_sessionless_tcp': 'enable',
930            'restart_time': 'test_value_122',
931            'revision_backup_on_logout': 'enable',
932            'revision_image_auto_backup': 'enable',
933            'scanunit_count': '125',
934            'security_rating_result_submission': 'enable',
935            'security_rating_run_on_schedule': 'enable',
936            'send_pmtu_icmp': 'enable',
937            'snat_route_change': 'enable',
938            'special_file_23_support': 'disable',
939            'ssd_trim_date': '131',
940            'ssd_trim_freq': 'never',
941            'ssd_trim_hour': '133',
942            'ssd_trim_min': '134',
943            'ssd_trim_weekday': 'sunday',
944            'ssh_cbc_cipher': 'enable',
945            'ssh_hmac_md5': 'enable',
946            'ssh_kex_sha1': 'enable',
947            'ssl_min_proto_version': 'SSLv3',
948            'ssl_static_key_ciphers': 'enable',
949            'sslvpn_cipher_hardware_acceleration': 'enable',
950            'sslvpn_kxp_hardware_acceleration': 'enable',
951            'sslvpn_max_worker_count': '143',
952            'sslvpn_plugin_version_check': 'enable',
953            'strict_dirty_session_check': 'enable',
954            'strong_crypto': 'enable',
955            'switch_controller': 'disable',
956            'switch_controller_reserved_network': 'test_value_148',
957            'sys_perf_log_interval': '149',
958            'tcp_halfclose_timer': '150',
959            'tcp_halfopen_timer': '151',
960            'tcp_option': 'enable',
961            'tcp_timewait_timer': '153',
962            'tftp': 'enable',
963            'timezone': '01',
964            'tp_mc_skip_policy': 'enable',
965            'traffic_priority': 'tos',
966            'traffic_priority_level': 'low',
967            'two_factor_email_expiry': '159',
968            'two_factor_fac_expiry': '160',
969            'two_factor_ftk_expiry': '161',
970            'two_factor_ftm_expiry': '162',
971            'two_factor_sms_expiry': '163',
972            'udp_idle_timer': '164',
973            'user_server_cert': 'test_value_165',
974            'vdom_admin': 'enable',
975            'vip_arp_range': 'unlimited',
976            'virtual_server_count': '168',
977            'virtual_server_hardware_acceleration': 'disable',
978            'wad_affinity': 'test_value_170',
979            'wad_csvc_cs_count': '171',
980            'wad_csvc_db_count': '172',
981            'wad_source_affinity': 'disable',
982            'wad_worker_count': '174',
983            'wifi_ca_certificate': 'test_value_175',
984            'wifi_certificate': 'test_value_176',
985            'wimax_4g_usb': 'enable',
986            'wireless_controller': 'enable',
987            'wireless_controller_port': '179'
988        },
989        'vdom': 'root'}
990
991    is_error, changed, response = fortios_system_global.fortios_system(input_data, fos_instance)
992
993    expected_data = {
994        'admin-concurrent': 'enable',
995        'admin-console-timeout': '4',
996        'admin-https-pki-required': 'enable',
997        'admin-lockout-duration': '6',
998        'admin-lockout-threshold': '7',
999        'admin-login-max': '8',
1000        'admin-maintainer': 'enable',
1001        'admin-port': '10',
1002        'admin-restrict-local': 'enable',
1003        'admin-scp': 'enable',
1004        'admin-server-cert': 'test_value_13',
1005        'admin-sport': '14',
1006        'admin-ssh-grace-time': '15',
1007        'admin-ssh-password': 'enable',
1008        'admin-ssh-port': '17',
1009        'admin-ssh-v1': 'enable',
1010        'admin-telnet-port': '19',
1011        'admintimeout': '20',
1012        'alias': 'test_value_21',
1013        'allow-traffic-redirect': 'enable',
1014        'anti-replay': 'disable',
1015        'arp-max-entry': '24',
1016        'asymroute': 'enable',
1017        'auth-cert': 'test_value_26',
1018        'auth-http-port': '27',
1019        'auth-https-port': '28',
1020        'auth-keepalive': 'enable',
1021        'auth-session-limit': 'block-new',
1022        'auto-auth-extension-device': 'enable',
1023        'av-affinity': 'test_value_32',
1024        'av-failopen': 'pass',
1025        'av-failopen-session': 'enable',
1026        'batch-cmdb': 'enable',
1027        'block-session-timer': '36',
1028        'br-fdb-max-entry': '37',
1029        'cert-chain-max': '38',
1030        'cfg-revert-timeout': '39',
1031        'cfg-save': 'automatic',
1032        'check-protocol-header': 'loose',
1033        'check-reset-range': 'strict',
1034        'cli-audit-log': 'enable',
1035        'clt-cert-req': 'enable',
1036        'compliance-check': 'enable',
1037        'compliance-check-time': 'test_value_46',
1038        'cpu-use-threshold': '47',
1039        'csr-ca-attribute': 'enable',
1040        'daily-restart': 'enable',
1041        'device-identification-active-scan-delay': '50',
1042        'device-idle-timeout': '51',
1043        'dh-params': '1024',
1044        'dnsproxy-worker-count': '53',
1045        'dst': 'enable',
1046        'endpoint-control-fds-access': 'enable',
1047        'endpoint-control-portal-port': '56',
1048        'failtime': '57',
1049        'fds-statistics': 'enable',
1050        'fds-statistics-period': '59',
1051        'fgd-alert-subscription': 'advisory',
1052        'fortiextender': 'enable',
1053        'fortiextender-data-port': '62',
1054        'fortiextender-vlan-mode': 'enable',
1055        'fortiservice-port': '64',
1056        'gui-certificates': 'enable',
1057        'gui-custom-language': 'enable',
1058        'gui-date-format': 'yyyy/MM/dd',
1059        'gui-device-latitude': 'test_value_68',
1060        'gui-device-longitude': 'test_value_69',
1061        'gui-display-hostname': 'enable',
1062        'gui-ipv6': 'enable',
1063        'gui-lines-per-page': '72',
1064        'gui-theme': 'green',
1065        'gui-wireless-opensecurity': 'enable',
1066        'honor-df': 'enable',
1067        'hostname': 'myhostname76',
1068        'igmp-state-limit': '77',
1069        'interval': '78',
1070        'ip-src-port-range': 'test_value_79',
1071        'ips-affinity': 'test_value_80',
1072        'ipsec-asic-offload': 'enable',
1073        'ipsec-hmac-offload': 'enable',
1074        'ipsec-soft-dec-async': 'enable',
1075        'ipv6-accept-dad': '84',
1076        'ipv6-allow-anycast-probe': 'enable',
1077        'language': 'english',
1078        'ldapconntimeout': '87',
1079        'lldp-transmission': 'enable',
1080        'log-ssl-connection': 'enable',
1081        'log-uuid': 'disable',
1082        'login-timestamp': 'enable',
1083        'long-vdom-name': 'enable',
1084        'management-vdom': 'test_value_93',
1085        'max-dlpstat-memory': '94',
1086        'max-route-cache-size': '95',
1087        'mc-ttl-notchange': 'enable',
1088        'memory-use-threshold-extreme': '97',
1089        'memory-use-threshold-green': '98',
1090        'memory-use-threshold-red': '99',
1091        'miglog-affinity': 'test_value_100',
1092        'miglogd-children': '101',
1093        'multi-factor-authentication': 'optional',
1094        'multicast-forward': 'enable',
1095        'ndp-max-entry': '104',
1096        'per-user-bwl': 'enable',
1097        'policy-auth-concurrent': '106',
1098        'post-login-banner': 'disable',
1099        'pre-login-banner': 'enable',
1100        'private-data-encryption': 'disable',
1101        'proxy-auth-lifetime': 'enable',
1102        'proxy-auth-lifetime-timeout': '111',
1103        'proxy-auth-timeout': '112',
1104        'proxy-cipher-hardware-acceleration': 'disable',
1105        'proxy-kxp-hardware-acceleration': 'disable',
1106        'proxy-re-authentication-mode': 'session',
1107        'proxy-worker-count': '116',
1108        'radius-port': '117',
1109        'reboot-upon-config-restore': 'enable',
1110        'refresh': '119',
1111        'remoteauthtimeout': '120',
1112        'reset-sessionless-tcp': 'enable',
1113        'restart-time': 'test_value_122',
1114        'revision-backup-on-logout': 'enable',
1115        'revision-image-auto-backup': 'enable',
1116        'scanunit-count': '125',
1117        'security-rating-result-submission': 'enable',
1118        'security-rating-run-on-schedule': 'enable',
1119        'send-pmtu-icmp': 'enable',
1120        'snat-route-change': 'enable',
1121        'special-file-23-support': 'disable',
1122        'ssd-trim-date': '131',
1123        'ssd-trim-freq': 'never',
1124        'ssd-trim-hour': '133',
1125        'ssd-trim-min': '134',
1126        'ssd-trim-weekday': 'sunday',
1127        'ssh-cbc-cipher': 'enable',
1128        'ssh-hmac-md5': 'enable',
1129        'ssh-kex-sha1': 'enable',
1130        'ssl-min-proto-version': 'SSLv3',
1131        'ssl-static-key-ciphers': 'enable',
1132        'sslvpn-cipher-hardware-acceleration': 'enable',
1133        'sslvpn-kxp-hardware-acceleration': 'enable',
1134        'sslvpn-max-worker-count': '143',
1135        'sslvpn-plugin-version-check': 'enable',
1136        'strict-dirty-session-check': 'enable',
1137        'strong-crypto': 'enable',
1138        'switch-controller': 'disable',
1139        'switch-controller-reserved-network': 'test_value_148',
1140        'sys-perf-log-interval': '149',
1141        'tcp-halfclose-timer': '150',
1142        'tcp-halfopen-timer': '151',
1143        'tcp-option': 'enable',
1144        'tcp-timewait-timer': '153',
1145        'tftp': 'enable',
1146                'timezone': '01',
1147                'tp-mc-skip-policy': 'enable',
1148                'traffic-priority': 'tos',
1149                'traffic-priority-level': 'low',
1150                'two-factor-email-expiry': '159',
1151                'two-factor-fac-expiry': '160',
1152                'two-factor-ftk-expiry': '161',
1153                'two-factor-ftm-expiry': '162',
1154                'two-factor-sms-expiry': '163',
1155                'udp-idle-timer': '164',
1156                'user-server-cert': 'test_value_165',
1157                'vdom-admin': 'enable',
1158                'vip-arp-range': 'unlimited',
1159                'virtual-server-count': '168',
1160                'virtual-server-hardware-acceleration': 'disable',
1161                'wad-affinity': 'test_value_170',
1162                'wad-csvc-cs-count': '171',
1163                'wad-csvc-db-count': '172',
1164                'wad-source-affinity': 'disable',
1165                'wad-worker-count': '174',
1166                'wifi-ca-certificate': 'test_value_175',
1167                'wifi-certificate': 'test_value_176',
1168                'wimax-4g-usb': 'enable',
1169                'wireless-controller': 'enable',
1170                'wireless-controller-port': '179'
1171    }
1172
1173    set_method_mock.assert_called_with('system', 'global', data=expected_data, vdom='root')
1174    schema_method_mock.assert_not_called()
1175    assert not is_error
1176    assert not changed
1177    assert response['status'] == 'error'
1178    assert response['http_status'] == 404
1179
1180
1181def test_system_global_filter_foreign_attributes(mocker):
1182    schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
1183
1184    set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
1185    set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
1186
1187    input_data = {
1188        'username': 'admin',
1189        'state': 'present',
1190        'system_global': {
1191            'random_attribute_not_valid': 'tag',
1192            'admin_concurrent': 'enable',
1193            'admin_console_timeout': '4',
1194            'admin_https_pki_required': 'enable',
1195            'admin_lockout_duration': '6',
1196            'admin_lockout_threshold': '7',
1197            'admin_login_max': '8',
1198            'admin_maintainer': 'enable',
1199            'admin_port': '10',
1200            'admin_restrict_local': 'enable',
1201            'admin_scp': 'enable',
1202            'admin_server_cert': 'test_value_13',
1203            'admin_sport': '14',
1204            'admin_ssh_grace_time': '15',
1205            'admin_ssh_password': 'enable',
1206            'admin_ssh_port': '17',
1207            'admin_ssh_v1': 'enable',
1208            'admin_telnet_port': '19',
1209            'admintimeout': '20',
1210            'alias': 'test_value_21',
1211            'allow_traffic_redirect': 'enable',
1212            'anti_replay': 'disable',
1213            'arp_max_entry': '24',
1214            'asymroute': 'enable',
1215            'auth_cert': 'test_value_26',
1216            'auth_http_port': '27',
1217            'auth_https_port': '28',
1218            'auth_keepalive': 'enable',
1219            'auth_session_limit': 'block-new',
1220            'auto_auth_extension_device': 'enable',
1221            'av_affinity': 'test_value_32',
1222            'av_failopen': 'pass',
1223            'av_failopen_session': 'enable',
1224            'batch_cmdb': 'enable',
1225            'block_session_timer': '36',
1226            'br_fdb_max_entry': '37',
1227            'cert_chain_max': '38',
1228            'cfg_revert_timeout': '39',
1229            'cfg_save': 'automatic',
1230            'check_protocol_header': 'loose',
1231            'check_reset_range': 'strict',
1232            'cli_audit_log': 'enable',
1233            'clt_cert_req': 'enable',
1234            'compliance_check': 'enable',
1235            'compliance_check_time': 'test_value_46',
1236            'cpu_use_threshold': '47',
1237            'csr_ca_attribute': 'enable',
1238            'daily_restart': 'enable',
1239            'device_identification_active_scan_delay': '50',
1240            'device_idle_timeout': '51',
1241            'dh_params': '1024',
1242            'dnsproxy_worker_count': '53',
1243            'dst': 'enable',
1244            'endpoint_control_fds_access': 'enable',
1245            'endpoint_control_portal_port': '56',
1246            'failtime': '57',
1247            'fds_statistics': 'enable',
1248            'fds_statistics_period': '59',
1249            'fgd_alert_subscription': 'advisory',
1250            'fortiextender': 'enable',
1251            'fortiextender_data_port': '62',
1252            'fortiextender_vlan_mode': 'enable',
1253            'fortiservice_port': '64',
1254            'gui_certificates': 'enable',
1255            'gui_custom_language': 'enable',
1256            'gui_date_format': 'yyyy/MM/dd',
1257            'gui_device_latitude': 'test_value_68',
1258            'gui_device_longitude': 'test_value_69',
1259            'gui_display_hostname': 'enable',
1260            'gui_ipv6': 'enable',
1261            'gui_lines_per_page': '72',
1262            'gui_theme': 'green',
1263            'gui_wireless_opensecurity': 'enable',
1264            'honor_df': 'enable',
1265            'hostname': 'myhostname76',
1266            'igmp_state_limit': '77',
1267            'interval': '78',
1268            'ip_src_port_range': 'test_value_79',
1269            'ips_affinity': 'test_value_80',
1270            'ipsec_asic_offload': 'enable',
1271            'ipsec_hmac_offload': 'enable',
1272            'ipsec_soft_dec_async': 'enable',
1273            'ipv6_accept_dad': '84',
1274            'ipv6_allow_anycast_probe': 'enable',
1275            'language': 'english',
1276            'ldapconntimeout': '87',
1277            'lldp_transmission': 'enable',
1278            'log_ssl_connection': 'enable',
1279            'log_uuid': 'disable',
1280            'login_timestamp': 'enable',
1281            'long_vdom_name': 'enable',
1282            'management_vdom': 'test_value_93',
1283            'max_dlpstat_memory': '94',
1284            'max_route_cache_size': '95',
1285            'mc_ttl_notchange': 'enable',
1286            'memory_use_threshold_extreme': '97',
1287            'memory_use_threshold_green': '98',
1288            'memory_use_threshold_red': '99',
1289            'miglog_affinity': 'test_value_100',
1290            'miglogd_children': '101',
1291            'multi_factor_authentication': 'optional',
1292            'multicast_forward': 'enable',
1293            'ndp_max_entry': '104',
1294            'per_user_bwl': 'enable',
1295            'policy_auth_concurrent': '106',
1296            'post_login_banner': 'disable',
1297            'pre_login_banner': 'enable',
1298            'private_data_encryption': 'disable',
1299            'proxy_auth_lifetime': 'enable',
1300            'proxy_auth_lifetime_timeout': '111',
1301            'proxy_auth_timeout': '112',
1302            'proxy_cipher_hardware_acceleration': 'disable',
1303            'proxy_kxp_hardware_acceleration': 'disable',
1304            'proxy_re_authentication_mode': 'session',
1305            'proxy_worker_count': '116',
1306            'radius_port': '117',
1307            'reboot_upon_config_restore': 'enable',
1308            'refresh': '119',
1309            'remoteauthtimeout': '120',
1310            'reset_sessionless_tcp': 'enable',
1311            'restart_time': 'test_value_122',
1312            'revision_backup_on_logout': 'enable',
1313            'revision_image_auto_backup': 'enable',
1314            'scanunit_count': '125',
1315            'security_rating_result_submission': 'enable',
1316            'security_rating_run_on_schedule': 'enable',
1317            'send_pmtu_icmp': 'enable',
1318            'snat_route_change': 'enable',
1319            'special_file_23_support': 'disable',
1320            'ssd_trim_date': '131',
1321            'ssd_trim_freq': 'never',
1322            'ssd_trim_hour': '133',
1323            'ssd_trim_min': '134',
1324            'ssd_trim_weekday': 'sunday',
1325            'ssh_cbc_cipher': 'enable',
1326            'ssh_hmac_md5': 'enable',
1327            'ssh_kex_sha1': 'enable',
1328            'ssl_min_proto_version': 'SSLv3',
1329            'ssl_static_key_ciphers': 'enable',
1330            'sslvpn_cipher_hardware_acceleration': 'enable',
1331            'sslvpn_kxp_hardware_acceleration': 'enable',
1332            'sslvpn_max_worker_count': '143',
1333            'sslvpn_plugin_version_check': 'enable',
1334            'strict_dirty_session_check': 'enable',
1335            'strong_crypto': 'enable',
1336            'switch_controller': 'disable',
1337            'switch_controller_reserved_network': 'test_value_148',
1338            'sys_perf_log_interval': '149',
1339            'tcp_halfclose_timer': '150',
1340            'tcp_halfopen_timer': '151',
1341            'tcp_option': 'enable',
1342            'tcp_timewait_timer': '153',
1343            'tftp': 'enable',
1344            'timezone': '01',
1345            'tp_mc_skip_policy': 'enable',
1346            'traffic_priority': 'tos',
1347            'traffic_priority_level': 'low',
1348            'two_factor_email_expiry': '159',
1349            'two_factor_fac_expiry': '160',
1350            'two_factor_ftk_expiry': '161',
1351            'two_factor_ftm_expiry': '162',
1352            'two_factor_sms_expiry': '163',
1353            'udp_idle_timer': '164',
1354            'user_server_cert': 'test_value_165',
1355            'vdom_admin': 'enable',
1356            'vip_arp_range': 'unlimited',
1357            'virtual_server_count': '168',
1358            'virtual_server_hardware_acceleration': 'disable',
1359            'wad_affinity': 'test_value_170',
1360            'wad_csvc_cs_count': '171',
1361            'wad_csvc_db_count': '172',
1362            'wad_source_affinity': 'disable',
1363            'wad_worker_count': '174',
1364            'wifi_ca_certificate': 'test_value_175',
1365            'wifi_certificate': 'test_value_176',
1366            'wimax_4g_usb': 'enable',
1367            'wireless_controller': 'enable',
1368            'wireless_controller_port': '179'
1369        },
1370        'vdom': 'root'}
1371
1372    is_error, changed, response = fortios_system_global.fortios_system(input_data, fos_instance)
1373
1374    expected_data = {
1375        'admin-concurrent': 'enable',
1376        'admin-console-timeout': '4',
1377        'admin-https-pki-required': 'enable',
1378        'admin-lockout-duration': '6',
1379        'admin-lockout-threshold': '7',
1380        'admin-login-max': '8',
1381        'admin-maintainer': 'enable',
1382        'admin-port': '10',
1383        'admin-restrict-local': 'enable',
1384        'admin-scp': 'enable',
1385        'admin-server-cert': 'test_value_13',
1386        'admin-sport': '14',
1387        'admin-ssh-grace-time': '15',
1388        'admin-ssh-password': 'enable',
1389        'admin-ssh-port': '17',
1390        'admin-ssh-v1': 'enable',
1391        'admin-telnet-port': '19',
1392        'admintimeout': '20',
1393        'alias': 'test_value_21',
1394        'allow-traffic-redirect': 'enable',
1395        'anti-replay': 'disable',
1396        'arp-max-entry': '24',
1397        'asymroute': 'enable',
1398        'auth-cert': 'test_value_26',
1399        'auth-http-port': '27',
1400        'auth-https-port': '28',
1401        'auth-keepalive': 'enable',
1402        'auth-session-limit': 'block-new',
1403        'auto-auth-extension-device': 'enable',
1404        'av-affinity': 'test_value_32',
1405        'av-failopen': 'pass',
1406        'av-failopen-session': 'enable',
1407        'batch-cmdb': 'enable',
1408        'block-session-timer': '36',
1409        'br-fdb-max-entry': '37',
1410        'cert-chain-max': '38',
1411        'cfg-revert-timeout': '39',
1412        'cfg-save': 'automatic',
1413        'check-protocol-header': 'loose',
1414        'check-reset-range': 'strict',
1415        'cli-audit-log': 'enable',
1416        'clt-cert-req': 'enable',
1417        'compliance-check': 'enable',
1418        'compliance-check-time': 'test_value_46',
1419        'cpu-use-threshold': '47',
1420        'csr-ca-attribute': 'enable',
1421        'daily-restart': 'enable',
1422        'device-identification-active-scan-delay': '50',
1423        'device-idle-timeout': '51',
1424        'dh-params': '1024',
1425        'dnsproxy-worker-count': '53',
1426        'dst': 'enable',
1427        'endpoint-control-fds-access': 'enable',
1428        'endpoint-control-portal-port': '56',
1429        'failtime': '57',
1430        'fds-statistics': 'enable',
1431        'fds-statistics-period': '59',
1432        'fgd-alert-subscription': 'advisory',
1433        'fortiextender': 'enable',
1434        'fortiextender-data-port': '62',
1435        'fortiextender-vlan-mode': 'enable',
1436        'fortiservice-port': '64',
1437        'gui-certificates': 'enable',
1438        'gui-custom-language': 'enable',
1439        'gui-date-format': 'yyyy/MM/dd',
1440        'gui-device-latitude': 'test_value_68',
1441        'gui-device-longitude': 'test_value_69',
1442        'gui-display-hostname': 'enable',
1443        'gui-ipv6': 'enable',
1444        'gui-lines-per-page': '72',
1445        'gui-theme': 'green',
1446        'gui-wireless-opensecurity': 'enable',
1447        'honor-df': 'enable',
1448        'hostname': 'myhostname76',
1449        'igmp-state-limit': '77',
1450        'interval': '78',
1451        'ip-src-port-range': 'test_value_79',
1452        'ips-affinity': 'test_value_80',
1453        'ipsec-asic-offload': 'enable',
1454        'ipsec-hmac-offload': 'enable',
1455        'ipsec-soft-dec-async': 'enable',
1456        'ipv6-accept-dad': '84',
1457        'ipv6-allow-anycast-probe': 'enable',
1458        'language': 'english',
1459        'ldapconntimeout': '87',
1460        'lldp-transmission': 'enable',
1461        'log-ssl-connection': 'enable',
1462        'log-uuid': 'disable',
1463        'login-timestamp': 'enable',
1464        'long-vdom-name': 'enable',
1465        'management-vdom': 'test_value_93',
1466        'max-dlpstat-memory': '94',
1467        'max-route-cache-size': '95',
1468        'mc-ttl-notchange': 'enable',
1469        'memory-use-threshold-extreme': '97',
1470        'memory-use-threshold-green': '98',
1471        'memory-use-threshold-red': '99',
1472        'miglog-affinity': 'test_value_100',
1473        'miglogd-children': '101',
1474        'multi-factor-authentication': 'optional',
1475        'multicast-forward': 'enable',
1476        'ndp-max-entry': '104',
1477        'per-user-bwl': 'enable',
1478        'policy-auth-concurrent': '106',
1479        'post-login-banner': 'disable',
1480        'pre-login-banner': 'enable',
1481        'private-data-encryption': 'disable',
1482        'proxy-auth-lifetime': 'enable',
1483        'proxy-auth-lifetime-timeout': '111',
1484        'proxy-auth-timeout': '112',
1485        'proxy-cipher-hardware-acceleration': 'disable',
1486        'proxy-kxp-hardware-acceleration': 'disable',
1487        'proxy-re-authentication-mode': 'session',
1488        'proxy-worker-count': '116',
1489        'radius-port': '117',
1490        'reboot-upon-config-restore': 'enable',
1491        'refresh': '119',
1492        'remoteauthtimeout': '120',
1493        'reset-sessionless-tcp': 'enable',
1494        'restart-time': 'test_value_122',
1495        'revision-backup-on-logout': 'enable',
1496        'revision-image-auto-backup': 'enable',
1497        'scanunit-count': '125',
1498        'security-rating-result-submission': 'enable',
1499        'security-rating-run-on-schedule': 'enable',
1500        'send-pmtu-icmp': 'enable',
1501        'snat-route-change': 'enable',
1502        'special-file-23-support': 'disable',
1503        'ssd-trim-date': '131',
1504        'ssd-trim-freq': 'never',
1505        'ssd-trim-hour': '133',
1506        'ssd-trim-min': '134',
1507        'ssd-trim-weekday': 'sunday',
1508        'ssh-cbc-cipher': 'enable',
1509        'ssh-hmac-md5': 'enable',
1510        'ssh-kex-sha1': 'enable',
1511        'ssl-min-proto-version': 'SSLv3',
1512        'ssl-static-key-ciphers': 'enable',
1513        'sslvpn-cipher-hardware-acceleration': 'enable',
1514        'sslvpn-kxp-hardware-acceleration': 'enable',
1515        'sslvpn-max-worker-count': '143',
1516        'sslvpn-plugin-version-check': 'enable',
1517        'strict-dirty-session-check': 'enable',
1518        'strong-crypto': 'enable',
1519        'switch-controller': 'disable',
1520        'switch-controller-reserved-network': 'test_value_148',
1521        'sys-perf-log-interval': '149',
1522        'tcp-halfclose-timer': '150',
1523        'tcp-halfopen-timer': '151',
1524        'tcp-option': 'enable',
1525        'tcp-timewait-timer': '153',
1526        'tftp': 'enable',
1527                'timezone': '01',
1528                'tp-mc-skip-policy': 'enable',
1529                'traffic-priority': 'tos',
1530                'traffic-priority-level': 'low',
1531                'two-factor-email-expiry': '159',
1532                'two-factor-fac-expiry': '160',
1533                'two-factor-ftk-expiry': '161',
1534                'two-factor-ftm-expiry': '162',
1535                'two-factor-sms-expiry': '163',
1536                'udp-idle-timer': '164',
1537                'user-server-cert': 'test_value_165',
1538                'vdom-admin': 'enable',
1539                'vip-arp-range': 'unlimited',
1540                'virtual-server-count': '168',
1541                'virtual-server-hardware-acceleration': 'disable',
1542                'wad-affinity': 'test_value_170',
1543                'wad-csvc-cs-count': '171',
1544                'wad-csvc-db-count': '172',
1545                'wad-source-affinity': 'disable',
1546                'wad-worker-count': '174',
1547                'wifi-ca-certificate': 'test_value_175',
1548                'wifi-certificate': 'test_value_176',
1549                'wimax-4g-usb': 'enable',
1550                'wireless-controller': 'enable',
1551                'wireless-controller-port': '179'
1552    }
1553
1554    set_method_mock.assert_called_with('system', 'global', data=expected_data, vdom='root')
1555    schema_method_mock.assert_not_called()
1556    assert not is_error
1557    assert changed
1558    assert response['status'] == 'success'
1559    assert response['http_status'] == 200
1560