Debian Codegraph @

tests/probes/file/test_probes_file.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # Copyright 2009 Red Hat Inc., Durham, North Carolina.
4 # All Rights Reserved.
5 #
6 # OpenScap Probes Test Suite.
7 #
8 # Created on: Nov 30, 2009
9 #
10 # Authors:
11 # Peter Vrabec, <[email protected]>
12 # David Niemoller
13 # Ondrej Moris, <[email protected]>
14
15 . $builddir/tests/test_common.sh
16
17 # Test Cases.
18
19 function test_probes_file {
20
21 probecheck "file" || return 255
22
23 local ret_val=0;
24 local DF="$srcdir/test_probes_file.xml"
25 local RF="results.xml"
26
27 [ -f $RF ] && rm -f $RF
28
29 if [ "$1" == "verbose" ];
30 then
31 VF="verbose"
32 $OSCAP oval eval --verbose DEVEL --verbose-log-file $VF --results $RF $DF
33 else
34 $OSCAP oval eval --results $RF $DF
35 fi
36
37 if [ -f $RF ]; then
38 verify_results "def" $DF $RF 13 && verify_results "tst" $DF $RF 204
39 ret_val=$?
40 else
41 ret_val=1
42 fi
43
44 return $ret_val
45 }
46
47 function test_probes_file_filenames {
48
49 probecheck "file" || return 255
50
51 local ret_val=0
52 local DF="$srcdir/test_probes_file_filename.xml"
53 result="results.xml"
54 files_dir=$(mktemp -d)
55 DF_INJECTED=$(mktemp)
56
57 echo "Files dir: ${files_dir}"
58 echo "Content file: ${DF_INJECTED}"
59
60 # create ascii files - should be processed correctly
61 pushd "$files_dir" && {
62 for i in {1..127};
63 do
64 [ $i == 47 ] && continue ; # '/' cannot be in filename
65 hex=\\x$(printf "%x" "$i")
66 touch "$(printf filename_ok_${i}_$hex$hex$hex)"
67 done
68 popd
69 }
70
71 # inject real path to content
72 sed "s;<!--injected-path -->;${files_dir};" "$DF" > $DF_INJECTED
73
74 $OSCAP oval eval --results $result $DF_INJECTED || ret_val=1
75 $OSCAP oval validate $result || ret_val=1
76
77 # some of files maybe weren't successfully created
78 # (possibly not supported filenames by filesystem)
79 # get real count of them
80 filesCount=$(find "$files_dir" -type f | wc -l | xargs)
81
82 assert_exists 1 '//results//criterion' || ret_val=1
83 assert_exists 1 '//results//criterion[@result="true"]' || ret_val=1
84 assert_exists "$filesCount" '//unix-sys:file_item' || ret_val=1
85
86 rm $DF_INJECTED
87 rm -rf "$files_dir"
88
89 return $ret_val
90 }
91
92 function test_probes_file_invalid_utf8 {
93
94 probecheck "file" || return 255
95
96 local ret_val=0
97 local DF="$srcdir/test_probes_file_filename.xml"
98 result="results.xml"
99 files_dir=$(mktemp -d)
100 DF_INJECTED=$(mktemp)
101
102 echo "Files dir: ${files_dir}"
103 echo "Content file: ${DF_INJECTED}"
104
105 # known invalid utf-8 sequence
106 touch $(printf "${files_dir}/filename_\xf0\x28\x8c\xbc") || ret_val=1
107
108 # inject real path to content
109 sed "s;<!--injected-path -->;${files_dir};" "$DF" > $DF_INJECTED
110
111 $OSCAP oval eval --results $result $DF_INJECTED || ret_val=1
112 $OSCAP oval validate $result || ret_val=1
113
114 assert_exists 1 '//results//criterion' || ret_val=1
115 assert_exists 1 '//results//criterion[@result="error"]' || ret_val=1
116
117 rm $DF_INJECTED
118 rm -rf "$files_dir"
119
120 return $ret_val
121 }
122
123 # Testing.
124
125 test_init
126
127 test_run "test_probes_file with verbose mode" test_probes_file verbose
128 test_run "test_probes_file" test_probes_file
129 test_run "test_probes_file_filenames" test_probes_file_filenames
130 test_run "test_probes_file_invalid_utf8" test_probes_file_invalid_utf8
131
132 test_exit