upstream: Fix debug logging of user specific delay. Patch from
[openssh.git] / regress / channel-timeout.sh
blob97708f2a2c9be5e264c918ed6d8a0ea86192b851
1 # $OpenBSD: channel-timeout.sh,v 1.2 2024/01/09 22:19:36 djm Exp $
2 # Placed in the Public Domain.
4 tid="channel timeout"
6 # XXX not comprehensive. Still need -R -L agent X11 forwarding + interactive
8 rm -f $OBJ/finished.* $OBJ/mux.*
10 MUXPATH=$OBJ/mux.$$
11 open_mux() {
12 ${SSH} -nNfM -oControlPath=$MUXPATH -F $OBJ/ssh_proxy "$@" somehost ||
13 fatal "open mux failed"
14 test -e $MUXPATH || fatal "mux socket $MUXPATH not established"
17 close_mux() {
18 test -e $MUXPATH || fatal "mux socket $MUXPATH missing"
19 ${SSH} -qF $OBJ/ssh_proxy -oControlPath=$MUXPATH -O exit somehost ||
20 fatal "could not terminate mux process"
21 for x in 1 2 3 4 5 6 7 8 9 10 ; do
22 test -e $OBJ/mux && break
23 sleep 1
24 done
25 test -e $MUXPATH && fatal "mux did not clean up"
27 mux_client() {
28 ${SSH} -F $OBJ/ssh_proxy -oControlPath=$MUXPATH somehost "$@"
31 rm -f $OBJ/sshd_proxy.orig
32 cp $OBJ/sshd_proxy $OBJ/sshd_proxy.orig
34 verbose "no timeout"
35 ${SSH} -F $OBJ/ssh_proxy somehost "sleep 5 ; exit 23"
36 r=$?
37 if [ $r -ne 23 ]; then
38 fail "ssh failed"
41 verbose "command timeout"
42 (cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:command=1") \
43 > $OBJ/sshd_proxy
44 ${SSH} -F $OBJ/ssh_proxy somehost "sleep 5 ; exit 23"
45 r=$?
46 if [ $r -ne 255 ]; then
47 fail "ssh returned unexpected error code $r"
50 verbose "command long timeout"
51 (cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:command=60") \
52 > $OBJ/sshd_proxy
53 ${SSH} -F $OBJ/ssh_proxy somehost "exit 23"
54 r=$?
55 if [ $r -ne 23 ]; then
56 fail "ssh returned unexpected error code $r"
59 verbose "command wildcard timeout"
60 (cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:*=1") \
61 > $OBJ/sshd_proxy
62 ${SSH} -F $OBJ/ssh_proxy somehost "sleep 5 ; exit 23"
63 r=$?
64 if [ $r -ne 255 ]; then
65 fail "ssh returned unexpected error code $r"
68 verbose "command irrelevant timeout"
69 (cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:shell=1") \
70 > $OBJ/sshd_proxy
71 ${SSH} -F $OBJ/ssh_proxy somehost "sleep 5 ; exit 23"
72 r=$?
73 if [ $r -ne 23 ]; then
74 fail "ssh failed"
77 if config_defined DISABLE_FD_PASSING ; then
78 verbose "skipping multiplexing tests"
79 else
80 verbose "multiplexed command timeout"
81 (cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:command=1") \
82 > $OBJ/sshd_proxy
83 open_mux
84 mux_client "sleep 5 ; exit 23"
85 r=$?
86 if [ $r -ne 255 ]; then
87 fail "ssh returned unexpected error code $r"
89 close_mux
91 verbose "irrelevant multiplexed command timeout"
92 (cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:shell=1") \
93 > $OBJ/sshd_proxy
94 open_mux
95 mux_client "sleep 5 ; exit 23"
96 r=$?
97 if [ $r -ne 23 ]; then
98 fail "ssh returned unexpected error code $r"
100 close_mux
102 verbose "global command timeout"
103 (cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout global=10") \
104 > $OBJ/sshd_proxy
105 open_mux
106 mux_client "sleep 1 ; echo ok ; sleep 1; echo ok; sleep 60; touch $OBJ/finished.1" >/dev/null &
107 mux_client "sleep 60 ; touch $OBJ/finished.2" >/dev/null &
108 mux_client "sleep 2 ; touch $OBJ/finished.3" >/dev/null &
109 wait
110 test -f $OBJ/finished.1 && fail "first mux process completed"
111 test -f $OBJ/finished.2 && fail "second mux process completed"
112 test -f $OBJ/finished.3 || fail "third mux process did not complete"
113 close_mux
116 # Set up a "slow sftp server" that sleeps before executing the real one.
117 cat > $OBJ/slow-sftp-server.sh << _EOF
118 #!/bin/sh
120 sleep 5
121 $SFTPSERVER
122 _EOF
123 chmod a+x $OBJ/slow-sftp-server.sh
125 verbose "sftp no timeout"
126 (grep -vi subsystem.*sftp $OBJ/sshd_proxy.orig;
127 echo "Subsystem sftp $OBJ/slow-sftp-server.sh" ) > $OBJ/sshd_proxy
129 rm -f ${COPY}
130 $SFTP -qS $SSH -F $OBJ/ssh_proxy somehost:$DATA $COPY
131 r=$?
132 if [ $r -ne 0 ]; then
133 fail "sftp failed"
135 cmp $DATA $COPY || fail "corrupted copy"
137 verbose "sftp timeout"
138 (grep -vi subsystem.*sftp $OBJ/sshd_proxy.orig;
139 echo "ChannelTimeout session:subsystem:sftp=1" ;
140 echo "Subsystem sftp $OBJ/slow-sftp-server.sh" ) > $OBJ/sshd_proxy
142 rm -f ${COPY}
143 $SFTP -qS $SSH -F $OBJ/ssh_proxy somehost:$DATA $COPY
144 r=$?
145 if [ $r -eq 0 ]; then
146 fail "sftp succeeded unexpectedly"
148 test -f $COPY && cmp $DATA $COPY && fail "intact copy"
150 verbose "sftp irrelevant timeout"
151 (grep -vi subsystem.*sftp $OBJ/sshd_proxy.orig;
152 echo "ChannelTimeout session:subsystem:command=1" ;
153 echo "Subsystem sftp $OBJ/slow-sftp-server.sh" ) > $OBJ/sshd_proxy
155 rm -f ${COPY}
156 $SFTP -qS $SSH -F $OBJ/ssh_proxy somehost:$DATA $COPY
157 r=$?
158 if [ $r -ne 0 ]; then
159 fail "sftp failed"
161 cmp $DATA $COPY || fail "corrupted copy"