blob: 8d4df2c98b5f2b6fe8dad8924ffa6bf825a46cfa [file] [log] [blame]
Darren Tuckered6b0c52009-10-07 10:43:57 +11001# $OpenBSD: sftp-glob.sh,v 1.4 2009/08/13 01:11:55 djm Exp $
Darren Tucker68f72132005-03-07 18:25:53 +11002# Placed in the Public Domain.
3
4tid="sftp glob"
5
Damien Miller58497782011-01-17 16:17:09 +11006config_defined FILESYSTEM_NO_BACKSLASH && nobs="not supported on this platform"
7
Damien Millerce0e60e2007-10-26 14:54:12 +10008sftp_ls() {
9 target=$1
10 errtag=$2
11 expected=$3
12 unexpected=$4
Damien Miller58497782011-01-17 16:17:09 +110013 skip=$5
14 if test "x$skip" != "x" ; then
15 verbose "$tid: $errtag (skipped: $skip)"
16 return
17 fi
Damien Millerce0e60e2007-10-26 14:54:12 +100018 verbose "$tid: $errtag"
Damien Millerda1e4bd2007-10-26 15:35:54 +100019 printf "ls -l %s" "${target}" | \
Darren Tuckered6b0c52009-10-07 10:43:57 +110020 ${SFTP} -b - -D ${SFTPSERVER} 2>/dev/null | \
Damien Millerce0e60e2007-10-26 14:54:12 +100021 grep -v "^sftp>" > ${RESULTS}
22 if [ $? -ne 0 ]; then
23 fail "$errtag failed"
24 fi
Tim Rice68d29382008-03-07 19:00:33 -080025 if test "x$expected" != "x" ; then
26 if fgrep "$expected" ${RESULTS} >/dev/null 2>&1 ; then
27 :
28 else
Damien Millerce0e60e2007-10-26 14:54:12 +100029 fail "$expected missing from $errtag results"
Tim Rice68d29382008-03-07 19:00:33 -080030 fi
Damien Millerce0e60e2007-10-26 14:54:12 +100031 fi
32 if test "x$unexpected" != "x" && \
33 fgrep "$unexpected" ${RESULTS} >/dev/null 2>&1 ; then
34 fail "$unexpected present in $errtag results"
35 fi
36 rm -f ${RESULTS}
37}
38
Darren Tucker68f72132005-03-07 18:25:53 +110039BASE=${OBJ}/glob
Damien Millerce0e60e2007-10-26 14:54:12 +100040RESULTS=${OBJ}/results
Darren Tucker68f72132005-03-07 18:25:53 +110041DIR=${BASE}/dir
42DATA=${DIR}/file
43
Damien Millerce0e60e2007-10-26 14:54:12 +100044GLOB1="${DIR}/g-wild*"
45GLOB2="${DIR}/g-wildx"
46QUOTE="${DIR}/g-quote\""
47SLASH="${DIR}/g-sl\\ash"
48ESLASH="${DIR}/g-slash\\"
49QSLASH="${DIR}/g-qs\\\""
50SPACE="${DIR}/g-q space"
51
Darren Tucker68f72132005-03-07 18:25:53 +110052rm -rf ${BASE}
53mkdir -p ${DIR}
Damien Miller58497782011-01-17 16:17:09 +110054touch "${DATA}" "${GLOB1}" "${GLOB2}" "${QUOTE}" "${SPACE}"
55test "x$nobs" = "x" && touch "${QSLASH}" "${ESLASH}" "${SLASH}"
Darren Tucker68f72132005-03-07 18:25:53 +110056
Damien Millerce0e60e2007-10-26 14:54:12 +100057# target message expected unexpected
58sftp_ls "${DIR}/fil*" "file glob" "${DATA}" ""
59sftp_ls "${BASE}/d*" "dir glob" "`basename ${DATA}`" ""
60sftp_ls "${DIR}/g-wild\"*\"" "quoted glob" "g-wild*" "g-wildx"
61sftp_ls "${DIR}/g-wild\*" "escaped glob" "g-wild*" "g-wildx"
62sftp_ls "${DIR}/g-quote\\\"" "escaped quote" "g-quote\"" ""
63sftp_ls "\"${DIR}/g-quote\\\"\"" "quoted quote" "g-quote\"" ""
64sftp_ls "'${DIR}/g-quote\"'" "single-quoted quote" "g-quote\"" ""
Damien Millerce0e60e2007-10-26 14:54:12 +100065sftp_ls "${DIR}/g-q\\ space" "escaped space" "g-q space" ""
66sftp_ls "'${DIR}/g-q space'" "quoted space" "g-q space" ""
Damien Miller58497782011-01-17 16:17:09 +110067sftp_ls "${DIR}/g-sl\\\\ash" "escaped slash" "g-sl\\ash" "" "$nobs"
68sftp_ls "'${DIR}/g-sl\\\\ash'" "quoted slash" "g-sl\\ash" "" "$nobs"
69sftp_ls "${DIR}/g-slash\\\\" "escaped slash at EOL" "g-slash\\" "" "$nobs"
70sftp_ls "'${DIR}/g-slash\\\\'" "quoted slash at EOL" "g-slash\\" "" "$nobs"
71sftp_ls "${DIR}/g-qs\\\\\\\"" "escaped slash+quote" "g-qs\\\"" "" "$nobs"
72sftp_ls "'${DIR}/g-qs\\\\\"'" "quoted slash+quote" "g-qs\\\"" "" "$nobs"
Darren Tucker68f72132005-03-07 18:25:53 +110073
74rm -rf ${BASE}
Damien Millerce0e60e2007-10-26 14:54:12 +100075