-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_cmc
executable file
·138 lines (120 loc) · 3.45 KB
/
test_cmc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env bash
set -o errexit
set -o errtrace
set -o nounset
# shellcheck disable=SC2154
trap '_es=${?};
printf "${0}: line ${LINENO}: \"${BASH_COMMAND}\"";
printf " exited with a status of ${_es}\n";
exit ${_es}' ERR
# https://en.wikipedia.org/wiki/ANSI_escape_code
E0="$(printf "\e[0m")" # reset
E30="$(printf "\033[30m")" # black foreground
E107="$(printf "\033[107m")" # bright white background
print_header() {
# Print 80 character wide black on white heading
printf "${E30}${E107} %-70s$(date '+%T') ${E0}\n" "${@}"
echo -n "${E30}${E107}"
for _ in {1..80}
do
echo -n '='
done
echo "${E0}"
}
TESTHOST=${1:-}
if [[ -z "${TESTHOST}" ]]
then
echo 'ERROR: the TESTHOST argument is required' 1>&2
exit 1
fi
print_header 'Show Debug information'
./cmc -d
echo
echo
print_header 'Verify syntax'
shellcheck cmc
echo 'no syntax issues identified'
echo
echo
HEAD="Verify \`-c ${TESTHOST}\` check HOST ControlMaster connection status"
print_header "${HEAD}"
echo "1. Establish a connection to ${TESTHOST}"
ssh -o ClearAllForwardings=yes -o ControlPersist=5m -o VisualHostKey=no \
"${TESTHOST}" exit 0
echo
echo "2. Check ${TESTHOST} with active socket"
./cmc -c "${TESTHOST}" \
| sed -e's/^/ /'
echo
PID=$(./cmc -c "${TESTHOST}" | awk '/pid:/ {print $2}')
echo "3. Send ALRM signal to PID ${PID} leave a stale socket"
kill -14 "${PID}"
echo
echo "4. Check ${TESTHOST} with stale socket"
./cmc -c "${TESTHOST}" 2>&1 \
| sed -e's/^/ /'
echo
echo
# shellcheck disable=SC2016
print_header 'Verify `-l` list all active ControlMaster connection sockets'
echo "1. Establish a connection to ${TESTHOST}"
ssh -o ClearAllForwardings=yes -o ControlPersist=5m -o VisualHostKey=no \
"${TESTHOST}" exit 0
echo
echo '2. List all with active socket'
./cmc -l \
| sed -e's/^/ /'
echo
PID=$(./cmc -c "${TESTHOST}" | awk '/pid:/ {print $2}')
echo "3. Send ALRM signal to PID ${PID} leave a stale socket"
kill -14 "${PID}"
echo
echo '4. List all with stale socket'
./cmc -l 2>&1 \
| sed -e's/^/ /'
echo
echo
print_header "Verify \`-x ${TESTHOST}\` exit ControlMaster session"
echo "1. Establish a connection to ${TESTHOST}"
ssh -o ClearAllForwardings=yes -o ControlPersist=5m -o VisualHostKey=no \
"${TESTHOST}" exit 0
echo
echo "2. Exit ${TESTHOST} with active socket"
./cmc -x "${TESTHOST}" \
| sed -e's/^/ /'
echo
echo "3. Establish a connection to ${TESTHOST}"
ssh -o ClearAllForwardings=yes -o ControlPersist=5m -o VisualHostKey=no \
"${TESTHOST}" exit 0
echo
PID=$(./cmc -c "${TESTHOST}" | awk '/pid:/ {print $2}')
echo "4. Send ALRM signal to PID ${PID} leave a stale socket"
kill -14 "${PID}"
echo
echo "5. Exit ${TESTHOST} with stale socket"
./cmc -x "${TESTHOST}" 2>&1 \
| sed -e's/^/ /'
echo
echo
# shellcheck disable=SC2016
print_header 'Verify `-X` exit all ControlMaster connections with sockets'
echo "1. Establish a connection to ${TESTHOST}"
ssh -o ClearAllForwardings=yes -o ControlPersist=5m -o VisualHostKey=no \
"${TESTHOST}" exit 0
echo
echo '2. Exit all with active socket'
./cmc -X \
| sed -e's/^/ /'
echo
echo "3. Establish a connection to ${TESTHOST}"
ssh -o ClearAllForwardings=yes -o ControlPersist=5m -o VisualHostKey=no \
"${TESTHOST}" exit 0
echo
PID=$(./cmc -c "${TESTHOST}" | awk '/pid:/ {print $2}')
echo "4. Send ALRM signal to PID ${PID} leave a stale socket"
kill -14 "${PID}"
echo
echo '5. Exit all with stale socket'
./cmc -X 2>&1 \
| sed -e's/^/ /'
echo