|
1
|
|
|
import subprocess |
|
2
|
|
|
import os |
|
3
|
|
|
import pytest |
|
4
|
|
|
import tempfile |
|
5
|
|
|
from readchar import key |
|
6
|
|
|
|
|
7
|
|
|
import tests.any_test_help |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
@pytest.mark.usefixtures("remove_generated_reports_in_root") |
|
11
|
|
|
def test_command_arf_to_graph(): |
|
12
|
|
|
subprocess.check_call(['python3', |
|
13
|
|
|
'-m', |
|
14
|
|
|
'oval_graph.command_line', |
|
15
|
|
|
'arf-to-graph', |
|
16
|
|
|
'-o', '.', |
|
17
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
|
18
|
|
|
'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
19
|
|
|
], |
|
20
|
|
|
cwd='./') |
|
21
|
|
|
file_src = tests.any_test_help.find_files( |
|
22
|
|
|
"graph-of-xccdf_org.ssgproject.content_rule_package_abrt_removed", |
|
23
|
|
|
'../') |
|
24
|
|
|
tests.any_test_help.compare_results_html(file_src[0]) |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
@pytest.mark.usefixtures("remove_generated_reports_in_root") |
|
28
|
|
|
def test_command_arf_to_graph_with_verbose(): |
|
29
|
|
|
out = subprocess.check_output(['python3', |
|
30
|
|
|
'-m', |
|
31
|
|
|
'oval_graph.command_line', |
|
32
|
|
|
'arf-to-graph', |
|
33
|
|
|
'-o', '.', |
|
34
|
|
|
'--verbose', |
|
35
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
|
36
|
|
|
'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
37
|
|
|
], |
|
38
|
|
|
cwd='./', |
|
39
|
|
|
stderr=subprocess.STDOUT) |
|
40
|
|
|
src = out.decode('utf-8').split('\n')[-2] |
|
41
|
|
|
tests.any_test_help.compare_results_html('.' + src) |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
def test_command_arf_to_graph_with_out_parameter(): |
|
45
|
|
|
src = tests.any_test_help.get_random_dir_in_tmp() |
|
46
|
|
|
subprocess.check_call(['python3', |
|
47
|
|
|
'-m', |
|
48
|
|
|
'oval_graph.command_line', |
|
49
|
|
|
'arf-to-graph', |
|
50
|
|
|
'-o', |
|
51
|
|
|
src, |
|
52
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
|
53
|
|
|
'xccdf_org.ssgproject.content_rule_package_abrt_removed' |
|
54
|
|
|
]) |
|
55
|
|
|
tests.any_test_help.compare_results_html( |
|
56
|
|
|
os.path.join(src, os.listdir(src)[0])) |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
def test_inquirer_choice_rule(): |
|
60
|
|
|
pexpect = pytest.importorskip("pexpect") |
|
61
|
|
|
src = tests.any_test_help.get_random_dir_in_tmp() |
|
62
|
|
|
sut = pexpect.spawn('python3', |
|
63
|
|
|
['-m', |
|
64
|
|
|
'oval_graph.command_line', |
|
65
|
|
|
'arf-to-graph', |
|
66
|
|
|
'-o', |
|
67
|
|
|
src, |
|
68
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
|
69
|
|
|
r'_package_\w+_removed' |
|
70
|
|
|
]) |
|
71
|
|
|
sut.expect(r'\w+') |
|
72
|
|
|
sut.send(key.DOWN) |
|
73
|
|
|
sut.send(key.SPACE) |
|
74
|
|
|
sut.send(key.ENTER) |
|
75
|
|
|
sut.wait() |
|
76
|
|
|
assert len(os.listdir(src)) == 1 |
|
77
|
|
|
assert ("xccdf_org.ssgproject.content_rule_package_sendmail_removed" |
|
78
|
|
|
in os.listdir(src)[0]) |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
def test_command_parameter_all(): |
|
82
|
|
|
src = tests.any_test_help.get_random_dir_in_tmp() |
|
83
|
|
|
subprocess.check_call(['python3', |
|
84
|
|
|
'-m', |
|
85
|
|
|
'oval_graph.command_line', |
|
86
|
|
|
'arf-to-graph', |
|
87
|
|
|
'--all', |
|
88
|
|
|
'-o', |
|
89
|
|
|
src, |
|
90
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
|
91
|
|
|
'.' |
|
92
|
|
|
]) |
|
93
|
|
|
assert len(os.listdir(src)) == 184 |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
def test_command_parameter_all_and_show_failed_rules(): |
|
97
|
|
|
src = tests.any_test_help.get_random_dir_in_tmp() |
|
98
|
|
|
subprocess.check_call(['python3', |
|
99
|
|
|
'-m', |
|
100
|
|
|
'oval_graph.command_line', |
|
101
|
|
|
'arf-to-graph', |
|
102
|
|
|
'--all', |
|
103
|
|
|
'--show-failed-rules', |
|
104
|
|
|
'-o', |
|
105
|
|
|
src, |
|
106
|
|
|
'tests/test_data/ssg-fedora-ds-arf.xml', |
|
107
|
|
|
r'_package_\w+_removed' |
|
108
|
|
|
]) |
|
109
|
|
|
assert len(os.listdir(src)) == 1 |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
def test_bad_command_arf_to_graph_with_verbose(): |
|
113
|
|
|
out = subprocess.check_output( |
|
114
|
|
|
[ |
|
115
|
|
|
'python3', |
|
116
|
|
|
'-m', |
|
117
|
|
|
'oval_graph.command_line', |
|
118
|
|
|
'arf-to-graph', |
|
119
|
|
|
'-v', |
|
120
|
|
|
'tests/test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml', |
|
121
|
|
|
'.'], |
|
122
|
|
|
stderr=subprocess.STDOUT) |
|
123
|
|
|
out_string = out.decode('utf-8') |
|
124
|
|
|
assert out_string.find("Traceback") > -1 |
|
125
|
|
|
assert out_string.find("Warning:") > -1 |
|
126
|
|
|
assert out_string.find("Error:") > -1 |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
def test_bad_command_arf_to_graph(): |
|
130
|
|
|
out = subprocess.check_output( |
|
131
|
|
|
[ |
|
132
|
|
|
'python3', |
|
133
|
|
|
'-m', |
|
134
|
|
|
'oval_graph.command_line', |
|
135
|
|
|
'arf-to-graph', |
|
136
|
|
|
'tests/test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml', |
|
137
|
|
|
'.'], |
|
138
|
|
|
stderr=subprocess.STDOUT) |
|
139
|
|
|
out_string = out.decode('utf-8') |
|
140
|
|
|
assert out_string.find("Traceback") == -1 |
|
141
|
|
|
assert out_string.find("Warning:") > -1 |
|
142
|
|
|
assert out_string.find("Error:") > -1 |
|
143
|
|
|
|