Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for URI parsing. OK markus@
- Loading branch information
millert
committed
Oct 24, 2017
1 parent
b33b385
commit 5d1df19
Showing
4 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |