|
1
|
|
|
import tests.any_test_help |
|
2
|
|
|
import graph.oval_graph |
|
3
|
|
|
import os |
|
4
|
|
|
import py |
|
5
|
|
|
import pytest |
|
6
|
|
|
import json |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
def test_parsing_full_scan_XML_and_evaluate(): |
|
10
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
|
11
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny' |
|
12
|
|
|
result = 'false' |
|
13
|
|
|
|
|
14
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
|
15
|
|
|
src, rule_id, result) |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
def test_parsing_and_evaluate_scan_with_extend_def(): |
|
19
|
|
|
src = 'test_data/ssg-fedora-ds-arf-scan-with-extend-definitions.xml' |
|
20
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_all_disable_ipv6' |
|
21
|
|
|
result = 'false' |
|
22
|
|
|
|
|
23
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
|
24
|
|
|
src, rule_id, result) |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
def test_parsing_and_evaluate_scan_with_pasing_rule(): |
|
28
|
|
|
src = 'test_data/ssg-fedora-ds-arf-passing-scan.xml' |
|
29
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_service_debug-shell_disabled' |
|
30
|
|
|
result = 'true' |
|
31
|
|
|
|
|
32
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
|
33
|
|
|
src, rule_id, result) |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
def test_parsing_and_evaluate_scan_with_fail_rule(): |
|
37
|
|
|
src = 'test_data/ssg-fedora-ds-arf-scan-fail.xml' |
|
38
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_mount_option_dev_shm_noexec' |
|
39
|
|
|
result = 'false' |
|
40
|
|
|
|
|
41
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
|
42
|
|
|
src, rule_id, result) |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
def test_parsing_and_evaluate_scan_with_rule_with_XOR(): |
|
46
|
|
|
src = 'test_data/ssg-fedora-ds-arf-scan-with-xor.xml' |
|
47
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_mount_option_nosuid_removable_partitions' |
|
48
|
|
|
result = 'true' |
|
49
|
|
|
|
|
50
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
|
51
|
|
|
src, rule_id, result) |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
def test_parsing_and_evaluate_scan_with_11_rules(): |
|
55
|
|
|
src = 'test_data/ssg-fedora-ds-arf-scan-with-11-rules.xml' |
|
56
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_mount_option_tmp_nosuid' |
|
57
|
|
|
result = 'true' |
|
58
|
|
|
|
|
59
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
|
60
|
|
|
src, rule_id, result) |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
def test_parsing_and_evaluate_scan_0(): |
|
64
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
|
65
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_audit_rules_file_deletion_events_rmdir' |
|
66
|
|
|
result = 'false' |
|
67
|
|
|
|
|
68
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
|
69
|
|
|
src, rule_id, result) |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
def test_parsing_and_evaluate_scan_1(): |
|
73
|
|
|
src = 'test_data/ssg-fedora-ds-arf-scan-with-negated-extend-definitions.xml' |
|
74
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_install_PAE_kernel_on_x86-32' |
|
75
|
|
|
result = 'true' |
|
76
|
|
|
|
|
77
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
|
78
|
|
|
src, rule_id, result) |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
def test_get_def_id_by_rule_id(): |
|
82
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
|
83
|
|
|
parser = graph.xml_parser.xml_parser(tests.any_test_help.get_src(src)) |
|
84
|
|
|
|
|
85
|
|
|
with pytest.raises(Exception, match="err- 404 rule not found!"): |
|
86
|
|
|
assert parser.get_def_id_by_rule_id('hello') |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
def test_get_def_id_by_notselected_rule_id(): |
|
90
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
|
91
|
|
|
|
|
92
|
|
|
parser = tests.any_test_help.get_parser(src) |
|
93
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_ntpd_specify_remote_server' |
|
94
|
|
|
|
|
95
|
|
|
with pytest.raises(Exception, match="not selected"): |
|
96
|
|
|
assert parser.get_def_id_by_rule_id(rule_id) |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
def test_str_to_bool(): |
|
100
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
|
101
|
|
|
parser = tests.any_test_help.get_parser(src) |
|
102
|
|
|
|
|
103
|
|
|
assert parser._str_to_bool('true') |
|
104
|
|
|
assert not parser._str_to_bool('false') |
|
105
|
|
|
with pytest.raises(Exception, match="err- negation is not bool"): |
|
106
|
|
|
assert parser._str_to_bool('error') |
|
107
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
def test_use_bat_report_file(): |
|
110
|
|
|
src = ( |
|
111
|
|
|
'test_data/xccdf_org.ssgproject.' |
|
112
|
|
|
'content_rule_sssd_ssh_known_hosts_timeout-comment.' |
|
113
|
|
|
'fail.sh-xccdf_org.ssgproject.content_profile_ospp-results-initial.xml') |
|
114
|
|
|
|
|
115
|
|
|
with pytest.raises(Exception, match=r"arf\b|ARF\b"): |
|
116
|
|
|
assert tests.any_test_help.get_parser(src) |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
def test_get_rule_dict(): |
|
120
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
|
121
|
|
|
parser = graph.xml_parser.xml_parser(tests.any_test_help.get_src(src)) |
|
122
|
|
|
rule_dict = parser.get_rule_dict( |
|
123
|
|
|
'xccdf_org.ssgproject.content_rule_dconf_gnome_session_idle_user_locks') |
|
124
|
|
|
src = 'test_data/rule_dict.json' |
|
125
|
|
|
with open(tests.any_test_help.get_src(src), 'r') as f: |
|
126
|
|
|
data = json.load(f) |
|
127
|
|
|
assert data == rule_dict |
|
128
|
|
|
|