selftest: Add a blackbox test for smbget
authorChristian Ambach <ambi@samba.org>
Sat, 6 Feb 2016 09:30:29 +0000 (10:30 +0100)
committerChristian Ambach <ambi@samba.org>
Fri, 26 Feb 2016 13:40:54 +0000 (14:40 +0100)
Signed-off-by: Christian Ambach <ambi@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Christian Ambach <ambi@samba.org>
Autobuild-Date(master): Fri Feb 26 14:40:55 CET 2016 on sn-devel-144

selftest/target/Samba3.pm
source3/script/tests/test_smbget.sh [new file with mode: 0755]
source3/selftest/tests.py

index f3d4454ecc36613cfe02522edb7a2c44538ba82f..2dde4ca14a8c9f04c96e2e0b05c0fb402acf4f70 100755 (executable)
@@ -606,6 +606,9 @@ sub setup_fileserver($$)
        my $force_user_valid_users_dir = "$share_dir/force_user_valid_users";
        push(@dirs, $force_user_valid_users_dir);
 
+       my $smbget_sharedir="$share_dir/smbget";
+       push(@dirs,$smbget_sharedir);
+
        my $fileserver_options = "
 [lowercase]
        path = $lower_case_share_dir
@@ -641,7 +644,12 @@ sub setup_fileserver($$)
        force user = force_user
        force group = everyone
        write list = force_user
