1
|
|
|
from pathlib import Path |
2
|
|
|
|
3
|
|
|
import pytest |
4
|
|
|
|
5
|
|
|
from oval_graph.arf_xml_parser.arf_xml_parser import ARFXMLParser |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
def get_arf_report_path(src="global_test_data/ssg-fedora-ds-arf.xml"): |
9
|
|
|
return str(Path(__file__).parent.parent / src) |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
@pytest.mark.parametrize("rule_id, result", [ |
13
|
|
|
( |
14
|
|
|
"xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny", |
15
|
|
|
"false", |
16
|
|
|
), |
17
|
|
|
( |
18
|
|
|
"xccdf_org.ssgproject.content_rule_sshd_disable_gssapi_auth", |
19
|
|
|
"false", |
20
|
|
|
), |
21
|
|
|
( |
22
|
|
|
"xccdf_org.ssgproject.content_rule_service_debug-shell_disabled", |
23
|
|
|
"true", |
24
|
|
|
), |
25
|
|
|
( |
26
|
|
|
"xccdf_org.ssgproject.content_rule_mount_option_dev_shm_noexec", |
27
|
|
|
"false", |
28
|
|
|
), |
29
|
|
|
( |
30
|
|
|
"xccdf_org.ssgproject.content_rule_audit_rules_unsuccessful_file_modification_creat", |
31
|
|
|
"false", |
32
|
|
|
), |
33
|
|
|
( |
34
|
|
|
"xccdf_org.ssgproject.content_rule_audit_rules_file_deletion_events_rmdir", |
35
|
|
|
"false", |
36
|
|
|
), |
37
|
|
|
( |
38
|
|
|
"xccdf_org.ssgproject.content_rule_require_singleuser_auth", |
39
|
|
|
"true", |
40
|
|
|
), |
41
|
|
|
]) |
42
|
|
|
def test_parsing_and_evaluate_scan_rule(rule_id, result): |
43
|
|
|
path = get_arf_report_path() |
44
|
|
|
|
45
|
|
|
parser = ARFXMLParser(path) |
46
|
|
|
oval_tree = parser.get_oval_tree(rule_id) |
47
|
|
|
assert oval_tree.evaluate_tree() == result |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
@pytest.mark.parametrize("rule_id, pattern", [ |
51
|
|
|
("hello", "404 rule \"hello\" not found!"), |
52
|
|
|
("xccdf_org.ssgproject.content_rule_ntpd_specify_remote_server", "notselected"), |
53
|
|
|
("xccdf_org.ssgproject.content_rule_configure_bind_crypto_policy", "notchecked"), |
54
|
|
|
("xccdf_org.ssgproject.content_rule_ensure_gpgcheck_local_packages", "notapplicable"), |
55
|
|
|
]) |
56
|
|
|
def test_parsing_bad_rule(rule_id, pattern): |
57
|
|
|
path = get_arf_report_path() |
58
|
|
|
parser = ARFXMLParser(path) |
59
|
|
|
|
60
|
|
|
with pytest.raises(Exception, match=pattern): |
61
|
|
|
assert parser.get_oval_tree(rule_id) |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
def test_use_bad_report_file(): |
65
|
|
|
src = 'global_test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml' |
66
|
|
|
path = get_arf_report_path(src) |
67
|
|
|
with pytest.raises(Exception, match=r"arf\b|ARF\b"): |
68
|
|
|
assert ARFXMLParser(path) |
69
|
|
|
|