Debian Codegraph @

tests/probes/file/test_probes_file.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/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_filescip-shell shell shell-project 0.0.0 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 [scip-shell system . . `[`. -f $RF ] && rmscip-shell system . . rm. -f $RF
28
29 if [scip-shell system . . `[`. "$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 [scip-shell system . . `[`. -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_filenamesscip-shell shell shell-project 0.0.0 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=$(mktempscip-shell system . . mktemp. -d)
55 DF_INJECTED=$(mktempscip-shell system . . mktemp.)
56
57 echoscip-shell system . . echo. "Files dir: ${files_dir}"
58 echoscip-shell system . . 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 [scip-shell system . . `[`. $i == 47 ] && continue ; # '/' cannot be in filename
65 hex=\\x$(printfscip-shell system . . printf. "%x" "$i")
66 touchscip-shell system . . touch. "$(printfscip-shell system . . printf. filename_ok_${i}_$hex$hex$hex)"
67 done
68 popd
69 }
70
71 # inject real path to content
72 sedscip-shell system . . 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=$(findscip-shell system . . find. "$files_dir" -type f | wcscip-shell system . . wc. -l | xargsscip-shell system . . 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 rmscip-shell system . . rm. $DF_INJECTED
87 rmscip-shell system . . rm. -rf "$files_dir"
88
89 return $ret_val
90 }
91
92 function test_probes_file_invalid_utf8scip-shell shell shell-project 0.0.0 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=$(mktempscip-shell system . . mktemp. -d)
100 DF_INJECTED=$(mktempscip-shell system . . mktemp.)
101
102 echoscip-shell system . . echo. "Files dir: ${files_dir}"
103 echoscip-shell system . . echo. "Content file: ${DF_INJECTED}"
104
105 # known invalid utf-8 sequence
106 touchscip-shell system . . touch. $(printfscip-shell system . . printf. "${files_dir}/filename_\xf0\x28\x8c\xbc") || ret_val=1
107
108 # inject real path to content
109 sedscip-shell system . . 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 rmscip-shell system . . rm. $DF_INJECTED
118 rmscip-shell system . . 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