Skip to content

Commit

Permalink
Add tests for URI parsing. OK markus@
Browse files Browse the repository at this point in the history
  • Loading branch information
millert committed Oct 24, 2017
1 parent b33b385 commit 5d1df19
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
@@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.95 2017/06/24 06:35:24 djm Exp $
# $OpenBSD: Makefile,v 1.96 2017/10/24 19:33:32 millert Exp $

.ifndef SKIP_UNIT
SUBDIR= unittests
Expand All @@ -11,6 +11,7 @@ REGRESS_TARGETS= t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
LTESTS= connect \
proxy-connect \
connect-privsep \
connect-uri \
proto-version \
proto-mismatch \
exit-status \
Expand All @@ -35,13 +36,15 @@ LTESTS= connect \
keygen-moduli \
key-options \
scp \
scp-uri \
sftp \
sftp-chroot \
sftp-cmds \
sftp-badcmds \
sftp-batch \
sftp-glob \
sftp-perm \
sftp-uri \
reconfigure \
dynamic-forward \
forwarding \
Expand Down
29 changes: 29 additions & 0 deletions connect-uri.sh
@@ -0,0 +1,29 @@
# $OpenBSD: connect-uri.sh,v 1.1 2017/10/24 19:33:32 millert Exp $
# Placed in the Public Domain.

tid="uri connect"

# Remove Port and User from ssh_config, we want to rely on the URI
cp $OBJ/ssh_config $OBJ/ssh_config.orig
egrep -v '^ +(Port|User) +.*$' $OBJ/ssh_config.orig > $OBJ/ssh_config

start_sshd

verbose "$tid: no trailing slash"
${SSH} -F $OBJ/ssh_config "ssh://${USER}@somehost:${PORT}" true
if [ $? -ne 0 ]; then
fail "ssh connection failed"
fi

verbose "$tid: trailing slash"
${SSH} -F $OBJ/ssh_config "ssh://${USER}@somehost:${PORT}/" true
if [ $? -ne 0 ]; then
fail "ssh connection failed"
fi

verbose "$tid: with path name"
${SSH} -F $OBJ/ssh_config "ssh://${USER}@somehost:${PORT}/${DATA}" true \
> /dev/null 2>&1
if [ $? -eq 0 ]; then
fail "ssh connection succeeded, expected failure"
fi
66 changes: 66 additions & 0 deletions scp-uri.sh
@@ -0,0 +1,66 @@
# $OpenBSD: scp-uri.sh,v 1.1 2017/10/24 19:33:32 millert Exp $
# Placed in the Public Domain.

tid="scp-uri"

#set -x

COPY2=${OBJ}/copy2
DIR=${COPY}.dd
DIR2=${COPY}.dd2

SRC=`dirname ${SCRIPT}`
cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp
chmod 755 ${OBJ}/scp-ssh-wrapper.scp
scpopts="-q -S ${OBJ}/scp-ssh-wrapper.scp"
export SCP # used in scp-ssh-wrapper.scp

scpclean() {
rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2}
mkdir ${DIR} ${DIR2}
}

# Remove Port and User from ssh_config, we want to rely on the URI
cp $OBJ/ssh_config $OBJ/ssh_config.orig
egrep -v '^ +(Port|User) +.*$' $OBJ/ssh_config.orig > $OBJ/ssh_config

verbose "$tid: simple copy local file to remote file"
scpclean
$SCP $scpopts ${DATA} "scp://${USER}@somehost:${PORT}/${COPY}" || fail "copy failed"
cmp ${DATA} ${COPY} || fail "corrupted copy"

verbose "$tid: simple copy remote file to local file"
scpclean
$SCP $scpopts "scp://${USER}@somehost:${PORT}/${DATA}" ${COPY} || fail "copy failed"
cmp ${DATA} ${COPY} || fail "corrupted copy"

