3 # Blackbox test for shadow_copy2 VFS.
8 Usage: test_shadow_copy SERVER SERVER_IP DOMAIN USERNAME PASSWORD WORKDIR SMBCLIENT
21 SMBCLIENT="$VALGRIND ${SMBCLIENT}"
24 incdir=`dirname $0`/../../../testprogs/blackbox
27 SNAPSHOTS[0]='@GMT-2015.10.31-19.40.30'
28 SNAPSHOTS[1]='@GMT-2016.10.31-19.40.30'
29 SNAPSHOTS[2]='@GMT-2017.10.31-19.40.30'
30 SNAPSHOTS[3]='@GMT-2018.10.31-19.40.30'
31 SNAPSHOTS[4]='@GMT-2019.10.31-19.40.30'
32 SNAPSHOTS[5]='@GMT-2020.10.31-19.40.30'
33 SNAPSHOTS[6]='@GMT-2021.10.31-19.40.30'
34 SNAPSHOTS[7]='@GMT-2022.10.31-19.40.30'
35 SNAPSHOTS[8]='@GMT-2023.10.31-19.40.30'
36 SNAPSHOTS[9]='@GMT-2024.10.31-19.40.30'
37 SNAPSHOTS[10]='@GMT-2010-11-11'
38 SNAPSHOTS[11]='@GMT-2011.11.11-11.40.30'
39 SNAPSHOTS[12]='snap@GMT-2012.11.11-11.40.30'
40 SNAPSHOTS[13]='@GMT-2013.11.11-11_40_33-snap'
41 SNAPSHOTS[14]='@GMT-2014.11.11-11.40.30'
42 SNAPSHOTS[15]='daily@GMT-2015.11.11-11.40.30'
44 # build a hierarchy of files, symlinks, and directories
54 if [ -n "$prefix" ] ; then
55 destdir=$rootdir/$prefix
61 if [ "$version" = "latest" ] ; then
63 # for non-snapshot version, create legit files
64 # so that wide-link checks focus on snapshot files
67 touch $destdir/bar/baz
68 touch $destdir/bar/lfoo
69 touch $destdir/bar/letcpasswd
70 touch $destdir/bar/loutside
71 elif [ "$version" = "fullsnap" ] ; then
75 touch $destdir/bar/baz
76 ln -fs ../foo $destdir/bar/lfoo
77 ln -fs /etc/passwd $destdir/bar/letcpasswd
78 ln -fs ../../outside $destdir/bar/loutside
79 touch `dirname $destdir`/outside
80 else #subshare snapshot - at bar
82 ln -fs ../foo $destdir/lfoo
83 ln -fs /etc/passwd $destdir/letcpasswd
84 ln -fs ../../outside $destdir/loutside
85 touch `dirname $destdir`/../outside
90 # build a snapshots directory
93 local where #where to build snapshots
94 local prefix #prefix from snapshot dir to share root
95 local start #timestamp index of first snapshot
96 local end #timestamp index of last snapshot
97 local sub #creat a snapshot of subtree of share
109 snapdir=$where/.snapshots
113 if [ "$sub" = "1" ] ; then
117 # a valid link target for an inner symlink -
118 # the link is not broken yet should be blocked
119 # by wide link checks
123 for i in `seq $start $end` ; do
124 snapname=${SNAPSHOTS[$i]}
125 mkdir $snapdir/$snapname
126 build_files $snapdir/$snapname "$prefix" $version
130 # Test listing previous versions of a file
131 test_count_versions()
141 versions=`$SMBCLIENT -U$USERNAME%$PASSWORD "//$SERVER/$share" -I $SERVER_IP -c "allinfo $path" | grep "^create_time:" | wc -l`
142 if [ "$versions" = "$expected_count" ] ; then
145 echo "expected $expected_count versions of $path, got $versions"
150 # Test fetching a previous version of a file
151 test_fetch_snap_file()
160 $SMBCLIENT -U$USERNAME%$PASSWORD "//$SERVER/$share" -I $SERVER_IP \
161 -c "get ${SNAPSHOTS[$snapidx]}/$path $WORKDIR/foo"
164 test_shadow_copy_fixed()
166 local share #share to contact
167 local where #where to place snapshots
168 local prefix #prefix to files inside snapshot
172 local ncopies_blocked
182 if [ -n "$allow_wl" ] ; then
186 #delete snapshots from previous tests
187 find $WORKDIR -name ".snapshots" -exec rm -rf {} \; 1>/dev/null 2>&1
188 build_snapshots $WORKDIR/$where "$prefix" 0 2
190 testit "$msg - regular file" \
191 test_count_versions $share foo $ncopies_allowed || \
192 failed=`expr $failed + 1`
194 testit "$msg - regular file in subdir" \
195 test_count_versions $share bar/baz $ncopies_allowed || \
196 failed=`expr $failed + 1`
198 testit "$msg - local symlink" \
199 test_count_versions $share bar/lfoo $ncopies_allowed || \
200 failed=`expr $failed + 1`
202 testit "$msg - abs symlink outside" \
203 test_count_versions $share bar/letcpasswd $ncopies_blocked || \
204 failed=`expr $failed + 1`
206 testit "$msg - rel symlink outside" \
207 test_count_versions $share bar/loutside $ncopies_blocked || \
208 failed=`expr $failed + 1`
211 test_shadow_copy_everywhere()
213 local share #share to contact
217 #delete snapshots from previous tests
218 find $WORKDIR -name ".snapshots" -exec rm -rf {} \; 1>/dev/null 2>&1
219 build_snapshots "$WORKDIR/mount" "base/share" 0 0
220 build_snapshots "$WORKDIR/mount/base" "share" 1 2
221 build_snapshots "$WORKDIR/mount/base/share" "" 3 5
222 build_snapshots "$WORKDIR/mount/base/share/bar" "" 6 9 1
224 testit "snapshots in each dir - regular file" \
225 test_count_versions $share foo 4 || \
226 failed=`expr $failed + 1`
228 testit "snapshots in each dir - regular file in subdir" \
229 test_count_versions $share bar/baz 5 || \
230 failed=`expr $failed + 1`
232 testit "snapshots in each dir - local symlink (but outside snapshot)" \
233 test_count_versions $share bar/lfoo 1 || \
234 failed=`expr $failed + 1`
236 testit "snapshots in each dir - abs symlink outside" \
237 test_count_versions $share bar/letcpasswd 1 || \
238 failed=`expr $failed + 1`
240 testit "snapshots in each dir - rel symlink outside" \
241 test_count_versions $share bar/loutside 1 || \
242 failed=`expr $failed + 1`
244 #the previous versions of the file bar/lfoo points to are outside its
245 #snapshot, and are not reachable. However, but previous versions
246 #taken at different, non-overlapping times higher up the
247 #hierarchy are still reachable.
248 testit "fetch a previous version of a regular file" \
249 test_fetch_snap_file $share "bar/baz" 6 || \
250 failed=`expr $failed + 1`
252 testit_expect_failure "fetch a (non-existent) previous version of a symlink" \
253 test_fetch_snap_file $share "bar/lfoo" 6 || \
254 failed=`expr $failed + 1`
256 testit "fetch a previous version of a symlink via browsing (1)" \
257 test_fetch_snap_file $share "bar/lfoo" 0 || \
258 failed=`expr $failed + 1`
260 testit "fetch a previous version of a symlink via browsing (2)" \
261 test_fetch_snap_file $share "bar/lfoo" 1 || \
262 failed=`expr $failed + 1`
264 testit "fetch a previous version of a symlink via browsing (3)" \
265 test_fetch_snap_file $share "bar/lfoo" 3 || \
266 failed=`expr $failed + 1`
270 test_shadow_copy_format()
272 local share #share to contact
273 local where #where to place snapshots
274 local prefix #prefix to files inside snapshot
284 #delete snapshots from previous tests
285 find $WORKDIR -name ".snapshots" -exec rm -rf {} \; 1>/dev/null 2>&1
286 build_snapshots $WORKDIR/$where "$prefix" 10 15
288 testit "$msg - regular file" \
289 test_count_versions $share foo $ncopies_allowed || \
290 failed=`expr $failed + 1`
293 #build "latest" files
294 build_files $WORKDIR/mount base/share "latest"
298 # a test with wide links allowed - also to verify that what's later
299 # being blocked is a result of server security measures and not
300 # a testing artifact.
301 test_shadow_copy_fixed shadow_wl mount base/share "shadow copies with wide links allowed" 1
303 # tests for a fixed snapshot location
304 test_shadow_copy_fixed shadow1 mount base/share "full volume snapshots mounted under volume"
305 test_shadow_copy_fixed shadow2 . base/share "full volume snapshots mounted outside volume"
306 test_shadow_copy_fixed shadow3 mount/base share "sub volume snapshots mounted under snapshot point"
307 test_shadow_copy_fixed shadow4 . share "sub volume snapshots mounted outside"
308 test_shadow_copy_fixed shadow5 mount/base/share "" "full volume snapshots and share mounted under volume"
309 test_shadow_copy_fixed shadow6 . "" "full volume snapshots and share mounted outside"
310 test_shadow_copy_fixed shadow8 . share "logical snapshot layout"
312 # tests for snapshot everywhere - one snapshot location
313 test_shadow_copy_fixed shadow7 mount base/share "'everywhere' full volume snapshots"
314 test_shadow_copy_fixed shadow7 mount/base share "'everywhere' sub volume snapshots"
315 test_shadow_copy_fixed shadow7 mount/base/share "" "'everywhere' share snapshots"
317 # a test for snapshots everywhere - multiple snapshot locations
318 test_shadow_copy_everywhere shadow7
320 # tests for testing snapshot selection via shadow:format
321 test_shadow_copy_format shadow_fmt0 mount/base share 3 "basic shadow:format test"
322 test_shadow_copy_format shadow_fmt1 mount/base share 2 "shadow:format with only date"
323 test_shadow_copy_format shadow_fmt2 mount/base share 2 "shadow:format with some prefix"
324 test_shadow_copy_format shadow_fmt3 mount/base share 2 "shadow:format with modified format"