xref: /openbsd-src/regress/usr.bin/ssh/multiplex.sh (revision c674ec46eb58e463797c8b78c679a5a3cc728b07)
1#	$OpenBSD: multiplex.sh,v 1.14 2012/09/09 11:51:25 dtucker Exp $
2#	Placed in the Public Domain.
3
4CTL=$OBJ/ctl-sock
5
6tid="connection multiplexing"
7
8DATA=/bin/ls
9COPY=$OBJ/ls.copy
10
11start_sshd
12
13trace "start master, fork to background"
14${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost &
15MASTER_PID=$!
16
17# Wait for master to start and authenticate
18sleep 5
19
20verbose "test $tid: envpass"
21trace "env passing over multiplexed connection"
22_XXX_TEST=blah ${SSH} -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" -S$CTL otherhost sh << 'EOF'
23	test X"$_XXX_TEST" = X"blah"
24EOF
25if [ $? -ne 0 ]; then
26	fail "environment not found"
27fi
28
29verbose "test $tid: transfer"
30rm -f ${COPY}
31trace "ssh transfer over multiplexed connection and check result"
32${SSH} -F $OBJ/ssh_config -S$CTL otherhost cat ${DATA} > ${COPY}
33test -f ${COPY}			|| fail "ssh -Sctl: failed copy ${DATA}"
34cmp ${DATA} ${COPY}		|| fail "ssh -Sctl: corrupted copy of ${DATA}"
35
36rm -f ${COPY}
37trace "ssh transfer over multiplexed connection and check result"
38${SSH} -F $OBJ/ssh_config -S $CTL otherhost cat ${DATA} > ${COPY}
39test -f ${COPY}			|| fail "ssh -S ctl: failed copy ${DATA}"
40cmp ${DATA} ${COPY}		|| fail "ssh -S ctl: corrupted copy of ${DATA}"
41
42rm -f ${COPY}
43trace "sftp transfer over multiplexed connection and check result"
44echo "get ${DATA} ${COPY}" | \
45	${SFTP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost >>$TEST_SSH_LOGFILE 2>&1
46test -f ${COPY}			|| fail "sftp: failed copy ${DATA}"
47cmp ${DATA} ${COPY}		|| fail "sftp: corrupted copy of ${DATA}"
48
49rm -f ${COPY}
50trace "scp transfer over multiplexed connection and check result"
51${SCP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost:${DATA} ${COPY} >>$TEST_SSH_LOGFILE 2>&1
52test -f ${COPY}			|| fail "scp: failed copy ${DATA}"
53cmp ${DATA} ${COPY}		|| fail "scp: corrupted copy of ${DATA}"
54
55rm -f ${COPY}
56
57for s in 0 1 4 5 44; do
58	trace "exit status $s over multiplexed connection"
59	verbose "test $tid: status $s"
60	${SSH} -F $OBJ/ssh_config -S $CTL otherhost exit $s
61	r=$?
62	if [ $r -ne $s ]; then
63		fail "exit code mismatch for protocol $p: $r != $s"
64	fi
65
66	# same with early close of stdout/err
67	trace "exit status $s with early close over multiplexed connection"
68	${SSH} -F $OBJ/ssh_config -S $CTL -n otherhost \
69                exec sh -c \'"sleep 2; exec > /dev/null 2>&1; sleep 3; exit $s"\'
70	r=$?
71	if [ $r -ne $s ]; then
72		fail "exit code (with sleep) mismatch for protocol $p: $r != $s"
73	fi
74done
75
76trace "test check command"
77${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost || fail "check command failed"
78
79trace "test exit command"
80${SSH} -F $OBJ/ssh_config -S $CTL -Oexit otherhost || fail "send exit command failed"
81
82# Wait for master to exit
83sleep 2
84
85ps -p $MASTER_PID >/dev/null && fail "exit command failed"
86
87# Restart master and test -O stop command with master using -N
88trace "start master, fork to background"
89${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost &
90MASTER_PID=$!
91sleep 5 # Wait for master to start and authenticate
92trace "test stop command"
93${SSH} -F $OBJ/ssh_config -S $CTL -Ostop otherhost || fail "send stop command failed"
94sleep 2 # Wait for master to exit
95ps -p $MASTER_PID >/dev/null && fail "stop command failed"
96