File: test_rule_dir_stats.py

package info (click to toggle)
scap-security-guide 0.1.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 110,644 kB
  • sloc: xml: 241,883; sh: 73,777; python: 32,527; makefile: 27
file content (117 lines) | stat: -rw-r--r-- 2,488 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import os

import pytest

import ssg.rule_dir_stats as rds


def test_missing_oval():
    good_rule = {
        "id": "good_rule",
        "ovals": {
            "shared.xml": {}
        }
    }
    bad_rule = {
        "id": "bad_rule",
        "ovals": {}
    }

    assert not rds.missing_oval(good_rule)
    assert rds.missing_oval(bad_rule)


def test_missing_remediation():
    good_rule = {
        "id": "good_rule",
        "remediations": {
            "bash": {
                "shared.sh": {}
            }
        }
    }
    bad_rule = {
        "id": "bad_rule",
        "remediations": {
            "bash": {}
        }
    }

    assert not rds.missing_remediation(good_rule, 'bash')
    assert rds.missing_remediation(bad_rule, 'bash')
    assert rds.missing_remediation(bad_rule, 'anaconda')


def test_two_plus_oval():
    three_rule = {
        "id": "three_rule",
        "ovals": {
            "rhel6.xml": {},
            "rhel7.xml": {},
            "fedora.xml": {}
        }
    }
    two_rule = {
        "id": "two_rule",
        "ovals": {
            "rhel6.xml": {},
            "rhel7.xml": {}
        }
    }
    one_rule = {
        "id": "one_rule",
        "ovals": {
            "rhel6.xml": {},
        }
    }
    empty_rule = {
        "id": "bad_rule",
        "ovals": {}
    }

    assert rds.two_plus_oval(three_rule)
    assert rds.two_plus_oval(two_rule)
    assert not rds.two_plus_oval(one_rule)
    assert not rds.two_plus_oval(empty_rule)


def test_two_plus_remediation():
    three_rule = {
        "id": "three_rule",
        "remediations": {
            "bash": {
                "rhel6.sh": {},
                "rhel7.sh": {},
                "fedora.sh": {}
            }
        }
    }
    two_rule = {
        "id": "two_rule",
        "remediations": {
            "bash": {
                "rhel6.sh": {},
                "rhel7.sh": {}
            }
        }
    }
    one_rule = {
        "id": "one_rule",
        "remediations": {
            "bash": {
                "rhel7.sh": {}
            }
        }
    }
    empty_rule = {
        "id": "empty_rule",
        "remediations": {
            "bash": {}
        }
    }

    assert rds.two_plus_remediation(three_rule, 'bash')
    assert rds.two_plus_remediation(two_rule, 'bash')
    assert not rds.two_plus_remediation(one_rule, 'bash')
    assert not rds.two_plus_remediation(empty_rule, 'bash')
    assert not rds.two_plus_remediation(empty_rule, 'anaconda')