Passed
Pull Request — master (#203)
by Jan
03:51
created

test_arf_xml_parser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 6

4 Functions

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