summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2023-01-06 08:07:39 +0000
committerDarren Tucker <dtucker@dtucker.net>2023-01-06 21:37:40 +1100
commite1ef172646f7f49c80807eea90225ef5e0be55a8 (patch)
tree2d506f35943997de2796b145a37d7b6f972f6517 /regress
parent2393ea8daf25853459eb07a528d7577688847777 (diff)
downloadopenssh-git-e1ef172646f7f49c80807eea90225ef5e0be55a8.tar.gz
upstream: regression test for ChannelTimeout
OpenBSD-Regress-ID: 280bfbefcfa415428ad744e43f69a8dede8ad685
Diffstat (limited to 'regress')
-rw-r--r--regress/Makefile7
-rw-r--r--regress/channel-timeout.sh91
2 files changed, 95 insertions, 3 deletions
diff --git a/regress/Makefile b/regress/Makefile
index e5377d41..e78e11b7 100644
--- a/regress/Makefile
+++ b/regress/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.121 2022/12/01 02:22:13 dtucker Exp $
+# $OpenBSD: Makefile,v 1.122 2023/01/06 08:07:39 djm Exp $
tests: prep file-tests t-exec unit
@@ -101,7 +101,8 @@ LTESTS= connect \
knownhosts \
knownhosts-command \
agent-restrict \
- hostbased
+ hostbased \
+ channel-timeout
INTEROP_TESTS= putty-transfer putty-ciphers putty-kex conch-ciphers
#INTEROP_TESTS+=ssh-com ssh-com-client ssh-com-keygen ssh-com-sftp
@@ -129,7 +130,7 @@ CLEANFILES= *.core actual agent-key.* authorized_keys_${USERNAME} \
rsa_ssh2_crnl.prv scp-ssh-wrapper.exe \
scp-ssh-wrapper.scp setuid-allowed sftp-server.log \
sftp-server.sh sftp.log ssh-log-wrapper.sh ssh.log \
- ssh-agent.log ssh-add.log \
+ ssh-agent.log ssh-add.log slow-sftp-server.sh \
ssh-rsa_oldfmt knownhosts_command \
ssh_config ssh_config.* ssh_proxy ssh_proxy_bak \
ssh_proxy_* sshd.log sshd_config sshd_config.* \
diff --git a/regress/channel-timeout.sh b/regress/channel-timeout.sh
new file mode 100644
index 00000000..1c42e832
--- /dev/null
+++ b/regress/channel-timeout.sh
@@ -0,0 +1,91 @@
+# $OpenBSD: channel-timeout.sh,v 1.1 2023/01/06 08:07:39 djm Exp $
+# Placed in the Public Domain.
+
+tid="channel timeout"
+
+# XXX not comprehensive. Still need -R -L agent X11 forwarding + interactive
+
+rm -f $OBJ/sshd_proxy.orig
+cp $OBJ/sshd_proxy $OBJ/sshd_proxy.orig
+
+verbose "no timeout"
+${SSH} -F $OBJ/ssh_proxy somehost "sleep 5 ; exit 23"
+r=$?
+if [ $r -ne 23 ]; then
+ fail "ssh failed"
+fi
+
+verbose "command timeout"
+(cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:command=1") \
+ > $OBJ/sshd_proxy
+${SSH} -F $OBJ/ssh_proxy somehost "sleep 5 ; exit 23"
+r=$?
+if [ $r -ne 255 ]; then
+ fail "ssh returned unexpected error code $r"
+fi
+
+verbose "command wildcard timeout"
+(cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:*=1") \
+ > $OBJ/sshd_proxy
+${SSH} -F $OBJ/ssh_proxy somehost "sleep 5 ; exit 23"
+r=$?
+if [ $r -ne 255 ]; then
+ fail "ssh returned unexpected error code $r"
+fi
+
+verbose "command irrelevant timeout"
+(cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:shell=1") \
+ > $OBJ/sshd_proxy
+${SSH} -F $OBJ/ssh_proxy somehost "sleep 5 ; exit 23"
+r=$?
+if [ $r -ne 23 ]; then
+ fail "ssh failed"
+fi
+
+# Set up a "slow sftp server" that sleeps before executing the real one.
+cat > $OBJ/slow-sftp-server.sh << _EOF
+#!/bin/sh
+
+sleep 5
+$SFTPSERVER
+_EOF
+chmod a+x $OBJ/slow-sftp-server.sh
+
+verbose "sftp no timeout"
+(grep -vi subsystem.*sftp $OBJ/sshd_proxy.orig;
+ echo "Subsystem sftp $OBJ/slow-sftp-server.sh" ) > $OBJ/sshd_proxy
+
+rm -f ${COPY}
+$SFTP -qS $SSH -F $OBJ/ssh_proxy somehost:$DATA $COPY
+r=$?
+if [ $r -ne 0 ]; then
+ fail "sftp failed"
+fi
+cmp $DATA $COPY || fail "corrupted copy"
+
+verbose "sftp timeout"
+(grep -vi subsystem.*sftp $OBJ/sshd_proxy.orig;
+ echo "ChannelTimeout session:subsystem:sftp=1" ;
+ echo "Subsystem sftp $OBJ/slow-sftp-server.sh" ) > $OBJ/sshd_proxy
+
+rm -f ${COPY}
+$SFTP -qS $SSH -F $OBJ/ssh_proxy somehost:$DATA $COPY
+r=$?
+if [ $r -eq 0 ]; then
+ fail "sftp succeeded unexpectedly"
+fi
+test -f $COPY && cmp $DATA $COPY && fail "intact copy"
+
+verbose "sftp irrelevant timeout"
+(grep -vi subsystem.*sftp $OBJ/sshd_proxy.orig;
+ echo "ChannelTimeout session:subsystem:command=1" ;
+ echo "Subsystem sftp $OBJ/slow-sftp-server.sh" ) > $OBJ/sshd_proxy
+
+rm -f ${COPY}
+$SFTP -qS $SSH -F $OBJ/ssh_proxy somehost:$DATA $COPY
+r=$?
+if [ $r -ne 0 ]; then
+ fail "sftp failed"
+fi
+cmp $DATA $COPY || fail "corrupted copy"
+