Skip to content

Commit c9cf3eb

Browse files
committed
wolfsshd: test that a pty session ends on exit
A pty session has no stderr pipe, so the shell loop must start with stderrEmpty set. The drain test now runs "exit 3" in a pty shell and expects the session to end with that status rather than wait for a stderr EOF that never comes.
1 parent c62bc7b commit c9cf3eb

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎apps/wolfsshd/test/sshd_stderr_drain_test.sh‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# much the loop reads first is a race, so this repeats. A short stream is never
1313
# correct, so a failure is always real.
1414
#
15+
# A pty session has no stderr pipe; the last check covers its exit.
16+
#
1517
# Lines are counted rather than bytes because the client's own "Error reading
1618
# stdin" lands in the same capture.
1719

@@ -36,6 +38,7 @@ TEST_LINE="wolfsshd-stderr-drain"
3638
TEST_LINES=9000
3739
TEST_ITERS=40
3840
TEST_TIMEOUT=60
41+
TEST_PTY_TIMEOUT=15
3942
TEST_PIPE_SZ=1048576
4043

4144
# The shell cannot resize a pipe, so the child is perl.
@@ -49,8 +52,10 @@ fi
4952
# Degraded rather than skipped where "timeout" is missing, matching
5053
# run_all_sshd_tests.sh.
5154
TIMEOUT=""
55+
PTY_TIMEOUT=""
5256
if command -v timeout >/dev/null 2>&1; then
5357
TIMEOUT="timeout $TEST_TIMEOUT"
58+
PTY_TIMEOUT="timeout $TEST_PTY_TIMEOUT"
5459
fi
5560

5661
source ./start_sshd.sh
@@ -145,6 +150,26 @@ for i in `seq 1 $TEST_ITERS`; do
145150
fi
146151
done
147152

153+
# A pty session has no stderr pipe, so the drain must start out satisfied.
154+
# Seeded wrong, the loop waits for an EOF that never comes and the shell's
155+
# exit never ends the session. The exit status proves the session ended and
156+
# carried the shell's own code back.
157+
if [ "$RESULT" = 0 ]; then
158+
printf 'exit 3\n' | $PTY_TIMEOUT $TEST_CLIENT -t \
159+
-u $USER -i $PRIVATE_KEY -j $PUBLIC_KEY -h $TEST_HOST -p $TEST_PORT \
160+
> /dev/null 2>&1
161+
CLIENT_RESULT=$?
162+
163+
if [ "$CLIENT_RESULT" = 124 ]; then
164+
echo "pty session never ended after the shell exited"
165+
echo "the client was still running after $TEST_PTY_TIMEOUT seconds"
166+
RESULT=1
167+
elif [ "$CLIENT_RESULT" != 3 ]; then
168+
echo "pty session exit status $CLIENT_RESULT, expected 3"
169+
RESULT=1
170+
fi
171+
fi
172+
148173
rm -rf "$TEST_TMP"
149174
cd apps/wolfsshd/test
150175
stop_wolfsshd

0 commit comments

Comments
 (0)