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'
38 # build a hierarchy of files, symlinks, and directories
48 if [ -n "$prefix" ] ; then
49 destdir=$rootdir/$prefix
55 if [ "$version" = "latest" ] ; then
57 # for non-snapshot version, create legit files
58 # so that wide-link checks focus on snapshot files
61 touch $destdir/bar/baz
62 touch $destdir/bar/lfoo
63 touch $destdir/bar/letcpasswd
64 touch $destdir/bar/loutside
65 elif [ "$version" = "fullsnap" ] ; then
69 touch $destdir/bar/baz
70 ln -fs ../foo $destdir/bar/lfoo
71 ln -fs /etc/passwd $destdir/bar/letcpasswd
72 ln -fs ../../outside $destdir/bar/loutside
73 touch `dirname $destdir`/outside
74 else #subshare snapshot - at bar
76 ln -fs ../foo $destdir/lfoo
77 ln -fs /etc/passwd $destdir/letcpasswd
78 ln -fs ../../outside $destdir/loutside
79 touch `dirname $destdir`/../outside
84 # build a snapshots directory
87 local where #where to build snapshots
88 local prefix #prefix from snapshot dir to share root
89 local start #timestamp index of first snapshot
90 local end #timestamp index of last snapshot
91 local sub #creat a snapshot of subtree of share
103 snapdir=$where/.snapshots
107 if [ "$sub" = "1" ] ; then
111 # a valid link target for an inner symlink -
112 # the link is not broken yet should be blocked
113 # by wide link checks
117 for i in `seq $start $end` ; do
118 snapname=${SNAPSHOTS[$i]}
119 mkdir $snapdir/$snapname
120 build_files $snapdir/$snapname "$prefix" $version
124 # Test listing previous versions of a file
125 test_count_versions()
135 versions=`$SMBCLIENT -U$USERNAME%$PASSWORD "//$SERVER/$share" -I $SERVER_IP -c "allinfo $path" | grep "^create_time:" | wc -l`
136 if [ "$versions" = "$expected_count" ] ; then
139 echo "expected $expected_count versions of $path, got $versions"
144 # Test fetching a previous version of a file
145 test_fetch_snap_file()
154 $SMBCLIENT -U$USERNAME%$PASSWORD "//$SERVER/$share" -I $SERVER_IP \
155 -c "get ${SNAPSHOTS[$snapidx]}/$path $WORKDIR/foo"
158 test_shadow_copy_fixed()
160 local share #share to contact
161 local where #where to place snapshots
162 local prefix #prefix to files inside snapshot
166 local ncopies_blocked
176 if [ -n "$allow_wl" ] ; then
180 #delete snapshots from previous tests
181 find $WORKDIR -name ".snapshots" -exec rm -rf {} \; 1>/dev/null 2>&1
182 build_snapshots $WORKDIR/$where "$prefix" 0 2
184 testit "$msg - regular file" \
185 test_count_versions $share foo $ncopies_allowed || \
186 failed=`expr $failed + 1`
188 testit "$msg - regular file in subdir" \
189 test_count_versions $share bar/baz $ncopies_allowed || \
190 failed=`expr $failed + 1`
192 testit "$msg - local symlink" \
193 test_count_versions $share bar/lfoo $ncopies_allowed || \
194 failed=`expr $failed + 1`
196 testit "$msg - abs symlink outside" \
197 test_count_versions $share bar/letcpasswd $ncopies_blocked || \
198 failed=`expr $failed + 1`
200 testit "$msg - rel symlink outside" \
201 test_count_versions $share bar/loutside $ncopies_blocked || \
202 failed=`expr $failed + 1`
205 test_shadow_copy_everywhere()
207 local share #share to contact
211 #delete snapshots from previous tests
212 find $WORKDIR -name ".snapshots" -exec rm -rf {} \; 1>/dev/null 2>&1
213 build_snapshots "$WORKDIR/mount" "base/share" 0 0
214 build_snapshots "$WORKDIR/mount/base" "share" 1 2
215 build_snapshots "$WORKDIR/mount/base/share" "" 3 5
216 build_snapshots "$WORKDIR/mount/base/share/bar" "" 6 9 1
218 testit "snapshots in each dir - regular file" \
219 test_count_versions $share foo 4 || \
220 failed=`expr $failed + 1`
222 testit "snapshots in each dir - regular file in subdir" \
223 test_count_versions $share bar/baz 5 || \
224 failed=`expr $failed + 1`
226 testit "snapshots in each dir - local symlink (but outside snapshot)" \
227 test_count_versions $share bar/lfoo 1 || \
228 failed=`expr $failed + 1`
230 testit "snapshots in each dir - abs symlink outside" \
231 test_count_versions $share bar/letcpasswd 1 || \
232 failed=`expr $failed + 1`
234 testit "snapshots in each dir - rel symlink outside" \
235 test_count_versions $share bar/loutside 1 || \
236 failed=`expr $failed + 1`
238 #the previous versions of the file bar/lfoo points to are outside its
239 #snapshot, and are not reachable. However, but previous versions
240 #taken at different, non-overlapping times higher up the
241 #hierarchy are still reachable.
242 testit "fetch a previous version of a regular file" \
243 test_fetch_snap_file $share "bar/baz" 6 || \
244 failed=`expr $failed + 1`
246 testit_expect_failure "fetch a (non-existent) previous version of a symlink" \
247 test_fetch_snap_file $share "bar/lfoo" 6 || \
248 failed=`expr $failed + 1`
250 testit "fetch a previous version of a symlink via browsing (1)" \
251 test_fetch_snap_file $share "bar/lfoo" 0 || \
252 failed=`expr $failed + 1`
254 testit "fetch a previous version of a symlink via browsing (2)" \
255 test_fetch_snap_file $share "bar/lfoo" 1 || \
256 failed=`expr $failed + 1`
258 testit "fetch a previous version of a symlink via browsing (3)" \
259 test_fetch_snap_file $share "bar/lfoo" 3 || \
260 failed=`expr $failed + 1`
264 #build "latest" files
265 build_files $WORKDIR/mount base/share "latest"
269 # a test with wide links allowed - also to verify that what's later
270 # being blocked is a result of server security measures and not
271 # a testing artifact.
272 test_shadow_copy_fixed shadow_wl mount base/share "shadow copies with wide links allowed" 1
274 # tests for a fixed snapshot location
275 test_shadow_copy_fixed shadow1 mount base/share "full volume snapshots mounted under volume"
276 test_shadow_copy_fixed shadow2 . base/share "full volume snapshots mounted outside volume"
277 test_shadow_copy_fixed shadow3 mount/base share "sub volume snapshots mounted under snapshot point"
278 test_shadow_copy_fixed shadow4 . share "sub volume snapshots mounted outside"
279 test_shadow_copy_fixed shadow5 mount/base/share "" "full volume snapshots and share mounted under volume"
280 test_shadow_copy_fixed shadow6 . "" "full volume snapshots and share mounted outside"
281 test_shadow_copy_fixed shadow8 . share "logical snapshot layout"
283 # tests for snapshot everywhere - one snapshot location
284 test_shadow_copy_fixed shadow7 mount base/share "'everywhere' full volume snapshots"
285 test_shadow_copy_fixed shadow7 mount/base share "'everywhere' sub volume snapshots"
286 test_shadow_copy_fixed shadow7 mount/base/share "" "'everywhere' share snapshots"
288 # a test for snapshots everywhere - multiple snapshot locations
289 test_shadow_copy_everywhere shadow7