]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - regress/multiplex.sh
Pull in a patchset from upstream to silence spurious "no such identity
[FreeBSD/FreeBSD.git] / regress / multiplex.sh
1 #       $OpenBSD: multiplex.sh,v 1.17 2012/10/05 02:05:30 dtucker Exp $
2 #       Placed in the Public Domain.
3
4 CTL=/tmp/openssh.regress.ctl-sock.$$
5
6 tid="connection multiplexing"
7
8 if config_defined DISABLE_FD_PASSING ; then
9         echo "skipped (not supported on this platform)"
10         exit 0
11 fi
12
13 DATA=/bin/ls${EXEEXT}
14 COPY=$OBJ/ls.copy
15
16 wait_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
26 start_sshd
27
28 trace "start master, fork to background"
29 ${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost &
30 MASTER_PID=$!
31 wait_for_mux_master_ready
32
33 verbose "test $tid: envpass"
34 trace "env passing over multiplexed connection"
35 _XXX_TEST=blah ${SSH} -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" -S$CTL otherhost sh << 'EOF'
36         test X"$_XXX_TEST" = X"blah"
37 EOF
38 if [ $? -ne 0 ]; then
39         fail "environment not found"
40 fi
41
42 verbose "test $tid: transfer"
43 rm -f ${COPY}
44 trace "ssh transfer over multiplexed connection and check result"
45 ${SSH} -F $OBJ/ssh_config -S$CTL otherhost cat ${DATA} > ${COPY}
46 test -f ${COPY}                 || fail "ssh -Sctl: failed copy ${DATA}" 
47 cmp ${DATA} ${COPY}             || fail "ssh -Sctl: corrupted copy of ${DATA}"
48
49 rm -f ${COPY}
50 trace "ssh transfer over multiplexed connection and check result"
51 ${SSH} -F $OBJ/ssh_config -S $CTL otherhost cat ${DATA} > ${COPY}
52 test -f ${COPY}                 || fail "ssh -S ctl: failed copy ${DATA}" 
53 cmp ${DATA} ${COPY}             || fail "ssh -S ctl: corrupted copy of ${DATA}"
54
55 rm -f ${COPY}
56 trace "sftp transfer over multiplexed connection and check result"
57 echo "get ${DATA} ${COPY}" | \
58         ${SFTP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost >>$TEST_SSH_LOGFILE 2>&1
59 test -f ${COPY}                 || fail "sftp: failed copy ${DATA}" 
60 cmp ${DATA} ${COPY}             || fail "sftp: corrupted copy of ${DATA}"
61
62 rm -f ${COPY}
63 trace "scp transfer over multiplexed connection and check result"
64 ${SCP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost:${DATA} ${COPY} >>$TEST_SSH_LOGFILE 2>&1
65 test -f ${COPY}                 || fail "scp: failed copy ${DATA}" 
66 cmp ${DATA} ${COPY}             || fail "scp: corrupted copy of ${DATA}"
67
68 rm -f ${COPY}
69
70 for s in 0 1 4 5 44; do
71         trace "exit status $s over multiplexed connection"
72         verbose "test $tid: status $s"
73         ${SSH} -F $OBJ/ssh_config -S $CTL otherhost exit $s
74         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"
81         ${SSH} -F $OBJ/ssh_config -S $CTL -n otherhost \
82                 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
87 done
88
89 verbose "test $tid: cmd check"
90 ${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost >>$TEST_SSH_LOGFILE 2>&1 \
91     || fail "check command failed" 
92
93 verbose "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" 
96
97 # Wait for master to exit
98 wait $MASTER_PID
99 kill -0 $MASTER_PID >/dev/null 2>&1 && fail "exit command failed"
100
101 # Restart master and test -O stop command with master using -N
102 verbose "test $tid: cmd stop"
103 trace "restart master, fork to background"
104 ${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost &
105 MASTER_PID=$!
106 wait_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 &
111 SLEEP_PID=$!
112 ${SSH} -F $OBJ/ssh_config -S $CTL -Ostop otherhost >>$TEST_SSH_LOGFILE 2>&1 \
113     || fail "send stop command failed"
114
115 # wait until both long-running command and master have exited.
116 wait $SLEEP_PID
117 [ $! != 0 ] || fail "waiting for concurrent command"
118 wait $MASTER_PID
119 [ $! != 0 ] || fail "waiting for master stop"
120 kill -0 $MASTER_PID >/dev/null 2>&1 && fail "stop command failed"