-       ";
+
+[smbget]
+       path = $smbget_sharedir
+       comment = smb username is [%U]
+       guest ok = yes
+";
 
        my $vars = $self->provision($path,
                                    "FILESERVER",
@@ -1299,6 +1307,7 @@ sub provision($$$$$$$$)
        my ($max_uid, $max_gid);
        my ($uid_nobody, $uid_root, $uid_pdbtest, $uid_pdbtest2, $uid_userdup);
        my ($uid_pdbtest_wkn);
+       my ($uid_smbget);
        my ($uid_force_user);
        my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
        my ($gid_userdup, $gid_everyone);
@@ -1317,6 +1326,7 @@ sub provision($$$$$$$$)
        $uid_userdup = $max_uid - 5;
        $uid_pdbtest_wkn = $max_uid - 6;
        $uid_force_user = $max_uid - 7;
+       $uid_smbget = $max_uid - 8;
 
        if ($unix_gids[0] < 0xffff - 8) {
                $max_gid = 0xffff;
@@ -1697,6 +1707,7 @@ pdbtest2:x:$uid_pdbtest2:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
 userdup:x:$uid_userdup:$gid_userdup:userdup gecos:$prefix_abs:/bin/false
 pdbtest_wkn:x:$uid_pdbtest_wkn:$gid_everyone:pdbtest_wkn gecos:$prefix_abs:/bin/false
 force_user:x:$uid_force_user:$gid_force_user:force user gecos:$prefix_abs:/bin/false
+smbget_user:x:$uid_smbget:$gid_domusers:smbget_user gecos:$prefix_abs:/bin/false
 ";
        if ($unix_uid != 0) {
                print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
@@ -1770,6 +1781,7 @@ force_user:x:$gid_force_user:
 
        createuser($self, $unix_name, $password, $conffile) || die("Unable to create user");
        createuser($self, "force_user", $password, $conffile) || die("Unable to create force_user");
+       createuser($self, "smbget_user", $password, $conffile) || die("Unable to create smbget_user");
 
        open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
        print DNS_UPDATE_LIST "A $server. $server_ip\n";
diff --git a/source3/script/tests/test_smbget.sh b/source3/script/tests/test_smbget.sh
new file mode 100755 (executable)
index 0000000..f21a131
--- /dev/null
@@ -0,0 +1,236 @@
+#!/bin/bash
+#
+# Blackbox test for smbget.
+#
+
+if [ $# -lt 7 ]; then
+cat <<EOF
+Usage: test_smbget SERVER SERVER_IP DOMAIN USERNAME PASSWORD WORKDIR SMBGET
+EOF
+exit 1;
+fi
+
+SERVER=${1}
+SERVER_IP=${2}
+DOMAIN=${3}
+USERNAME=${4}
+PASSWORD=${5}
+WORKDIR=${6}
+SMBGET="$VALGRIND ${7}"
+
+TMPDIR="$SRCDIR_ABS/st/tmp"
+
+incdir=`dirname $0`/../../../testprogs/blackbox
+. $incdir/subunit.sh
+
+create_test_data()
+{
+       pushd $WORKDIR
+       dd if=/dev/urandom bs=1024 count=128 of=testfile
+       chmod 644 testfile
+       mkdir dir1
+       dd if=/dev/urandom bs=1024 count=128 of=dir1/testfile1
+       mkdir dir2
+       dd if=/dev/urandom bs=1024 count=128 of=dir2/testfile2
+       popd
+}
+
+remove_test_data()
+{
+       rm -rf dir1 dir2 testfile
+       pushd $WORKDIR
+       rm -rf dir1 dir2 testfile
+       popd
+}
+
+test_singlefile_guest()
+{
+       [ -e testfile ] && rm testfile
+       echo "$SMBGET -v -a smb://$SERVER_IP/smbget/testfile"
+       $SMBGET -v -a smb://$SERVER_IP/smbget/testfile
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: RC does not match, expected: 0'
+               return 1
+       fi
+       cmp --silent $WORKDIR/testfile ./testfile
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: file content does not match'
+               return 1
+       fi
+       return 0
+}
+
+test_singlefile_U()
+{
+       [ -e testfile ] && rm testfile
+       $SMBGET -v -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/testfile
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: RC does not match, expected: 0'
+               return 1
+       fi
+       cmp --silent $WORKDIR/testfile ./testfile
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: file content does not match'
+               return 1
+       fi
+       return 0
+}
+
+test_singlefile_smburl()
+{
+       [ -e testfile ] && rm testfile
+       $SMBGET -w $DOMAIN smb://$USERNAME:$PASSWORD@$SERVER_IP/smbget/testfile
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: RC does not match, expected: 0'
+               return 1
+       fi
+       cmp --silent $WORKDIR/testfile ./testfile
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: file content does not match'
+               return 1
+       fi
+       return 0
+}
+
+test_singlefile_rcfile()
+{
+       [ -e testfile ] && rm testfile
+       echo "user $USERNAME%$PASSWORD" > $TMPDIR/rcfile
+       $SMBGET -vn -f $TMPDIR/rcfile smb://$SERVER_IP/smbget/testfile
+       rc=$?
+       rm -f $TMPDIR/rcfile
+       if [ $rc -ne 0 ]; then
+               echo 'ERROR: RC does not match, expected: 0'
+               return 1
+       fi
+       cmp --silent $WORKDIR/testfile ./testfile
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: file content does not match'
+               return 1
+       fi
+       return 0
+}
+
+test_recursive_U()
+{
+       [ -e testfile ] && rm testfile
+       [ -d dir1 ] && rm -rf dir1
+       [ -d dir2 ] && rm -rf dir2
+       $SMBGET -v -R -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: RC does not match, expected: 0'
+               return 1
+       fi
+
+       cmp --silent $WORKDIR/testfile ./testfile && \
+       cmp --silent $WORKDIR/dir1/testfile1 ./dir1/testfile1 && \
+       cmp --silent $WORKDIR/dir2/testfile2 ./dir2/testfile2
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: file content does not match'
+               return 1
+       fi
+
+       return 0
+}
+
+test_resume()
+{
+       [ -e testfile ] && rm testfile
+       cp $WORKDIR/testfile .
+       truncate -s 1024 testfile
+       $SMBGET -v -r -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/testfile
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: RC does not match, expected: 0'
+               return 1
+       fi
+
+       cmp --silent $WORKDIR/testfile ./testfile
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: file content does not match'
+               return 1
+       fi
+
+       return 0
+}
+
+test_resume_modified()
+{
+       dd if=/dev/urandom bs=1024 count=2 of=testfile
+       $SMBGET -v -r -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/testfile
+       if [ $? -ne 1 ]; then
+               echo 'ERROR: RC does not match, expected: 1'
+               return 1
+       fi
+
+       return 0
+}
+
+test_update()
+{
+       [ -e testfile ] && rm testfile
+       $SMBGET -v -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/testfile
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: RC does not match, expected: 0'
+               return 1
+       fi
+
+       # secondary download should pass
+       $SMBGET -v -u -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/testfile
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: RC does not match, expected: 0'
+               return 1
+       fi
+
+       echo "modified" >> testfile
+       # touch source to trigger new download
+       sleep 2
+       touch -m $WORKDIR/testfile
+       $SMBGET -v -u -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/testfile
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: RC does not match, expected: 0'
+               return 1
+       fi
+
+       cmp --silent $WORKDIR/testfile ./testfile
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: file content does not match'
+               return 1
+       fi
+
+       return 0
+}
+
+create_test_data
+
+pushd $TMPDIR
+
+failed=0
+testit "download single file as guest" test_singlefile_guest \
+       || failed=`expr $failed + 1`
+
+testit "download single file with -U" test_singlefile_U \
+       || failed=`expr $failed + 1`
+
+testit "download single file with smb URL" test_singlefile_smburl \
+       || failed=`expr $failed + 1`
+
+testit "download single file with rcfile" test_singlefile_rcfile \
+       || failed=`expr $failed + 1`
+
+testit "recursive download" test_recursive_U \
+       || failed=`expr $failed + 1`
+
+testit "resume download" test_resume \
+       || failed=`expr $failed + 1`
+
+testit "resume download (modified file)" test_resume_modified \
+       || failed=`expr $failed + 1`
+
+testit "update" test_update \
+       || failed=`expr $failed + 1`
+
+popd
+
+remove_test_data
+
+exit $failed
index b2bae75e131522f6b3cb632fcb5aa4008338cae5..48e082f82049718aa576b7a73a63a61affdb8e6f 100755 (executable)
@@ -182,6 +182,7 @@ for env in ["fileserver"]:
     plantestsuite("samba3.blackbox.offline (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_offline.sh"), '$SERVER', '$SERVER_IP', '$DOMAIN', '$USERNAME', '$PASSWORD', '$LOCAL_PATH/offline', smbclient3])
     plantestsuite("samba3.blackbox.shadow_copy2 (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_shadow_copy.sh"), '$SERVER', '$SERVER_IP', '$DOMAIN', '$USERNAME', '$PASSWORD', '$LOCAL_PATH/shadow', smbclient3])
     plantestsuite("samba3.blackbox.smbclient.forceuser_validusers (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_forceuser_validusers.sh"), '$SERVER', '$DOMAIN', '$USERNAME', '$PASSWORD', '$LOCAL_PATH', smbclient3])
+    plantestsuite("samba3.blackbox.smbget (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_smbget.sh"), '$SERVER', '$SERVER_IP', '$DOMAIN', 'smbget_user', '$PASSWORD', '$LOCAL_PATH/smbget', smbget])
 
     #
     # tar command tests