Debian Codegraph @

debian/tests/test-tunneled-ssh.d/run-test

raw
1 #!/bin/sh
2
3 set -e
4
5 proxyhost="$1"
6 proxyport="$2"
7 tunnelhost="${3:-$proxyhost}"
8 tunnelport="${4:-$proxyport}"
9
10 # Use explicit <newline> characters for POSIX compliance.
11 nl="
12 "
13 expected_stderr="Connected to $tunnelhost.$nl"
14 if [ -z "$3" ]; then
15 expected_stderr="Via $proxyhost:$proxyport -> localhost:22$nl$expected_stderr"
16 fi
17
18 sslprotocol="`grep -o 'SSLProtocol.*' /etc/apache2/sites-enabled/$proxyhost.conf`" || true
19 sslprotocol="${sslprotocol:-no SSLProtocol}"
20 echo "=== Running test ${3:+on $tunnelhost, port $tunnelport }via $proxyhost with $sslprotocol ==="
21
22 if [ -n "$3" ]; then
23 # Check IP protocol version and address proxytunnel is listening on
24 listenerinfo=`lsof -c proxytunnel -a -i -s TCP:LISTEN -nP -F tn | xargs echo`
25 ipaddress=`echo "$listenerinfo" | grep -Po '((?<=n)[\d.]+|(?<=n\[)[\da-f:]+)'`
26 ipprotocol=`echo "$listenerinfo" | grep -Po '(?<=t)\w+'`
27 expected_ipprotocol=`if [ ${ipaddress##*.*.*.*} ]; then echo 'IPv6'; else echo 'IPv4'; fi`
28
29 if [ "$ipprotocol" != "$expected_ipprotocol" ]; then
30 echo "Listening on unexpected IP protocol $ipprotocol instead of $expected_ipprotocol."
31 exit 1
32 fi
33 if [ "$ipaddress" != "$tunnelhost" ]; then
34 echo "Listening on unexpected IP address $ipaddress instead of $tunnelhost."
35 exit 1
36 fi
37 fi
38
39 ( echo 'ls -l .ssh' | sftp localhost 1>localhost_stdout 2>localhost_stderr ) || true
40 ( echo 'ls -l .ssh' | sftp ${3:+-P $tunnelport} $tunnelhost 1>tunnelhost_stdout 2>tunnelhost_stderr ) || true
41
42 echo stderr\'s diff
43 echo -n "$expected_stderr" | diff -y - tunnelhost_stderr
44
45 echo stdout\'s diff
46 diff -y localhost_stdout tunnelhost_stdout
47
48 echo Test succeeded for $tunnelhost.