Passed
Pull Request — master (#3188)
by Alexander
02:25
created

test_rules.test_get_rule_dir_ovals()   A

Complexity

Conditions 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nop 0
dl 0
loc 16
rs 9.75
c 0
b 0
f 0
1
import pytest
2
3
import os
4
import ssg.rules
5
6
data_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "data"))
7
rule_dir = os.path.join(data_dir, "group_dir", "rule_dir")
8
9
10
def test_get_rule_dir_id():
11
    assert ssg.rules.get_rule_dir_id("/some/path/fix_all_vulns/rule.yml") == "fix_all_vulns"
12
    assert ssg.rules.get_rule_dir_id("/some/path/fix_all_vulns") == "fix_all_vulns"
13
    assert ssg.rules.get_rule_dir_id(rule_dir) == 'rule_dir'
14
15
16
def test_is_rule_dir():
17
    assert ssg.rules.is_rule_dir(rule_dir)
18
19
20
def test__applies_to_product():
21
    assert ssg.rules._applies_to_product('shared', None)
22
    assert ssg.rules._applies_to_product('rhel', None)
23
    assert ssg.rules._applies_to_product('shared', 'rhel')
24
    assert ssg.rules._applies_to_product('rhel', 'rhel')
25
    assert not ssg.rules._applies_to_product('ol', 'rhel')
26
27
28
def test_find_rule_dirs():
29
    rule_dirs = list(ssg.rules.find_rule_dirs(data_dir))
30
    rule_ids = list(map(ssg.rules.get_rule_dir_id, rule_dirs))
31
32
    assert rule_dir in rule_dirs
33
    assert 'rule_dir' in rule_ids
34
    assert 'random_dir' not in rule_ids
35
36
37
def test_get_rule_dir_ovals():
38
    ovals = ssg.rules.get_rule_dir_ovals(rule_dir)
39
    oval_files = list(map(os.path.basename, ovals))
40
41
    assert len(ovals) == 2
42
    assert 'shared.xml' in oval_files
43
    assert 'rhel.xml' in oval_files
44
    assert oval_files.index('shared.xml') > oval_files.index('rhel.xml')
45
46
    rhel_ovals = ssg.rules.get_rule_dir_ovals(rule_dir, 'rhel')
47
    assert rhel_ovals == ovals
48
49
    ol_ovals = ssg.rules.get_rule_dir_ovals(rule_dir, 'ol')
50
    assert ol_ovals != ovals
51
    assert len(ol_ovals) == 1
52
    assert 'rhel.xml' not in ol_ovals
53
54
55
def test_get_rule_dir_remediations():
56
    bash = ssg.rules.get_rule_dir_remediations(rule_dir, 'bash')
57
    bash_files = list(map(os.path.basename, bash))
58
59
    assert len(bash) == 2
60
    assert 'something.sh' in bash_files
61
    assert 'rhel.sh' in bash_files
62
63
    rhel_bash = ssg.rules.get_rule_dir_remediations(rule_dir, 'bash', 'rhel')
64
    assert len(rhel_bash) == 1
65
    assert rhel_bash[0].endswith('/rhel.sh')
66
67
    ol_bash = ssg.rules.get_rule_dir_remediations(rule_dir, 'bash', 'ol')
68
    assert len(ol_bash) == 0
69
70
    something_bash = ssg.rules.get_rule_dir_remediations(rule_dir, 'bash', 'something')
71
    assert len(something_bash) == 1
72
    assert something_bash != rhel_bash
73