diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2007-10-24 03:32:36 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2007-10-24 03:32:36 +0000 |
commit | 900381cff4b0e8783050404f320fd3057dc97ed3 (patch) | |
tree | 8c5ce9b2b3a5499715fcef1199c8b11302f9ecc4 | |
parent | b4e6e72846afcda93375d07de10f20153550a966 (diff) |
comprehensive tests for sftp escaping its interaction with globbing;
ok dtucker@
-rw-r--r-- | regress/usr.bin/ssh/sftp-cmds.sh | 45 | ||||
-rw-r--r-- | regress/usr.bin/ssh/sftp-glob.sh | 69 | ||||
-rw-r--r-- | regress/usr.bin/ssh/test-exec.sh | 19 |
3 files changed, 99 insertions, 34 deletions
diff --git a/regress/usr.bin/ssh/sftp-cmds.sh b/regress/usr.bin/ssh/sftp-cmds.sh index 736f3651006..9414573e60c 100644 --- a/regress/usr.bin/ssh/sftp-cmds.sh +++ b/regress/usr.bin/ssh/sftp-cmds.sh @@ -1,4 +1,4 @@ -# $OpenBSD: sftp-cmds.sh,v 1.7 2006/08/29 09:44:00 djm Exp $ +# $OpenBSD: sftp-cmds.sh,v 1.8 2007/10/24 03:32:35 djm Exp $ # Placed in the Public Domain. # XXX - TODO: @@ -14,6 +14,11 @@ GLOBFILES=`(cd /bin;echo l*)` # Path with embedded quote QUOTECOPY=${COPY}".\"blah\"" QUOTECOPY_ARG=${COPY}'.\"blah\"' +# File with spaces +SPACECOPY="${COPY} this has spaces.txt" +SPACECOPY_ARG="${COPY}\ this\ has\ spaces.txt" +# File with glob metacharacters +GLOBMETACOPY="${COPY} [metachar].txt" rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2 ${BATCH}.* mkdir ${COPY}.dd @@ -69,10 +74,25 @@ rm -f ${QUOTECOPY} cp $DATA ${QUOTECOPY} verbose "$tid: get filename with quotes" echo "get \"$QUOTECOPY_ARG\" ${COPY}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ - || fail "put failed" + || fail "get failed" cmp ${COPY} ${QUOTECOPY} || fail "corrupted copy after get with quotes" rm -f ${QUOTECOPY} ${COPY} +rm -f "$SPACECOPY" ${COPY} +cp $DATA "$SPACECOPY" +verbose "$tid: get filename with spaces" +echo "get ${SPACECOPY_ARG} ${COPY}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ + || fail "get failed" +cmp ${COPY} "$SPACECOPY" || fail "corrupted copy after get with spaces" + +rm -f "$GLOBMETACOPY" ${COPY} +cp $DATA "$GLOBMETACOPY" +verbose "$tid: get filename with glob metacharacters" +echo "get \"${GLOBMETACOPY}\" ${COPY}" | \ + ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || fail "get failed" +cmp ${COPY} "$GLOBMETACOPY" || \ + fail "corrupted copy after get with glob metacharacters" + rm -f ${COPY}.dd/* verbose "$tid: get to directory" echo "get $DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ @@ -103,16 +123,22 @@ done rm -f ${COPY} verbose "$tid: put" -echo "put $DATA $COPY" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ - || fail "put failed" +echo "put $DATA $COPY" | \ + ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed" cmp $DATA ${COPY} || fail "corrupted copy after put" rm -f ${QUOTECOPY} verbose "$tid: put filename with quotes" -echo "put $DATA \"$QUOTECOPY_ARG\"" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ - || fail "put failed" +echo "put $DATA \"$QUOTECOPY_ARG\"" | \ + ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed" cmp $DATA ${QUOTECOPY} || fail "corrupted copy after put with quotes" +rm -f "$SPACECOPY" +verbose "$tid: put filename with spaces" +echo "put $DATA ${SPACECOPY_ARG}" | \ + ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed" +cmp $DATA "$SPACECOPY" || fail "corrupted copy after put with spaces" + rm -f ${COPY}.dd/* verbose "$tid: put to directory" echo "put $DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ @@ -148,8 +174,9 @@ test -f ${COPY}.1 || fail "missing file after rename" cmp $DATA ${COPY}.1 >/dev/null 2>&1 || fail "corrupted copy after rename" verbose "$tid: rename directory" -echo "rename ${COPY}.dd ${COPY}.dd2" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ - || fail "rename directory failed" +echo "rename ${COPY}.dd ${COPY}.dd2" | \ + ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || \ + fail "rename directory failed" test -d ${COPY}.dd && fail "oldname exists after rename directory" test -d ${COPY}.dd2 || fail "missing newname after rename directory" @@ -183,6 +210,6 @@ echo "lchdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ || fail "lchdir failed" rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2 ${BATCH}.* -rm -rf ${QUOTECOPY} +rm -rf ${QUOTECOPY} "$SPACECOPY" "$GLOBMETACOPY" diff --git a/regress/usr.bin/ssh/sftp-glob.sh b/regress/usr.bin/ssh/sftp-glob.sh index e238356a21f..d5ebf9fd6d5 100644 --- a/regress/usr.bin/ssh/sftp-glob.sh +++ b/regress/usr.bin/ssh/sftp-glob.sh @@ -1,28 +1,65 @@ -# $OpenBSD: sftp-glob.sh,v 1.1 2004/12/10 01:31:30 fgsch Exp $ +# $OpenBSD: sftp-glob.sh,v 1.2 2007/10/24 03:32:35 djm Exp $ # Placed in the Public Domain. tid="sftp glob" +sftp_ls() { + target=$1 + errtag=$2 + expected=$3 + unexpected=$4 + verbose "$tid: $errtag" + $ECHOE "ls -l ${target}" | \ + ${SFTP} -b - -P ${SFTPSERVER} 2>/dev/null | \ + grep -v "^sftp>" > ${RESULTS} + if [ $? -ne 0 ]; then + fail "$errtag failed" + fi + if test "x$expected" != "x" && \ + ! fgrep "$expected" ${RESULTS} >/dev/null 2>&1 ; then + fail "$expected missing from $errtag results" + fi + if test "x$unexpected" != "x" && \ + fgrep "$unexpected" ${RESULTS} >/dev/null 2>&1 ; then + fail "$unexpected present in $errtag results" + fi + rm -f ${RESULTS} +} + BASE=${OBJ}/glob +RESULTS=${OBJ}/results DIR=${BASE}/dir DATA=${DIR}/file +GLOB1="${DIR}/g-wild*" +GLOB2="${DIR}/g-wildx" +QUOTE="${DIR}/g-quote\"" +SLASH="${DIR}/g-sl\\ash" +ESLASH="${DIR}/g-slash\\" +QSLASH="${DIR}/g-qs\\\"" +SPACE="${DIR}/g-q space" + rm -rf ${BASE} mkdir -p ${DIR} -touch ${DATA} - -verbose "$tid: ls file" -echo "ls -l ${DIR}/fil*" | ${SFTP} -P ${SFTPSERVER} 2>/dev/null | \ - grep ${DATA} >/dev/null 2>&1 -if [ $? -ne 0 ]; then - fail "globbed ls file failed" -fi - -verbose "$tid: ls dir" -echo "ls -l ${BASE}/d*" | ${SFTP} -P ${SFTPSERVER} 2>/dev/null | \ - grep file >/dev/null 2>&1 -if [ $? -ne 0 ]; then - fail "globbed ls dir failed" -fi +touch "${DATA}" "${GLOB1}" "${GLOB2}" "${QUOTE}" +touch "${QSLASH}" "${ESLASH}" "${SLASH}" "${SPACE}" + +# target message expected unexpected +sftp_ls "${DIR}/fil*" "file glob" "${DATA}" "" +sftp_ls "${BASE}/d*" "dir glob" "`basename ${DATA}`" "" +sftp_ls "${DIR}/g-wild\"*\"" "quoted glob" "g-wild*" "g-wildx" +sftp_ls "${DIR}/g-wild\*" "escaped glob" "g-wild*" "g-wildx" +sftp_ls "${DIR}/g-quote\\\"" "escaped quote" "g-quote\"" "" +sftp_ls "\"${DIR}/g-quote\\\"\"" "quoted quote" "g-quote\"" "" +sftp_ls "'${DIR}/g-quote\"'" "single-quoted quote" "g-quote\"" "" +sftp_ls "${DIR}/g-sl\\\\ash" "escaped slash" "g-sl\\ash" "" +sftp_ls "'${DIR}/g-sl\\\\ash'" "quoted slash" "g-sl\\ash" "" +sftp_ls "${DIR}/g-slash\\\\" "escaped slash at EOL" "g-slash\\" "" +sftp_ls "'${DIR}/g-slash\\\\'" "quoted slash at EOL" "g-slash\\" "" +sftp_ls "${DIR}/g-qs\\\\\\\"" "escaped slash+quote" "g-qs\\\"" "" +sftp_ls "'${DIR}/g-qs\\\\\"'" "quoted slash+quote" "g-qs\\\"" "" +sftp_ls "${DIR}/g-q\\ space" "escaped space" "g-q space" "" +sftp_ls "'${DIR}/g-q space'" "quoted space" "g-q space" "" rm -rf ${BASE} + diff --git a/regress/usr.bin/ssh/test-exec.sh b/regress/usr.bin/ssh/test-exec.sh index b4e42e17477..9803657fabf 100644 --- a/regress/usr.bin/ssh/test-exec.sh +++ b/regress/usr.bin/ssh/test-exec.sh @@ -1,8 +1,9 @@ -# $OpenBSD: test-exec.sh,v 1.28 2005/05/20 23:14:15 djm Exp $ +# $OpenBSD: test-exec.sh,v 1.29 2007/10/24 03:32:35 djm Exp $ # Placed in the Public Domain. USER=`id -un` #SUDO=sudo +ECHOE="echo -E" if [ ! -z "$TEST_SSH_PORT" ]; then PORT="$TEST_SSH_PORT" @@ -109,32 +110,32 @@ cleanup () trace () { - echo "trace: $@" >>$TEST_SSH_LOGFILE + $ECHOE "trace: $@" >>$TEST_SSH_LOGFILE if [ "X$TEST_SSH_TRACE" = "Xyes" ]; then - echo "$@" + $ECHOE "$@" fi } verbose () { - echo "verbose: $@" >>$TEST_SSH_LOGFILE + $ECHOE "verbose: $@" >>$TEST_SSH_LOGFILE if [ "X$TEST_SSH_QUIET" != "Xyes" ]; then - echo "$@" + $ECHOE "$@" fi } fail () { - echo "FAIL: $@" >>$TEST_SSH_LOGFILE + $ECHOE "FAIL: $@" >>$TEST_SSH_LOGFILE RESULT=1 - echo "$@" + $ECHOE "$@" } fatal () { - echo "FATAL: $@" >>$TEST_SSH_LOGFILE - echo -n "FATAL: " + $ECHOE "FATAL: $@" >>$TEST_SSH_LOGFILE + $ECHOE -n "FATAL: " fail "$@" cleanup exit $RESULT |