1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
#!/bin/bash
#
# Copyright (c) 2014, Red Hat, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied, of the FreeBSD Project.
#
# Authors: Michal Minar <miminar@redhat.com>
. ./base.sh
# Set the full test name
TEST="openlmi-scripts/test/test_file.sh"
# Package being tested
PACKAGE="openlmi-scripts-logicalfile"
function list_dir() {
# Generate the same output as `lmi file list <path>` should do
declare -a column_sizes
declare -a data
path="$1"
[ "$path" == '/' ] || path+=/
data[$((line_no++))]="Type@Mode@Current SELinux Context@Name"
while IFS= read col_name; do
column_sizes[$((col_index++))]=${#col_name}
done < <(echo "${data[0]}" | tr '@' '\n')
while IFS= read line; do
if [[ "$line" == EOF ]]; then
for i in `seq 0 $((${#data[@]} - 1))`; do
IFS=@ read ft fm sl fn <<<"${data[i]}"
printf "%-*s %-*s %-*s %s\n" \
${column_sizes[0]} "$ft" \
${column_sizes[3]} "$fn" \
${column_sizes[1]} "$fm" \
"$sl"
done
break
fi
file_type=${line:0:1}
if [[ $file_type == 'd' ]]; then
file_type=Dir
else
file_type=`echo ${file_type^^} | tr '-' 'F'`
fi
[ ${column_sizes[0]:-0} -lt ${#file_type} ] && column_sizes[0]=${#file_type}
file_mode=${line:1:3}
[ ${column_sizes[1]:-0} -lt ${#file_mode} ] && column_sizes[1]=${#file_mode}
selinux=`echo $line | cut -d \ -f 4`
[ ${column_sizes[2]:-0} -lt ${#selinux} ] && column_sizes[2]=${#selinux}
file_name="$path$(echo $line | cut -d \ -f 5)"
[ ${column_sizes[3]:-0} -lt ${#file_name} ] && column_sizes[3]=${#file_name}
data[$((line_no++))]="$file_type@$file_mode@$selinux@$file_name"
done < <(ls -la -Z "$1" | tail -n +3; echo EOF)
unset column_sizes data path file_type file_mode selinux file_name \
line_no col_index
}
rlJournalStart
rlPhaseStartSetup
rlLogInfo "Creating temporary python sandbox"
sandbox=`mktemp -d`
export PYTHONPATH="$sandbox"
pushd ../../..
rlLogInfo "Installing lmi meta-command"
rlRun "python setup.py develop --install-dir=$sandbox" 0
popd
pushd ..
rlLogInfo "Installing file subcommand"
rlRun "python setup.py develop --install-dir=$sandbox" 0
popd
export PATH="$sandbox:$PATH"
rlPhaseEnd
rlPhaseStartTest
rlLogInfo "Test list directory"
for directory in / /usr /usr/lib; do
list_dir_tmp_out=`mktemp list_dirXXXX`
rlRun -s "$LMI file list $directory" 0
list_dir "$directory" > $list_dir_tmp_out
rlAssertNotDiffer $list_dir_tmp_out $rlRun_LOG
rm $rlRun_LOG $list_dir_tmp_out
done
rlPhaseEnd
rlPhaseStartTest
rlLogInfo "Test create and delete non-ascii directory"
list_dir_tmp_out=`mktemp list_dirXXXX`
temp_dir=`mktemp -d`
dir="$temp_dir/ěščřžýáíé"
if [ -e $dir ]; then
rm -rf $dir
fi
rlRun -s "$LMI file list $temp_dir" 0
list_dir "$temp_dir" > $list_dir_tmp_out
rlAssertNotDiffer $list_dir_tmp_out $rlRun_LOG
rm $rlRun_LOG
rlRun "$LMI file createdir $dir" 0
rlRun "[ -d $dir ]" 0
rlRun -s "$LMI file list $temp_dir" 0
list_dir $temp_dir > $list_dir_tmp_out
rlAssertGrep "$dir" $list_dir_tmp_out
rlAssertNotDiffer $list_dir_tmp_out $rlRun_LOG
rm $rlRun_LOG
rlRun "$LMI file deletedir $dir" 0
rlRun "[ -e $dir ]" 1
rlRun -s "$LMI file list $temp_dir" 0
list_dir $temp_dir > $list_dir_tmp_out
rlAssertNotGrep "$dir" $list_dir_tmp_out
rlAssertNotDiffer $list_dir_tmp_out $rlRun_LOG
rm -rf $list_dir_tmp_out $temp_dir $rlRun_LOG
rlPhaseEnd
rlPhaseStartCleanup
rlLogInfo "Removing temporary python sandbox"
rm -rf "$sandbox"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd
|