Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame^] | 1 | # $OpenBSD: sftp-glob.sh,v 1.4 2009/08/13 01:11:55 djm Exp $ |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
| 4 | tid="sftp glob" |
| 5 | |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 6 | sftp_ls() { |
| 7 | target=$1 |
| 8 | errtag=$2 |
| 9 | expected=$3 |
| 10 | unexpected=$4 |
| 11 | verbose "$tid: $errtag" |
Damien Miller | da1e4bd | 2007-10-26 15:35:54 +1000 | [diff] [blame] | 12 | printf "ls -l %s" "${target}" | \ |
Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame^] | 13 | ${SFTP} -b - -D ${SFTPSERVER} 2>/dev/null | \ |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 14 | grep -v "^sftp>" > ${RESULTS} |
| 15 | if [ $? -ne 0 ]; then |
| 16 | fail "$errtag failed" |
| 17 | fi |
Tim Rice | 68d2938 | 2008-03-07 19:00:33 -0800 | [diff] [blame] | 18 | if test "x$expected" != "x" ; then |
| 19 | if fgrep "$expected" ${RESULTS} >/dev/null 2>&1 ; then |
| 20 | : |
| 21 | else |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 22 | fail "$expected missing from $errtag results" |
Tim Rice | 68d2938 | 2008-03-07 19:00:33 -0800 | [diff] [blame] | 23 | fi |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 24 | fi |
| 25 | if test "x$unexpected" != "x" && \ |
| 26 | fgrep "$unexpected" ${RESULTS} >/dev/null 2>&1 ; then |
| 27 | fail "$unexpected present in $errtag results" |
| 28 | fi |
| 29 | rm -f ${RESULTS} |
| 30 | } |
| 31 | |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 32 | BASE=${OBJ}/glob |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 33 | RESULTS=${OBJ}/results |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 34 | DIR=${BASE}/dir |
| 35 | DATA=${DIR}/file |
| 36 | |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 37 | GLOB1="${DIR}/g-wild*" |
| 38 | GLOB2="${DIR}/g-wildx" |
| 39 | QUOTE="${DIR}/g-quote\"" |
| 40 | SLASH="${DIR}/g-sl\\ash" |
| 41 | ESLASH="${DIR}/g-slash\\" |
| 42 | QSLASH="${DIR}/g-qs\\\"" |
| 43 | SPACE="${DIR}/g-q space" |
| 44 | |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 45 | rm -rf ${BASE} |
| 46 | mkdir -p ${DIR} |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 47 | touch "${DATA}" "${GLOB1}" "${GLOB2}" "${QUOTE}" |
| 48 | touch "${QSLASH}" "${ESLASH}" "${SLASH}" "${SPACE}" |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 49 | |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 50 | # target message expected unexpected |
| 51 | sftp_ls "${DIR}/fil*" "file glob" "${DATA}" "" |
| 52 | sftp_ls "${BASE}/d*" "dir glob" "`basename ${DATA}`" "" |
| 53 | sftp_ls "${DIR}/g-wild\"*\"" "quoted glob" "g-wild*" "g-wildx" |
| 54 | sftp_ls "${DIR}/g-wild\*" "escaped glob" "g-wild*" "g-wildx" |
| 55 | sftp_ls "${DIR}/g-quote\\\"" "escaped quote" "g-quote\"" "" |
| 56 | sftp_ls "\"${DIR}/g-quote\\\"\"" "quoted quote" "g-quote\"" "" |
| 57 | sftp_ls "'${DIR}/g-quote\"'" "single-quoted quote" "g-quote\"" "" |
| 58 | sftp_ls "${DIR}/g-sl\\\\ash" "escaped slash" "g-sl\\ash" "" |
| 59 | sftp_ls "'${DIR}/g-sl\\\\ash'" "quoted slash" "g-sl\\ash" "" |
| 60 | sftp_ls "${DIR}/g-slash\\\\" "escaped slash at EOL" "g-slash\\" "" |
| 61 | sftp_ls "'${DIR}/g-slash\\\\'" "quoted slash at EOL" "g-slash\\" "" |
| 62 | sftp_ls "${DIR}/g-qs\\\\\\\"" "escaped slash+quote" "g-qs\\\"" "" |
| 63 | sftp_ls "'${DIR}/g-qs\\\\\"'" "quoted slash+quote" "g-qs\\\"" "" |
| 64 | sftp_ls "${DIR}/g-q\\ space" "escaped space" "g-q space" "" |
| 65 | sftp_ls "'${DIR}/g-q space'" "quoted space" "g-q space" "" |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 66 | |
| 67 | rm -rf ${BASE} |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 68 | |