blob: 1e6cc7606c161c22510f711ee9ce5335d3814087 [file] [log] [blame]
Damien Millerd27a0262012-12-03 10:06:37 +11001# $OpenBSD: multiplex.sh,v 1.17 2012/10/05 02:05:30 dtucker Exp $
Darren Tuckere7d05832004-06-16 20:22:22 +10002# Placed in the Public Domain.
3
Darren Tuckeraf342552005-04-25 17:01:26 +10004CTL=/tmp/openssh.regress.ctl-sock.$$
Darren Tuckere7d05832004-06-16 20:22:22 +10005
6tid="connection multiplexing"
7
Damien Miller58497782011-01-17 16:17:09 +11008if config_defined DISABLE_FD_PASSING ; then
Darren Tucker2a81adc2004-08-29 17:09:34 +10009 echo "skipped (not supported on this platform)"
10 exit 0
11fi
12
Darren Tucker10e7f192004-06-17 16:36:27 +100013DATA=/bin/ls${EXEEXT}
Darren Tuckerffaa6a52004-06-17 16:32:45 +100014COPY=$OBJ/ls.copy
15
Darren Tuckeree4ad772012-10-05 12:04:10 +100016wait_for_mux_master_ready()
17{
18 for i in 1 2 3 4 5; do
19 ${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost \
20 >/dev/null 2>&1 && return 0
21 sleep $i
22 done
23 fatal "mux master never becomes ready"
24}
25
Darren Tuckere7d05832004-06-16 20:22:22 +100026start_sshd
27
28trace "start master, fork to background"
Darren Tucker79ec66e2004-12-06 23:12:15 +110029${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost &
30MASTER_PID=$!
Darren Tuckeree4ad772012-10-05 12:04:10 +100031wait_for_mux_master_ready
Darren Tuckere7d05832004-06-16 20:22:22 +100032
Damien Millere826a8c2004-06-18 01:23:03 +100033verbose "test $tid: envpass"
34trace "env passing over multiplexed connection"
Darren Tucker79885532009-10-07 10:30:57 +110035_XXX_TEST=blah ${SSH} -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" -S$CTL otherhost sh << 'EOF'
Darren Tucker430c6a12004-06-22 13:38:56 +100036 test X"$_XXX_TEST" = X"blah"
37EOF
Damien Millere826a8c2004-06-18 01:23:03 +100038if [ $? -ne 0 ]; then
39 fail "environment not found"
40fi
41
42verbose "test $tid: transfer"
Darren Tuckerffaa6a52004-06-17 16:32:45 +100043rm -f ${COPY}
Darren Tuckere7d05832004-06-16 20:22:22 +100044trace "ssh transfer over multiplexed connection and check result"
Darren Tucker79885532009-10-07 10:30:57 +110045${SSH} -F $OBJ/ssh_config -S$CTL otherhost cat ${DATA} > ${COPY}
Darren Tucker3e86fc42004-06-17 16:34:02 +100046test -f ${COPY} || fail "ssh -Sctl: failed copy ${DATA}"
47cmp ${DATA} ${COPY} || fail "ssh -Sctl: corrupted copy of ${DATA}"
Darren Tuckere7d05832004-06-16 20:22:22 +100048
Darren Tuckerffaa6a52004-06-17 16:32:45 +100049rm -f ${COPY}
Darren Tuckere7d05832004-06-16 20:22:22 +100050trace "ssh transfer over multiplexed connection and check result"
Darren Tucker79885532009-10-07 10:30:57 +110051${SSH} -F $OBJ/ssh_config -S $CTL otherhost cat ${DATA} > ${COPY}
Darren Tucker3e86fc42004-06-17 16:34:02 +100052test -f ${COPY} || fail "ssh -S ctl: failed copy ${DATA}"
53cmp ${DATA} ${COPY} || fail "ssh -S ctl: corrupted copy of ${DATA}"
Darren Tuckere7d05832004-06-16 20:22:22 +100054
Darren Tuckerffaa6a52004-06-17 16:32:45 +100055rm -f ${COPY}
Darren Tuckere7d05832004-06-16 20:22:22 +100056trace "sftp transfer over multiplexed connection and check result"
Darren Tuckerffaa6a52004-06-17 16:32:45 +100057echo "get ${DATA} ${COPY}" | \
Darren Tucker4430a862012-06-30 15:03:28 +100058 ${SFTP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost >>$TEST_SSH_LOGFILE 2>&1
Darren Tucker3e86fc42004-06-17 16:34:02 +100059test -f ${COPY} || fail "sftp: failed copy ${DATA}"
60cmp ${DATA} ${COPY} || fail "sftp: corrupted copy of ${DATA}"
Darren Tuckere7d05832004-06-16 20:22:22 +100061
Darren Tuckerffaa6a52004-06-17 16:32:45 +100062rm -f ${COPY}
Darren Tuckere7d05832004-06-16 20:22:22 +100063trace "scp transfer over multiplexed connection and check result"
Darren Tucker4430a862012-06-30 15:03:28 +100064${SCP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost:${DATA} ${COPY} >>$TEST_SSH_LOGFILE 2>&1
Darren Tucker3e86fc42004-06-17 16:34:02 +100065test -f ${COPY} || fail "scp: failed copy ${DATA}"
66cmp ${DATA} ${COPY} || fail "scp: corrupted copy of ${DATA}"
Darren Tuckere7d05832004-06-16 20:22:22 +100067
Darren Tuckerffaa6a52004-06-17 16:32:45 +100068rm -f ${COPY}
Darren Tuckerddea13d2004-06-17 16:27:43 +100069
Darren Tuckere7d05832004-06-16 20:22:22 +100070for s in 0 1 4 5 44; do
71 trace "exit status $s over multiplexed connection"
72 verbose "test $tid: status $s"
Darren Tucker79885532009-10-07 10:30:57 +110073 ${SSH} -F $OBJ/ssh_config -S $CTL otherhost exit $s
Darren Tuckere7d05832004-06-16 20:22:22 +100074 r=$?
75 if [ $r -ne $s ]; then
76 fail "exit code mismatch for protocol $p: $r != $s"
77 fi
78
79 # same with early close of stdout/err
80 trace "exit status $s with early close over multiplexed connection"
Darren Tucker79885532009-10-07 10:30:57 +110081 ${SSH} -F $OBJ/ssh_config -S $CTL -n otherhost \
Darren Tuckere7d05832004-06-16 20:22:22 +100082 exec sh -c \'"sleep 2; exec > /dev/null 2>&1; sleep 3; exit $s"\'
83 r=$?
84 if [ $r -ne $s ]; then
85 fail "exit code (with sleep) mismatch for protocol $p: $r != $s"
86 fi
87done
88
Darren Tucker9b2c0362012-10-05 11:45:39 +100089verbose "test $tid: cmd check"
90${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost >>$TEST_SSH_LOGFILE 2>&1 \
91 || fail "check command failed"
Darren Tucker79ec66e2004-12-06 23:12:15 +110092
Darren Tucker9b2c0362012-10-05 11:45:39 +100093verbose "test $tid: cmd exit"
94${SSH} -F $OBJ/ssh_config -S $CTL -Oexit otherhost >>$TEST_SSH_LOGFILE 2>&1 \
95 || fail "send exit command failed"
Darren Tucker79ec66e2004-12-06 23:12:15 +110096
97# Wait for master to exit
Darren Tuckeree4ad772012-10-05 12:04:10 +100098wait $MASTER_PID
Damien Millerd27a0262012-12-03 10:06:37 +110099kill -0 $MASTER_PID >/dev/null 2>&1 && fail "exit command failed"
Darren Tucker6fc5aa82012-10-05 11:43:57 +1000100
101# Restart master and test -O stop command with master using -N
Darren Tuckeree4ad772012-10-05 12:04:10 +1000102verbose "test $tid: cmd stop"
103trace "restart master, fork to background"
Darren Tucker6fc5aa82012-10-05 11:43:57 +1000104${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost &
105MASTER_PID=$!
Darren Tuckeree4ad772012-10-05 12:04:10 +1000106wait_for_mux_master_ready
107
108# start a long-running command then immediately request a stop
109${SSH} -F $OBJ/ssh_config -S $CTL otherhost "sleep 10; exit 0" \
110 >>$TEST_SSH_LOGFILE 2>&1 &
Darren Tucker9b2c0362012-10-05 11:45:39 +1000111SLEEP_PID=$!
112${SSH} -F $OBJ/ssh_config -S $CTL -Ostop otherhost >>$TEST_SSH_LOGFILE 2>&1 \
113 || fail "send stop command failed"
Darren Tuckeree4ad772012-10-05 12:04:10 +1000114
115# wait until both long-running command and master have exited.
Darren Tucker9b2c0362012-10-05 11:45:39 +1000116wait $SLEEP_PID
Darren Tuckeree4ad772012-10-05 12:04:10 +1000117[ $! != 0 ] || fail "waiting for concurrent command"
118wait $MASTER_PID
119[ $! != 0 ] || fail "waiting for master stop"
Damien Millerd27a0262012-12-03 10:06:37 +1100120kill -0 $MASTER_PID >/dev/null 2>&1 && fail "stop command failed"