9 |00:00 *** Welcome to lamechat!
29 |00:00 *** Welcome to lamechat!
36 setup -c -s 6667 <<-EOF
55 |00:00 [localhost] *** three
56 |00:00 [localhost] *** four
57 |00:00 [localhost] *** five
58 |00:00 [localhost] *** six
59 | Windows: [localhost]
64 |00:00 [localhost] *** two
65 |00:00 [localhost] *** five
69 |00:00 [localhost] *** three
70 |00:00 [localhost] *** six
74 |00:00 [localhost] *** one
75 |00:00 [localhost] *** four
79 |00:00 [localhost] *** three
80 |00:00 [localhost] *** six
85 setup -c -s 6667 <<-EOF
94 < NOTICE andy :Welcome to lame server!
96 < NOTICE andy :$(color 002)bold$(color 017)
97 < NOTICE andy :$(color 011)italic$(color 017)
98 < NOTICE andy :$(color 023)uline$(color 017)
99 < NOTICE andy :$(color 025)uline$(color 017)
100 < NOTICE andy :$(color 037)uline$(color 017)
101 < NOTICE andy :$(color 026)rev$(color 017)
103 < NOTICE andy :$(color 003)01 fg,--$(color 017)
104 < NOTICE andy :$(color 003)2 fg,--$(color 017)
105 < NOTICE andy :$(color 003)3,fg,--$(color 017)
106 < NOTICE andy :$(color 003),4 --,bg$(color 017)
107 < NOTICE andy :$(color 003)5,6 fg,bg$(color 017)
110 input /theme dark && sleep 0.01
111 input /theme light && sleep 0.01
112 input /theme normal && sleep 0.01
115 |00:00 [local] *** Welcome to lame server!
116 |00:00 [local] *** bold
117 |00:00 [local] *** italic
118 |00:00 [local] *** uline
119 |00:00 [local] *** uline
120 |00:00 [local] *** uline
121 |00:00 [local] *** rev
122 |00:00 [local] *** fg,--
123 |00:00 [local] *** fg,--
124 |00:00 [local] *** ,fg,--
125 |00:00 [local] *** --,bg
126 |00:00 [local] *** fg,bg
131 setup -c -s 6667 <<-EOF
144 < :lamechat 001 andy :Welcome to lame server!
145 < :user1 PRIVMSG andy :hello 1
146 < :user2 PRIVMSG andy :hello 2
154 |00:00 [user1] user1: hello 1
155 |00:00 [user2] user2: hello 2
156 | Windows: [local] [users]
172 setup -c -s 6667 <<-EOF
190 < :lamechat 001 andy :Welcome to lamechat!
200 |00:00 [local] *** Joining Server: local
201 |00:00 [local] *** Start TLS unsupported
202 |00:00 [#test] *** Joining Channel: #test
203 |00:00 [local] *** Welcome to lamechat!
208 setup -c -x 6697 <<-EOF
224 < 904 :Authentication Failed.
227 |00:00 [serv] *** SASL auth proceeding
228 |00:00 [serv] *** SASL auth failed
237 |00:00 [local] *** Welcome to lamechat!
238 |00:00 [local] *** Server disconnected
242 test_irc_reconnect() {
243 setup -c -s 6667 <<-EOF
247 reconnect = -10000000
259 < :lamechat 001 andy :Welcome to lamechat!
270 |00:00 [local] *** Joining Server: local
271 |00:00 [local] *** Welcome to lamechat!
272 |00:00 [local] *** Server disconnected
273 |00:00 [local] *** Reconnecting: local
274 |00:00 [local] *** Joining Server: local
279 setup -c -s 6001 -s 6002 <<-EOF
282 jid = "andy@local/lame"
304 filter = "serv.|#chan."
312 < :lamechat 001 andy1 :Welcome to lamechat 1!
323 < :lamechat 001 andy2 :Welcome to lamechat 2!
329 < :alice1 PRIVMSG #chan1 :hello, here 1!
330 < :bob1 PRIVMSG #other1 :hello, there 1!
333 < :alice2 PRIVMSG #chan2 :hello, here 2!
334 < :bob2 PRIVMSG #other2 :hello, there 2!
337 |00:00 [serv1] *** Joining Server: serv1
338 |00:00 [serv2] *** Joining Server: serv2
339 |00:00 [serv1] *** Welcome to lamechat 1!
340 |00:00 [serv2] *** Welcome to lamechat 2!
341 |00:00 [#chan1] alice1: hello, here 1!
342 |00:00 [#chan2] alice2: hello, here 2!
343 | Windows: [system] [#other1] [#other2]
348 setup -c -x 6697 <<-EOF
365 < :lamechat 001 andy :Welcome to lamechat!
368 |00:00 [local] *** SASL auth unsupported
369 |00:00 [local] *** Welcome to lamechat!
374 setup -c -s 6667 <<-EOF
388 < :lamechat 607 andy :STARTTLS successful
391 |00:00 [local] *** Start TLS proceeding
396 setup -c -s 6667 <<-EOF
410 < :lamechat 001 andy :Welcome to lamechat!
417 setup -c -x 12345 <<-EOF
438 > AUTHENTICATE $(echo -n ali ali opensesame |
439 tr ' ' '\0' | base64)
440 < 903 :Authentication Successful.
444 < :lamechat 001 andy :Welcome to lamechat!
445 < :bob PRIVMSG #test :hello, there!
448 |00:00 [serv] *** Joining Server: serv
449 |00:00 [serv] *** SASL auth proceeding
450 |00:00 [serv] *** SASL auth succeeded
451 |00:00 [chan] bob: hello, there!
458 input /filter "system"
460 < :alice PRIVMSG #test :hello, here!
461 < :bob PRIVMSG #other :hello, there!
462 < :eve PRIVMSG andy :hello, where?
463 < :eve PRIVMSG andy :hello, everywhere
465 input /filter "#.*|eve"
468 |00:00 [#test] alice: hello, here!
469 |00:00 [#other] bob: hello, there!
470 |00:00 [eve] eve: hello, where?
471 |00:00 [eve] eve: hello, everywhere
472 | Windows: [system] [#test] [#other] [eve:1]
482 < :bob 353 andy @ #test :alice bob
483 < :bob 331 #test #test :First Topic!
484 < :bob 332 #test #test :Second Topic!
485 < :bob TOPIC #test #test :Third Topic!
489 |00:00 [#test] *** Members: alice bob
490 |00:00 [#test] *** Topic: First Topic!
491 |00:00 [#test] *** Topic: Second Topic!
492 |00:00 [#test] *** Topic changed to Third Topic!
498 input /filter '#test'
501 input -n "hello bob!\n"
505 > PRIVMSG #test :hello bob!
510 |00:00 [#test] *** Joining Channel: #test
511 |00:00 [#test] andy: hello bob!
517 test_irc_commands() {
518 setup -c -s 6667 <<-EOF
525 filter = "local|alice|#.*"
533 < :lamechat 001 andy :Welcome to lamechat!
552 input /kill_all_humans
555 |00:00 [local] *** Cannot send to server
556 |00:00 [#test] *** Joining Channel: #test
557 |00:00 [#test] andy: hello #test
558 |00:00 [#test] *** Leaving Channel: #test
559 |00:00 [#test] *** Joining Channel: #test
560 |00:00 [#test] *** usage: /query <user>
561 |00:00 [alice] *** User: alice
562 |00:00 [alice] andy: hello alice
563 |00:00 [alice] *** Unknown command /kill_all_humans
569 setup -c -s 5222 <<-EOF
573 jid = "andy@localhost/lamechat"
579 filter = "local|info|test|other|alice|bob|Adelais|Robert"
582 > <?xml version='1.0'?>
583 > <stream:stream from='andy@localhost/lamechat'*>
584 < <stream:stream to="andy@localhost/lamechat" from="localhost">
588 test_xmpp_dropped() {
592 < <text>We don't serve your kind here!</text>
599 |00:00 [local] *** XMPP Server: local
600 |00:00 [local] *** error: We don't serve your kind here!
601 |00:00 [local] *** Server disconnected
612 |0.000: error: jid is required
617 int timerfd_create() { return -1; }
623 jid = "andy@localhost/lamechat"
626 |0.000: error: creating timer fd
631 void *XML_ParserCreate() { return 0; }
637 jid = "andy@localhost/lamechat"
640 |0.000: error: creating XML parser
645 int XML_ParserReset() { return 0; }
649 |0.000: error: resetting XML parser
654 int XML_ParserReset() { return 0; }
661 > <auth xmlns='*:xmpp-sasl' mechanism='PLAIN'>*</auth>
665 |0.000: error: resetting XML parser
669 test_xmpp_timeout() {
670 setup -c -s 5222 <<-EOF
675 jid = "andy@localhost/lamechat"
684 test_xmpp_options() {
685 setup -c -s 5000 <<-EOF
695 jid = "andy@local.host/lamechat"
707 filter = "local|test"
713 < <stream:features><bind/></stream:features>
715 > <iq*><bind*><resource>lamechat</resource></bind></iq>
718 > <iq*><session*/></iq>
720 > <presence*><*/></presence>
721 < <presence id="join" from="test@localhost/andy"/>
722 < <presence id="join" from="test@localhost/bob"/>
732 test_xmpp_starttls() {
738 > <starttls xmlns='*:xmpp-tls'/>
749 > <auth xmlns='*:xmpp-sasl' mechanism='PLAIN'>*</auth>
752 > <?xml version='1.0'?>
753 > <stream:stream from='andy@localhost/lamechat'*>
754 < <stream:stream to="andy@localhost/lamechat" from="localhost">
757 |00:00 [local] *** Authentication success
767 > <auth xmlns='*:xmpp-sasl' mechanism='PLAIN'>*</auth>
771 |00:00 [local] *** Authentication failure
781 > <iq id='bind' type='set'>
782 > <bind xmlns='*:xmpp-bind'>
783 > <resource>lamechat</resource>
786 < <iq id="bind" type="result">
788 < <jid>andy@localhost/lamechat</jid>
798 > <iq id='session' type='set' to='localhost'>
799 > <session xmlns='*:xmpp-session'/>
802 > <presence id='join' from='andy@localhost/lamechat' to='*'>
803 > <x xmlns='http://jabber.org/protocol/muc'/>
805 < <iq to="localhost" type="result" id="session"/>
806 < <presence id="join" from="test@conf.local/andy"/>
807 < <presence id="join" from="test@conf.local/bob">
808 < <item jid="bob1@local"/>
812 |00:00 [test] *** XMPP Channel: test
813 |00:00 [test] *** andy entered room.
814 |00:00 [test] *** bob (bob1) entered room.
824 < <message type="groupchat" from="test@conf.local/bob">
825 < <subject>Some Topic</subject>
831 |00:00 [test] *** Topic: Some Topic
835 test_xmpp_message() {
841 < <iq from="info@local">
842 < <item jid="test@conf.local" name="Test Chat"/>
844 < <message type="error">
845 < <body>Server says goodbye!</body>
849 |00:00 [info] *** item: [test@conf.local] Test Chat
853 < <message type="groupchat" from="test@conf.local/bob">
854 < <body>Hello, again!</body>
856 < <message type="groupchat" from="test@conf.local/bob">
857 < <delay stamp="2017-01-01T00:00:00"/>
858 < <body>Goodbye!</body>
860 < <message type="groupchat" from="test@conf.local/bob">
861 < <html>I <i>said</i> <b>HELLO!</b></html>
866 |00:00 [test] bob: Goodbye!
867 |00:00 [test] bob: Hello, again!
868 |00:00 [test] bob: I said HELLO!
872 < <presence id="join" from="test@conf.local/bob">
873 < <item jid="2@local"/>
875 < <message from="1@local">
876 < <body>I'm Andy!</body>
878 > <iq id='auto-vcard' * to='1@local'>
879 > <vCard xmlns='vcard-temp'/>
881 < <iq id='auto-vcard' from='1@local'>
883 < <FN>Andy Spencer</FN>
889 |00:00 Andy Spencer: I'm Andy!
890 | Windows: [system] [Andy Spencer]
894 input /abbrev first &&
896 | Windows: [system] [andy]
901 | Windows: [system] [spencer]
906 | Windows: [system] [aspencer]
909 input /abbrev initials
911 | Windows: [system] [as]
915 test_xmpp_servers() {
916 setup -c -s 6001 -s 6002 <<-EOF
924 jid = "andy@serv1/lame"
931 jid = "andy@sevr2/lame"
942 filter = "serv.|chan.|other.|irc"
948 < <stream:features><bind/></stream:features>
950 > <iq*><bind*><resource>lame</resource></bind></iq>
953 > <iq*><session*/></iq>
955 > <presence*><*/></presence>
956 < <presence from="chan1@conf.serv1/alice1"/>
957 < <presence from="other1@conf.serv1/bob1"/>
963 < <stream:features><bind/></stream:features>
965 > <iq*><bind*><resource>lame</resource></bind></iq>
968 > <iq*><session*/></iq>
970 > <presence*><*/></presence>
971 < <presence from="chan2@conf.serv2/alice2"/>
972 < <presence from="other2@conf.serv2/bob2"/>
975 |00:00 [serv1] *** XMPP Server: serv1
976 |00:00 [serv2] *** XMPP Server: serv2
977 |00:00 [chan1] *** XMPP Channel: chan1
978 |00:00 [chan1] *** alice1 entered room.
979 |00:00 [other1] *** bob1 entered room.
980 |00:00 [chan2] *** XMPP Channel: chan2
981 |00:00 [chan2] *** alice2 entered room.
982 |00:00 [other2] *** bob2 entered room.
986 test_xmpp_commands() {
992 input /config more_magic
993 input /kill_all_humans
995 |00:00 [local] *** usage: /join <channel>
996 |00:00 [local] *** usage: /query <user>
997 |00:00 [local] *** Unimplemented: /config <arg>
998 |00:00 [local] *** Unknown command /kill_all_humans
1005 |00:00 [local] *** Cannot send to server
1006 |00:00 [local] *** Cannot get names from server
1007 |00:00 [local] *** Cannot get config from server
1013 > <iq id='items' * to='localhost'><query xmlns='*/disco#items'/></iq>
1014 < <iq id='items'><item name='Public Chatrooms' jid='conf.localhost'/></iq>
1015 > <iq id='info' * to='localhost'><query xmlns='*/disco#info'/></iq>
1016 < <iq id='info'><identity name='chatrooms'/><feature var='vcard-temp'/></iq>
1019 |00:00 [local] *** item: [conf.localhost] Public Chatrooms
1020 |00:00 [local] *** identity: chatrooms
1021 |00:00 [local] *** feature: vcard-temp
1029 > <iq id='names' * to='test@conf.local'><query xmlns='*/disco#items'/></iq>
1030 < <iq id='names' from='test@conf.local'><item jid='test@conf.local/Alice'/></iq>
1031 > <iq id='names' * to='other@conf.local'><query xmlns='*/disco#items'/></iq>
1032 < <iq id='names' from='other@conf.local'><item jid='other@conf.local/Bob'/></iq>
1033 > <presence id='join' * to='other@conf.local/andy'><x xmlns='*/muc'/></presence>
1036 |00:00 [test] *** User: Alice (test@conf.local/Alice)
1037 |00:00 [other] *** User: Bob (other@conf.local/Bob)
1045 > <message id='chat0' * to='other@conf.local' type='groupchat'><body>hello other</body></message>
1046 < <message from='other@conf.local/andy' type='groupchat'><body>hello other</body></message>
1047 > <iq id='config' * to='other@conf.local'><query xmlns='*/muc#owner'/></iq>
1048 < <iq from='other@conf.local'>
1049 < <title>Channel Setup</title>
1050 < <instructions>Fill out the form, yo!</instructions>
1051 < <field var='magic' type='hidden'/>
1052 < <field var='topic' type='string' label='Room Topic'/>
1056 |00:00 [other] andy: hello other
1057 |00:00 [other] *** Title: Channel Setup
1058 |00:00 [other] *** Fill out the form, yo!
1059 |00:00 [other] *** topic -- Room Topic (string)
1067 > <message id='chat1' * to='alice@localhost' type='chat'><body>hello alice</body></message>
1068 > <iq id='vcard' * to='alice@localhost'><vCard xmlns='vcard-temp'/></iq>
1069 < <iq id='vcard' from='alice@localhost'><vCard><FN>Adelais</FN></vCard></iq>
1070 > <iq id='vcard' * to='bob@localhost'><vCard xmlns='vcard-temp'/></iq>
1071 < <iq id='vcard' from='bob@localhost'><vCard><FN>Robert</FN></vCard></iq>
1074 |00:00 [Adelais] andy: hello alice
1075 |00:00 [Adelais] *** Begin vCard (alice)
1076 |00:00 [Adelais] *** FN -> Adelais
1077 |00:00 [Adelais] *** End vCard
1078 |00:00 [Robert] *** Begin vCard (bob)
1079 |00:00 [Robert] *** FN -> Robert
1080 |00:00 [Robert] *** End vCard
1086 for i in `seq 10 -1 0`; do
1087 if [ -f "$TMPDIR/pid.txt" ]; then
1090 if [ "$i" -eq 0 ]; then
1091 fail -v "Process failed to start"
1098 for i in `seq 50 -1 0`; do
1100 for p in "${PIDS[@]}"; do
1101 if [ ! -f "/proc/$p/status" ]; then
1102 if [ "$1" != '-e' ]; then
1103 fail -v "Process exited early: $p"
1109 if /bin/grep -q '^State:.*S' "/proc/$p/status" 2>/dev/null; then
1112 if [ "$i" -eq 0 ]; then
1113 fail -v "Process failed to sleep: $p" \
1114 "-- $(grep "State:" /proc/$p/status)" \
1115 "-- $(sed 's/\x0/ /' "/proc/$p/cmdline")"
1120 debug "wait_idle ok"
1127 debug "listen $1 $2"
1131 if [ "$proto" = ssl ] && [ ! -f "test.key" -o ! -f "test.crt" ]; then
1132 openssl req -newkey rsa:2048 -nodes -x509 \
1133 -days 7 -subj "/CN=example.com" \
1134 -keyout "test.key" -out "test.crt" \
1137 if [ "$proto" = ssl ]; then
1138 addr="OPENSSL-LISTEN:$port"
1139 addr="$addr,reuseaddr,nodelay"
1140 addr="$addr,key=test.key,cert=test.crt,verify=0"
1142 addr="TCP-LISTEN:$port"
1143 addr="$addr,reuseaddr,nodelay"
1146 coproc socat "STDIO" "$addr"
1147 RECV[$port]=${COPROC[0]}
1148 SEND[$port]=${COPROC[1]}
1149 PIDS+=("$COPROC_PID")
1151 if [ ! -e "$TMPDIR/send_$port" ] ||
1152 [ ! -e "$TMPDIR/recv_$port" ]; then
1153 mkfifo "$TMPDIR/send_$port"
1154 mkfifo "$TMPDIR/recv_$port"
1156 socat "STDIO" "$addr" \
1157 < "$TMPDIR/send_$port" \
1158 > "$TMPDIR/recv_$port" &
1159 exec {SEND[$port]}> "$TMPDIR/send_$port"
1160 exec {RECV[$port]}< "$TMPDIR/recv_$port"
1163 debug "${PIDS[@]} | >${SEND[$port]} <${RECV[$port]}"
1168 id="$(cksum <<<"$txt")"
1170 if [ ! -f "$TMPDIR/libpreload-$id.so" ]; then
1172 echo "$txt" > "$TMPDIR/preload-$id.c"
1173 gcc -Wall -fPIC -shared -o \
1174 "$TMPDIR/libpreload-$id.so" \
1175 "$TMPDIR/preload-$id.c"
1177 cp "$TMPDIR/libpreload-$id.so" \
1178 "$TMPDIR/libpreload.so"
1183 rm -f "$TMPDIR/.lamechatrc" \
1190 -x) listen ssl $2; shift ;;
1191 -s) listen tcp $2; shift ;;
1192 -c) cat > "$TMPDIR/.lamechatrc" ;;
1193 *) error "Invalid setup" ;;
1198 cat >"$TMPDIR/start.sh" <<-EOF
1199 echo \$\$ > "$TMPDIR/pid.txt"
1201 $([ -f "$TMPDIR/libpreload.so" ] &&
1202 echo export LD_PRELOAD=\"$TMPDIR/libpreload.so\")
1203 export HOME="$TMPDIR"
1207 screen -S "$SESSION-p" -d -m -- \
1208 screen -S "$SESSION" /bin/sh
1209 screen -S "$SESSION" -X stuff "/bin/sh $TMPDIR/start.sh\n"
1212 pid=$(cat "$TMPDIR/pid.txt")
1214 debug "pid $pid -- lamechat"
1218 screen -S "$SESSION-p" -X height -w $1 $2
1219 screen -S "$SESSION" -X height -w $1 $2
1232 screen -S "$SESSION" -X stuff "$keys"
1236 send_fd="${SEND[$1]}"
1237 recv_fd="${RECV[$1]}"
1238 if [ -z "$send_fd" -o -z "$recv_fd" ]; then
1239 error "Invalid server port: $1"
1241 while IFS= read line; do
1242 debug "line: [$line]"
1246 "> "*) recv="${line#> }" ;;
1247 "< "*) send="${line#< }" ;;
1249 if [ "$recv" ]; then
1250 if [[ "$recv" == *'<'* ]]; then
1253 for i in ${recv//[^>]/ }; do
1254 if ! read -u"$recv_fd" -d'>' -t0.5 tag; then
1255 fail "Timeout receiving '$recv'"
1259 elif [[ "$recv" == ' ' ]]; then
1260 if ! IFS= read -n1 -u"$recv_fd" -t0.5 line; then
1261 fail "Timeout receiving '$recv'"
1264 if ! read -u"$recv_fd" -t0.5 line; then
1265 fail "Timeout receiving '$recv'"
1268 if [[ "$line" != $recv ]]; then
1269 fail "Received incorrect data\n" \
1270 " Expect: $recv\n" \
1273 debug "recv: $recv -> $line"
1275 if [ "$send" ]; then
1277 echo "$send" >&"$send_fd"
1284 if [ "$1" == "-e" ]; then
1287 screen -S "$SESSION" -X hardcopy "$TMPDIR/output.txt"
1291 // { sub(/^[0-2][0-9]:[0-5][0-9]/, "00:00") }
1292 // { sub(/^[0-9]+\.[0-9][0-9][0-9]: /, "0.000: ") }
1293 // { sub(/^/, "|") }
1295 ' < "$TMPDIR/output.txt" > "$TMPDIR/actual.txt"
1296 cat > "${TMPDIR}/expect.txt"
1297 out=$(diff -u99999 "$TMPDIR"/{expect,actual}.txt || true)
1299 out=$(echo "$out" | tail -n+4)
1301 -i) check=$(echo "$out" | sed '/^+|/d') ;;
1302 -x) check=$(echo "$out" | sed '/^-|/d') ;;
1303 *) check=$(echo "$out") ;;
1305 if [ "$(echo "$check" | sed '/^ /d')" ]; then
1312 if [ "$1" == "-v" ]; then
1317 screen -S "$SESSION" -X hardcopy "$TMPDIR/fail.txt"
1320 sed '/^$/d; s/^/| /' "$TMPDIR/fail.txt"
1326 if [ "${#PIDS}" -gt 0 ]; then
1327 kill -INT "${PIDS[@]}" 2>&1
1330 rm -f "$TMPDIR/libpreload.so"
1331 screen -S "$SESSION" -X quit
1336 if out=$(trap quit EXIT; eval "$name"); then
1342 dt=$(dc -e "$t1 $t0 - p")
1343 printf "%s -- %-20s -- %0.2fs\n" \
1344 "$result" "$name" "$dt"
1346 echo "$out" | sed 's/^/ /'
1348 if [ -f "core" ]; then
1349 echo " Found core file"
1350 gdb -batch -q -ex bt -ex quit ./lamechat core |
1352 mv "core" "core-$name"
1371 info "$(date +%s.%N) $*"
1376 echo "usage: ./test.sh [-dh] [test_case]"
1379 echo " -d,--debug Print debug information"
1380 echo " -h,--help Print usage information"
1383 echo "$avail" | sed 's/^/ /'
1388 avail=$(grep -o '^test_[a-z0-9_]*' "${BASH_SOURCE}")
1389 opts=$(getopt -n "$0" -o dh -l debug,help -- "$@")
1390 eval set -- "${opts[@]}"
1402 if these=$(echo "$avail" | grep -F "$1"); then
1405 error "Unknown test: $1"
1409 if [ "${#tests}" -eq 0 ]; then
1426 TMPDIR=/tmp/lamechat-test
1427 SESSION=lamechat-test