1
|
|
|
import pytest |
2
|
|
|
|
3
|
|
|
import os |
4
|
|
|
import ssg.build_remediations as sbr |
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
|
|
|
rhel_bash = os.path.join(rule_dir, "bash", "rhel.sh") |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
def test_is_applicable_for_product(): |
12
|
|
|
assert sbr.is_applicable_for_product("multi_platform_all", "rhel7") |
13
|
|
|
assert sbr.is_applicable_for_product("multi_platform_rhel", "rhel7") |
14
|
|
|
assert sbr.is_applicable_for_product("multi_platform_rhel,multi_platform_ol", "rhel7") |
15
|
|
|
assert sbr.is_applicable_for_product("Red Hat Enterprise Linux 7", "rhel7") |
16
|
|
|
assert not sbr.is_applicable_for_product("Red Hat Enterprise Linux 7", "rhel6") |
17
|
|
|
assert not sbr.is_applicable_for_product("multi_platform_ol", "rhel7") |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
def test_is_supported_file_name(): |
21
|
|
|
assert sbr.is_supported_filename('bash', 'something.sh') |
22
|
|
|
assert not sbr.is_supported_filename('bash', 'something.py') |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
def do_test_contents(remediation, config): |
26
|
|
|
assert 'do_something_magical' in remediation |
27
|
|
|
assert '# a random comment' in remediation |
28
|
|
|
assert len(remediation) == 3 |
29
|
|
|
|
30
|
|
|
assert 'platform' in config |
31
|
|
|
assert 'reboot' in config |
32
|
|
|
assert 'complexity' in config |
33
|
|
|
assert 'strategy' in config |
34
|
|
|
assert 'disruption' in config |
35
|
|
|
|
36
|
|
|
assert sbr.is_applicable_for_product(config['platform'], 'rhel7') |
37
|
|
|
assert sbr.is_applicable_for_product(config['platform'], 'fedora') |
38
|
|
|
assert not sbr.is_applicable_for_product(config['platform'], 'rhel6') |
39
|
|
|
assert not sbr.is_applicable_for_product(config['platform'], 'ol7') |
40
|
|
|
|
41
|
|
|
assert 'false' == config['reboot'] |
42
|
|
|
assert 'low' == config['complexity'] |
43
|
|
|
assert 'configure' == config['strategy'] |
44
|
|
|
assert 'low' == config['disruption'] |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
def test_parse_from_file(): |
48
|
|
|
remediation, config = sbr.parse_from_file(rhel_bash, {}) |
49
|
|
|
do_test_contents(remediation, config) |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
def test_process_fix(): |
53
|
|
|
fixes = {} |
54
|
|
|
sbr.process_fix(fixes, 'bash', {}, 'rhel7', rhel_bash, 'rule_dir') |
55
|
|
|
|
56
|
|
|
assert 'rule_dir' in fixes |
57
|
|
|
assert len(fixes['rule_dir']) == 2 |
58
|
|
|
do_test_contents(fixes['rule_dir'].contents, fixes['rule_dir'].config) |
59
|
|
|
|