verbose "$tid: simple copy local file to remote dir"
scpclean
cp ${DATA} ${COPY}
$SCP $scpopts ${COPY} "scp://${USER}@somehost:${PORT}/${DIR}" || fail "copy failed"
cmp ${COPY} ${DIR}/copy || fail "corrupted copy"

verbose "$tid: simple copy remote file to local dir"
scpclean
cp ${DATA} ${COPY}
$SCP $scpopts "scp://${USER}@somehost:${PORT}/${COPY}" ${DIR} || fail "copy failed"
cmp ${COPY} ${DIR}/copy || fail "corrupted copy"

verbose "$tid: recursive local dir to remote dir"
scpclean
rm -rf ${DIR2}
cp ${DATA} ${DIR}/copy
$SCP $scpopts -r ${DIR} "scp://${USER}@somehost:${PORT}/${DIR2}" || fail "copy failed"
diff -rN ${DIR} ${DIR2} || fail "corrupted copy"

verbose "$tid: recursive remote dir to local dir"
scpclean
rm -rf ${DIR2}
cp ${DATA} ${DIR}/copy
$SCP $scpopts -r "scp://${USER}@somehost:${PORT}/${DIR}" ${DIR2} || fail "copy failed"
diff -rN ${DIR} ${DIR2} || fail "corrupted copy"

# TODO: scp -3

scpclean
rm -f ${OBJ}/scp-ssh-wrapper.exe
63 changes: 63 additions & 0 deletions sftp-uri.sh
@@ -0,0 +1,63 @@
# $OpenBSD: sftp-uri.sh,v 1.1 2017/10/24 19:33:32 millert Exp $
# Placed in the Public Domain.

tid="sftp-uri"

#set -x

COPY2=${OBJ}/copy2
DIR=${COPY}.dd
DIR2=${COPY}.dd2
SRC=`dirname ${SCRIPT}`

sftpclean() {
rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2}
mkdir ${DIR} ${DIR2}
}

start_sshd -oForceCommand="internal-sftp -d /"

# Remove Port and User from ssh_config, we want to rely on the URI
cp $OBJ/ssh_config $OBJ/ssh_config.orig
egrep -v '^ +(Port|User) +.*$' $OBJ/ssh_config.orig > $OBJ/ssh_config

verbose "$tid: non-interactive fetch to local file"
sftpclean
${SFTP} -q -S "$SSH" -F $OBJ/ssh_config "sftp://${USER}@somehost:${PORT}/${DATA}" ${COPY} || fail "copy failed"
cmp ${DATA} ${COPY} || fail "corrupted copy"

verbose "$tid: non-interactive fetch to local dir"
sftpclean
cp ${DATA} ${COPY}
${SFTP} -q -S "$SSH" -F $OBJ/ssh_config "sftp://${USER}@somehost:${PORT}/${COPY}" ${DIR} || fail "copy failed"
cmp ${COPY} ${DIR}/copy || fail "corrupted copy"

verbose "$tid: put to remote directory (trailing slash)"
sftpclean
${SFTP} -q -S "$SSH" -F $OBJ/ssh_config -b /dev/stdin \
"sftp://${USER}@somehost:${PORT}/${DIR}/" > /dev/null 2>&1 << EOF
version
put ${DATA} copy
EOF
r=$?
if [ $r -ne 0 ]; then
fail "sftp failed with $r"
else
cmp ${DATA} ${DIR}/copy || fail "corrupted copy"
fi

verbose "$tid: put to remote directory (no slash)"
sftpclean
${SFTP} -q -S "$SSH" -F $OBJ/ssh_config -b /dev/stdin \
"sftp://${USER}@somehost:${PORT}/${DIR}" > /dev/null 2>&1 << EOF
version
put ${DATA} copy
EOF
r=$?
if [ $r -ne 0 ]; then
fail "sftp failed with $r"
else
cmp ${DATA} ${DIR}/copy || fail "corrupted copy"
fi

sftpclean

0 comments on commit 5d1df19

Please sign in to comment.