Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame^] | 1 | # $OpenBSD: sftp-glob.sh,v 1.2 2007/10/24 03:32:35 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" |
| 12 | $ECHOE "ls -l ${target}" | \ |
| 13 | ${SFTP} -b - -P ${SFTPSERVER} 2>/dev/null | \ |
| 14 | grep -v "^sftp>" > ${RESULTS} |
| 15 | if [ $? -ne 0 ]; then |
| 16 | fail "$errtag failed" |
| 17 | fi |
| 18 | if test "x$expected" != "x" && \ |
| 19 | ! fgrep "$expected" ${RESULTS} >/dev/null 2>&1 ; then |
| 20 | fail "$expected missing from $errtag results" |
| 21 | fi |
| 22 | if test "x$unexpected" != "x" && \ |
| 23 | fgrep "$unexpected" ${RESULTS} >/dev/null 2>&1 ; then |
| 24 | fail "$unexpected present in $errtag results" |
| 25 | fi |
| 26 | rm -f ${RESULTS} |
| 27 | } |
| 28 | |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 29 | BASE=${OBJ}/glob |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame^] | 30 | RESULTS=${OBJ}/results |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 31 | DIR=${BASE}/dir |
| 32 | DATA=${DIR}/file |
| 33 | |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame^] | 34 | GLOB1="${DIR}/g-wild*" |
| 35 | GLOB2="${DIR}/g-wildx" |
| 36 | QUOTE="${DIR}/g-quote\"" |
| 37 | SLASH="${DIR}/g-sl\\ash" |
| 38 | ESLASH="${DIR}/g-slash\\" |
| 39 | QSLASH="${DIR}/g-qs\\\"" |
| 40 | SPACE="${DIR}/g-q space" |
| 41 | |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 42 | rm -rf ${BASE} |
| 43 | mkdir -p ${DIR} |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame^] | 44 | touch "${DATA}" "${GLOB1}" "${GLOB2}" "${QUOTE}" |
| 45 | touch "${QSLASH}" "${ESLASH}" "${SLASH}" "${SPACE}" |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 46 | |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame^] | 47 | # target message expected unexpected |
| 48 | sftp_ls "${DIR}/fil*" "file glob" "${DATA}" "" |
| 49 | sftp_ls "${BASE}/d*" "dir glob" "`basename ${DATA}`" "" |
| 50 | sftp_ls "${DIR}/g-wild\"*\"" "quoted glob" "g-wild*" "g-wildx" |
| 51 | sftp_ls "${DIR}/g-wild\*" "escaped glob" "g-wild*" "g-wildx" |
| 52 | sftp_ls "${DIR}/g-quote\\\"" "escaped quote" "g-quote\"" "" |
| 53 | sftp_ls "\"${DIR}/g-quote\\\"\"" "quoted quote" "g-quote\"" "" |
| 54 | sftp_ls "'${DIR}/g-quote\"'" "single-quoted quote" "g-quote\"" "" |
| 55 | sftp_ls "${DIR}/g-sl\\\\ash" "escaped slash" "g-sl\\ash" "" |
| 56 | sftp_ls "'${DIR}/g-sl\\\\ash'" "quoted slash" "g-sl\\ash" "" |
| 57 | sftp_ls "${DIR}/g-slash\\\\" "escaped slash at EOL" "g-slash\\" "" |
| 58 | sftp_ls "'${DIR}/g-slash\\\\'" "quoted slash at EOL" "g-slash\\" "" |
| 59 | sftp_ls "${DIR}/g-qs\\\\\\\"" "escaped slash+quote" "g-qs\\\"" "" |
| 60 | sftp_ls "'${DIR}/g-qs\\\\\"'" "quoted slash+quote" "g-qs\\\"" "" |
| 61 | sftp_ls "${DIR}/g-q\\ space" "escaped space" "g-q space" "" |
| 62 | sftp_ls "'${DIR}/g-q space'" "quoted space" "g-q space" "" |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 63 | |
| 64 | rm -rf ${BASE} |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame^] | 65 | |