From c2f7030033b497593a296accdbc581f896a01103 Mon Sep 17 00:00:00 2001 From: "Salvador I. Gonzalez" Date: Sun, 12 Aug 2012 13:53:21 -0400 Subject: [PATCH 4/4] * Do not use /tmp for file storage * Utilize the local path variable to get files on 'client' * Also check data integrity * Test both create (-Tc) and extract (-Tx) --- source3/script/tests/test_smbclient_tarmode.sh | 75 ++++++++++++++++++------ source3/selftest/tests.py | 3 +- 2 files changed, 58 insertions(+), 20 deletions(-) diff --git a/source3/script/tests/test_smbclient_tarmode.sh b/source3/script/tests/test_smbclient_tarmode.sh index 81412b5..e67d93f 100755 --- a/source3/script/tests/test_smbclient_tarmode.sh +++ b/source3/script/tests/test_smbclient_tarmode.sh @@ -1,10 +1,15 @@ #!/bin/sh +have_command() { + type "$1" > /dev/null 2>&1 + return $? +} + # this runs a simple tarmode test if [ $# -lt 4 ]; then cat < +Usage: test_smbclient_tarmode.sh SERVER SERVER_IP USERNAME PASSWORD LOCAL_PATH PREFIX SMBCLIENT [create|extract] EOF exit 1; fi @@ -13,45 +18,77 @@ SERVER="$1" SERVER_IP="$2" USERNAME="$3" PASSWORD="$4" -SMBCLIENT="$5" +LOCAL_PATH="$5" +PREFIX="$6" +SMBCLIENT="$7" SMBCLIENT="$VALGRIND ${SMBCLIENT}" -shift 5 +TYPE="$8" +shift 8 ADDARGS="$*" incdir=`dirname $0`/../../../testprogs/blackbox . $incdir/subunit.sh + + # Build a quick Dir structure -TEMPDIR="/tmp" TESTDIR="tarmode.test.$$" -mkdir -p "/tmp/$TESTDIR" +mkdir -p "$PREFIX/$TESTDIR" NUM_TEST_FILES=10 -if od --version > /dev/null 2>&1; then # Use random file sizes +if have_command "od"; then # Use random file sizes I=1 for RND in `od -An -N$NUM_TEST_FILES -tu1 < /dev/urandom`; do - dd if=/dev/urandom of="$TEMPDIR/$TESTDIR/test.dat.$I" bs=1024 count=$RND + dd if=/dev/urandom of="$PREFIX/$TESTDIR/test.dat.$I" bs=1024 count=$RND || exit 1 I=`expr $I + 1` done else # Fallback to same file sizes I=1 while [ $I -le $NUM_TEST_FILES ]; do - dd if=/dev/urandom of="$TEMPDIR/$TESTDIR/test.dat.$I" bs=1024 count=25 + dd if=/dev/urandom of="$PREFIX/$TESTDIR/test.dat.$I" bs=1024 count=25 || exit 1 I=`expr $I + 1` done fi -# Upload to server -( cd $TMPDIR && \ - $SMBCLIENT //$SERVER/c$ $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 \ - -c "recurse;prompt;mput $TESTDIR" ) +tar -cf $PREFIX/${TESTDIR}.tar || exit 1 + +GOOD_HASH="" +TEST_HASH="" + +if have_command "sha1sum"; then + GOOD_HASH="$( sha1sum -b $PREFIX/${TESTDIR}.tar | cut -d\ -f1 )" +elif have_command "md5sum"; then + GOOD_HASH="$( md5sum -b $PREFIX/${TESTDIR}.tar | cut -d\ -f1 )" +fi + +if [ "$TYPE" == "create" ]; then # Run tarmode creation test + # Put on 'client' + cp -a $PREFIX/$TESTDIR $LOCAL_PATH/$TESTDIR || exit 1 + + testit "smbclient //$SERVER/c$ tarmode" $SMBCLIENT //$SERVER/c$ $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 \ + -c "tarmode full" -Tc $PREFIX/tarmode-create.$$.tar "/$TESTDIR" $ADDARGS + + if have_command "sha1sum"; then + TEST_HASH="$( sha1sum -b $PREFIX/tarmode-create.$$.tar | cut -d\ -f1 )" + elif have_command "md5sum"; then + TEST_HASH="$( md5sum -b $PREFIX/tarmode-create.$$.tar | cut -d\ -f1 )" + fi -testit "smbclient //$SERVER/c$ tarmode" $SMBCLIENT //$SERVER/c$ $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 \ - -c "tarmode full" -Tc /dev/null "/$TESTDIR" $ADDARGS + # Test whether data is equivalent + testit "[ \"$TEST_HASH\" -- \"$GOOD_HASH\" ]" +else # Run tarmode extraction test + testit "smbclient //$SERVER/c$ tarmode" $SMBCLIENT //$SERVER/c$ $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 \ + -c "tarmode full" -Tx $PREFIX/${TESTDIR}.tar $ADDARGS + + if have_command "sha1sum"; then + TEST_HASH="$( tar -cf - -C $LOCAL_PATH $TESTDIR | sha1sum -b | cut -d\ -f1 )" + elif have_command "md5sum"; then + TEST_HASH="$( tar -cf - -C $LOCAL_PATH $TESTDIR | md5sum -b | cut -d\ -f1 )" + fi + + # Test whether data is equivalent + testit "[ \"$TEST_HASH\" -- \"$GOOD_HASH\" ]" +fi # Cleanup our mess. FIXME: Will this run if the test fails? -rm -rf -- "$TMPDIR/$TESTDIR" -$SMBCLIENT //$SERVER/c$ $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 \ - -D "$TESTDIR" -c "del *" -$SMBCLIENT //$SERVER/c$ $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 \ - -c "rd $TESTDIR" +rm -rf -- "$PREFIX/$TESTDIR" "$LOCAL_PATH/$TESTDIR" "$PREFIX/tarmode-create.$$.tar" diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index f28293d..30f12db 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -209,7 +209,8 @@ for env in ["s3dc"]: # Test smbclient/tarmode for env in [""]: - plantestsuite("samba3.blackbox.smbclient_tarmode (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_smbclient_tarmode.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', smbclient, configuration]) + for tarmode_test in [ "create", "extract" ]: + plantestsuite("samba3.blackbox.smbclient_tarmode (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_smbclient_tarmode.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', '$LOCAL_PATH', '$PREFIX', smbclient, tarmode_test, configuration]) #TODO encrypted against member, with member creds, and with DC creds plantestsuite("samba3.blackbox.net.misc", "s3dc:local", -- 1.7.8.6