1
|
|
|
import os |
2
|
|
|
import pytest |
3
|
|
|
import json |
4
|
|
|
|
5
|
|
|
import pytest |
6
|
|
|
|
7
|
|
|
import tests.any_test_help |
8
|
|
|
from oval_graph.xml_parser import XmlParser |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
def test_parsing_full_scan_XML_and_evaluate(): |
12
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
13
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny' |
14
|
|
|
result = 'false' |
15
|
|
|
|
16
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
17
|
|
|
src, rule_id, result) |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
def test_parsing_and_evaluate_scan_with_extend_def(): |
21
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
22
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_sshd_disable_gssapi_auth' |
23
|
|
|
result = 'false' |
24
|
|
|
|
25
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
26
|
|
|
src, rule_id, result) |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
def test_parsing_and_evaluate_scan_with_pasing_rule(): |
30
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
31
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_service_debug-shell_disabled' |
32
|
|
|
result = 'true' |
33
|
|
|
|
34
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
35
|
|
|
src, rule_id, result) |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
def test_parsing_and_evaluate_scan_with_fail_rule(): |
39
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
40
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_mount_option_dev_shm_noexec' |
41
|
|
|
result = 'false' |
42
|
|
|
|
43
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
44
|
|
|
src, rule_id, result) |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
def test_parsing_and_evaluate_scan_with_rule_with_NOT_OR(): |
48
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
49
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_audit_rules_unsuccessful_file_modification_creat' |
50
|
|
|
result = 'false' |
51
|
|
|
|
52
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
53
|
|
|
src, rule_id, result) |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
def test_parsing_and_evaluate_scan_0(): |
57
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
58
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_audit_rules_file_deletion_events_rmdir' |
59
|
|
|
result = 'false' |
60
|
|
|
|
61
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
62
|
|
|
src, rule_id, result) |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
def test_parsing_and_evaluate_scan_1(): |
66
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
67
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_require_singleuser_auth' |
68
|
|
|
result = 'true' |
69
|
|
|
|
70
|
|
|
tests.any_test_help.any_test_parsing_and_evaluate_scan_rule( |
71
|
|
|
src, rule_id, result) |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
def test_get_def_id_by_rule_id(): |
75
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
76
|
|
|
parser = XmlParser(tests.any_test_help.get_src(src)) |
77
|
|
|
|
78
|
|
|
with pytest.raises(Exception, match='404 rule "hello" not found!'): |
79
|
|
|
assert parser._get_definition_of_rule('hello') |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
def test_get_def_id_by_notselected_rule_id(): |
83
|
|
|
src = 'test_data/ssg-fedora-ds-arf.xml' |
84
|
|
|
|
85
|
|
|
parser = tests.any_test_help.get_parser(src) |
86
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_ntpd_specify_remote_server' |
87
|
|
|
|
88
|
|
|
with pytest.raises(Exception, match="not selected"): |
89
|
|
|
assert parser._get_definition_of_rule(rule_id) |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
def test_use_bat_report_file(): |
93
|
|
|
src = 'test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml' |
94
|
|
|
|
95
|
|
|
with pytest.raises(Exception, match=r"arf\b|ARF\b"): |
96
|
|
|
assert tests.any_test_help.get_parser(src) |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
def test_get_def_id_by_notchecked_rule_id(): |
100
|
|
|
src = 'test_data/arf-scan-with-notchecked-rule.xml' |
101
|
|
|
|
102
|
|
|
parser = tests.any_test_help.get_parser(src) |
103
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_security_patches_up_to_date' |
104
|
|
|
|
105
|
|
|
with pytest.raises(Exception, match="notchecked"): |
106
|
|
|
assert parser._get_definition_of_rule(rule_id) |
107
|
|
|
|