xref: /freebsd/crypto/openssh/regress/sftp-glob.sh (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1#	$OpenBSD: sftp-glob.sh,v 1.4 2009/08/13 01:11:55 djm Exp $
2#	Placed in the Public Domain.
3
4tid="sftp glob"
5
6config_defined FILESYSTEM_NO_BACKSLASH && nobs="not supported on this platform"
7
8sftp_ls() {
9	target=$1
10	errtag=$2
11	expected=$3
12	unexpected=$4
13	skip=$5
14	if test "x$skip" != "x" ; then
15		verbose "$tid: $errtag (skipped: $skip)"
16		return
17	fi
18	verbose "$tid: $errtag"
19	printf "ls -l %s" "${target}" | \
20		${SFTP} -b - -D ${SFTPSERVER} 2>/dev/null | \
21		grep -v "^sftp>" > ${RESULTS}
22	if [ $? -ne 0 ]; then
23		fail "$errtag failed"
24	fi
25	if test "x$expected" != "x" ; then
26	    if fgrep "$expected" ${RESULTS} >/dev/null 2>&1 ; then
27		:
28	    else
29		fail "$expected missing from $errtag results"
30	    fi
31	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
39BASE=${OBJ}/glob
40RESULTS=${OBJ}/results
41DIR=${BASE}/dir
42DATA=${DIR}/file
43
44GLOB1="${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
52rm -rf ${BASE}
53mkdir -p ${DIR}
54touch "${DATA}" "${GLOB1}" "${GLOB2}" "${QUOTE}" "${SPACE}"
55test "x$nobs" = "x" && touch "${QSLASH}" "${ESLASH}" "${SLASH}"
56
57#       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\""  ""
65sftp_ls "${DIR}/g-q\\ space"     "escaped space"        "g-q space"  ""
66sftp_ls "'${DIR}/g-q space'"     "quoted space"         "g-q space"  ""
67sftp_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"
73
74rm -rf ${BASE}
75
76