|
1
|
|
|
import os |
|
2
|
|
|
|
|
3
|
|
|
import pytest |
|
4
|
|
|
|
|
5
|
|
|
import org_fedora_oscap.content_discovery as tested_module |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
@pytest.fixture |
|
9
|
|
|
def labelled_files(): |
|
10
|
|
|
return { |
|
11
|
|
|
"dir/datastream": "D", |
|
12
|
|
|
"dir/datastream2": "D", |
|
13
|
|
|
"dir/dir/datastream3": "D", |
|
14
|
|
|
"dir/dir/datastream3": "D", |
|
15
|
|
|
"dir/XCCDF": "X", |
|
16
|
|
|
"XCCDF2": "X", |
|
17
|
|
|
"cpe": "C", |
|
18
|
|
|
"t1": "T", |
|
19
|
|
|
"dir3/t2": "T", |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
def test_reduce(labelled_files): |
|
24
|
|
|
bringer = tested_module.ContentBringer(None) |
|
25
|
|
|
|
|
26
|
|
|
d_count = 0 |
|
27
|
|
|
x_count = 0 |
|
28
|
|
|
for l in labelled_files.values(): |
|
29
|
|
|
if l == "D": |
|
30
|
|
|
d_count += 1 |
|
31
|
|
|
elif l == "X": |
|
32
|
|
|
x_count += 1 |
|
33
|
|
|
|
|
34
|
|
|
reduced = bringer.reduce_files(labelled_files, "dir/datastream", ["D"]) |
|
35
|
|
|
assert len(reduced) == len(labelled_files) - d_count + 1 |
|
36
|
|
|
assert "dir/datastream" in reduced |
|
37
|
|
|
|
|
38
|
|
|
reduced = bringer.reduce_files(labelled_files, "dir/datastream", ["D", "X"]) |
|
39
|
|
|
assert len(reduced) == len(labelled_files) - d_count - x_count + 1 |
|
40
|
|
|
assert "dir/datastream" in reduced |
|
41
|
|
|
|
|
42
|
|
|
reduced = bringer.reduce_files(labelled_files, "dir/XCCDF", ["D", "X"]) |
|
43
|
|
|
assert len(reduced) == len(labelled_files) - d_count - x_count + 1 |
|
44
|
|
|
assert "dir/XCCDF" in reduced |
|
45
|
|
|
|
|
46
|
|
|
with pytest.raises(RuntimeError, match="dir/datastream4"): |
|
47
|
|
|
bringer.reduce_files(labelled_files, "dir/datastream4", ["D"]) |
|
48
|
|
|
|
|
49
|
|
|
reduced = bringer.reduce_files(labelled_files, "cpe", ["C"]) |
|
50
|
|
|
assert reduced == labelled_files |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
def test_path_presence_detection(): |
|
54
|
|
|
list_of_paths = ["file1", os.path.abspath("file2"), os.path.abspath("dir///file3")] |
|
55
|
|
|
|
|
56
|
|
|
list_of_paths_in_list = [ |
|
57
|
|
|
"file1", os.path.abspath("file1"), "./file1", |
|
58
|
|
|
"file2", "dir/..//file2", |
|
59
|
|
|
"dir/../dir/file3", "dir/file3", |
|
60
|
|
|
] |
|
61
|
|
|
list_of_paths_not_in_list = [ |
|
62
|
|
|
"../file1", "file3" |
|
63
|
|
|
] |
|
64
|
|
|
|
|
65
|
|
|
for path in list_of_paths_in_list: |
|
66
|
|
|
assert tested_module.path_is_present_among_paths(path, list_of_paths) |
|
67
|
|
|
|
|
68
|
|
|
for path in list_of_paths_not_in_list: |
|
69
|
|
|
assert not tested_module.path_is_present_among_paths(path, list_of_paths) |
|
70
|
|
|
|