|
1
|
|
|
# |
|
2
|
|
|
# Copyright (C) 2021 Red Hat, Inc. |
|
3
|
|
|
# |
|
4
|
|
|
# This copyrighted material is made available to anyone wishing to use, |
|
5
|
|
|
# modify, copy, or redistribute it subject to the terms and conditions of |
|
6
|
|
|
# the GNU General Public License v.2, or (at your option) any later version. |
|
7
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
|
8
|
|
|
# ANY WARRANTY expressed or implied, including the implied warranties of |
|
9
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
10
|
|
|
# Public License for more details. You should have received a copy of the |
|
11
|
|
|
# GNU General Public License along with this program; if not, write to the |
|
12
|
|
|
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
13
|
|
|
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the |
|
14
|
|
|
# source code or documentation are not subject to the GNU General Public |
|
15
|
|
|
# License and may only be used or replicated with the express permission of |
|
16
|
|
|
# Red Hat, Inc. |
|
17
|
|
|
# |
|
18
|
|
|
import pytest |
|
19
|
|
|
|
|
20
|
|
|
from org_fedora_oscap.structures import PolicyData |
|
21
|
|
|
from org_fedora_oscap import common |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
View Code Duplication |
def test_datastream_content_paths(): |
|
|
|
|
|
|
25
|
|
|
data = PolicyData() |
|
26
|
|
|
data.content_type = "datastream" |
|
27
|
|
|
data.content_url = "https://example.com/hardening.xml" |
|
28
|
|
|
data.datastream_id = "id_datastream_1" |
|
29
|
|
|
data.xccdf_id = "id_xccdf_new" |
|
30
|
|
|
data.content_path = "/usr/share/oscap/testing_ds.xml" |
|
31
|
|
|
data.cpe_path = "/usr/share/oscap/cpe.xml" |
|
32
|
|
|
data.tailoring_path = "/usr/share/oscap/tailoring.xml" |
|
33
|
|
|
data.profile_id = "Web Server" |
|
34
|
|
|
|
|
35
|
|
|
assert common.get_content_name(data) == "hardening.xml" |
|
36
|
|
|
|
|
37
|
|
|
expected_path = "/tmp/openscap_data/hardening.xml" |
|
38
|
|
|
assert common.get_raw_preinst_content_path(data) == expected_path |
|
39
|
|
|
|
|
40
|
|
|
expected_path = "/tmp/openscap_data/hardening.xml" |
|
41
|
|
|
assert common.get_preinst_content_path(data) == expected_path |
|
42
|
|
|
|
|
43
|
|
|
expected_path = "/root/openscap_data/hardening.xml" |
|
44
|
|
|
assert common.get_postinst_content_path(data) == expected_path |
|
45
|
|
|
|
|
46
|
|
|
expected_path = "/tmp/openscap_data/usr/share/oscap/tailoring.xml" |
|
47
|
|
|
assert common.get_preinst_tailoring_path(data) == expected_path |
|
48
|
|
|
|
|
49
|
|
|
expected_path = "/root/openscap_data/usr/share/oscap/tailoring.xml" |
|
50
|
|
|
assert common.get_postinst_tailoring_path(data) == expected_path |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
View Code Duplication |
def test_archive_content_paths(): |
|
|
|
|
|
|
54
|
|
|
data = PolicyData() |
|
55
|
|
|
data.content_type = "archive" |
|
56
|
|
|
data.content_url = "http://example.com/oscap_content.tar" |
|
57
|
|
|
data.content_path = "oscap/xccdf.xml" |
|
58
|
|
|
data.profile_id = "Web Server" |
|
59
|
|
|
data.content_path = "oscap/xccdf.xml" |
|
60
|
|
|
data.tailoring_path = "oscap/tailoring.xml" |
|
61
|
|
|
|
|
62
|
|
|
assert common.get_content_name(data) == "oscap_content.tar" |
|
63
|
|
|
|
|
64
|
|
|
expected_path = "/tmp/openscap_data/oscap_content.tar" |
|
65
|
|
|
assert common.get_raw_preinst_content_path(data) == expected_path |
|
66
|
|
|
|
|
67
|
|
|
expected_path = "/tmp/openscap_data/oscap/xccdf.xml" |
|
68
|
|
|
assert common.get_preinst_content_path(data) == expected_path |
|
69
|
|
|
|
|
70
|
|
|
expected_path = "/root/openscap_data/oscap/xccdf.xml" |
|
71
|
|
|
assert common.get_postinst_content_path(data) == expected_path |
|
72
|
|
|
|
|
73
|
|
|
expected_path = "/tmp/openscap_data/oscap/tailoring.xml" |
|
74
|
|
|
assert common.get_preinst_tailoring_path(data) == expected_path |
|
75
|
|
|
|
|
76
|
|
|
expected_path = "/root/openscap_data/oscap/tailoring.xml" |
|
77
|
|
|
assert common.get_postinst_tailoring_path(data) == expected_path |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
View Code Duplication |
def test_rpm_content_paths(): |
|
|
|
|
|
|
81
|
|
|
data = PolicyData() |
|
82
|
|
|
data.content_type = "rpm" |
|
83
|
|
|
data.content_url = "http://example.com/oscap_content.rpm" |
|
84
|
|
|
data.profile_id = "Web Server" |
|
85
|
|
|
data.content_path = "/usr/share/oscap/xccdf.xml" |
|
86
|
|
|
data.tailoring_path = "/usr/share/oscap/tailoring.xml" |
|
87
|
|
|
|
|
88
|
|
|
assert common.get_content_name(data) == "oscap_content.rpm" |
|
89
|
|
|
|
|
90
|
|
|
expected_path = "/tmp/openscap_data/oscap_content.rpm" |
|
91
|
|
|
assert common.get_raw_preinst_content_path(data) == expected_path |
|
92
|
|
|
|
|
93
|
|
|
expected_path = "/tmp/openscap_data/usr/share/oscap/xccdf.xml" |
|
94
|
|
|
assert common.get_preinst_content_path(data) == expected_path |
|
95
|
|
|
|
|
96
|
|
|
expected_path = "/usr/share/oscap/xccdf.xml" |
|
97
|
|
|
assert common.get_postinst_content_path(data) == expected_path |
|
98
|
|
|
|
|
99
|
|
|
expected_path = "/tmp/openscap_data/usr/share/oscap/tailoring.xml" |
|
100
|
|
|
assert common.get_preinst_tailoring_path(data) == expected_path |
|
101
|
|
|
|
|
102
|
|
|
expected_path = "/usr/share/oscap/tailoring.xml" |
|
103
|
|
|
assert common.get_postinst_tailoring_path(data) == expected_path |
|
104
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
def test_scap_security_guide_paths(): |
|
107
|
|
|
data = PolicyData() |
|
108
|
|
|
data.content_type = "scap-security-guide" |
|
109
|
|
|
data.profile_id = "Web Server" |
|
110
|
|
|
data.content_path = "/usr/share/xml/scap/ssg/content.xml" |
|
111
|
|
|
|
|
112
|
|
|
expected_msg = "Using scap-security-guide, no single content file" |
|
113
|
|
|
with pytest.raises(ValueError, match=expected_msg): |
|
114
|
|
|
common.get_content_name(data) |
|
115
|
|
|
|
|
116
|
|
|
expected_path = None |
|
117
|
|
|
assert common.get_raw_preinst_content_path(data) == expected_path |
|
118
|
|
|
|
|
119
|
|
|
expected_path = "/usr/share/xml/scap/ssg/content.xml" |
|
120
|
|
|
assert common.get_preinst_content_path(data) == expected_path |
|
121
|
|
|
|
|
122
|
|
|
expected_path = "/usr/share/xml/scap/ssg/content.xml" |
|
123
|
|
|
assert common.get_postinst_content_path(data) == expected_path |
|
124
|
|
|
|
|
125
|
|
|
expected_path = "" |
|
126
|
|
|
assert common.get_preinst_tailoring_path(data) == expected_path |
|
127
|
|
|
|
|
128
|
|
|
expected_path = "" |
|
129
|
|
|
assert common.get_postinst_tailoring_path(data) == expected_path |
|
130
|
|
|
|