#!/bin/bash # Tests for Serval DNA server operations. # # Copyright 2012 Paul Gardner-Stephen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. source "${0%/*}/../testframework.sh" source "${0%/*}/../testdefs.sh" setup() { setup_servald assert_no_servald_processes setup_dnahelper start_servald_instances +A } teardown() { stop_all_servald_servers kill_all_servald_processes assert_no_servald_processes } # Called by start_servald_instances immediately before starting the server # process in each instance. configure_servald_server() { executeOk_servald config set log.show_pid on executeOk_servald config set log.show_time on executeOk_servald config set debug.dnahelper on executeOk_servald config set dna.helper.executable "$dnahelper" } setup_dnahelper() { export SID_JOE_A=1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEA export SID_JOE_B=1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEB export SID_JOE_C=1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEC export SID_JOE_D=1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDED export SID_JOE_E=1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEE export SID_JOE_F=1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF export SID_ECCLES=1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDE0 dnahelper="$TFWTMP/dnahelper" cat >"$dnahelper" <<'EOF' #!/bin/sh echo STARTED while read line do token="${line%%|*}" line="${line#*|}" did="${line%%|*}" line="${line#*|}" case "$token|$did|$line" in '|'*'|') echo "empty token" >&2 ;; *'||') echo "empty DID" >&2 ;; *'|00000|') # For verification during setup echo "$token|A|$did|B|" ;; *'|00001|') # One valid reply echo "$token|sip://$SID_JOE_A@10.1.1.1|$did|Joe A. Bloggs|" ;; *'|00002|') # Two valid replies echo "$token|sip://$SID_JOE_A@10.1.1.1|$did|Joe A. Bloggs|" sleep 0.1 echo "$token|sip://$SID_JOE_B@10.1.1.1|$did|Joe B. Bloggs|" sleep 0.1 ;; *'|00003|') # Three valid replies echo "$token|sip://$SID_JOE_A@10.1.1.1|$did|Joe A. Bloggs|" sleep 0.1 echo "$token|sip://$SID_JOE_B@10.1.1.1|$did|Joe B. Bloggs|" sleep 0.1 echo "$token|sip://$SID_JOE_C@10.1.1.1|$did|Joe C. Bloggs|" sleep 0.1 ;; *'|00004|') # Empty URI echo "$token||$did|Eccles|" ;; *'|000051|') # Malformed URI echo "$token|Bluebottle|$did|Eccles|" ;; *'|000052|') # Malformed URI echo "$token|sip://Sea goon|$did|Eccles|" ;; *'|000053|') # Malformed URI echo "$token|sip:|$did|Eccles|" ;; *'|000061|') # Mismatched token echo "$SID_ECCLES|did://$SID_ECCLES/$did|$did|Eccles|" ;; *'|000062|') # Empty token echo "|did://$SID_ECCLES/$did|$did|Eccles|" ;; *'|000063|') # Invalid token (not a SID) echo "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEX|did://$SID_ECCLES/$did|$did|Eccles|" ;; *'|000064|') # Long token echo "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF0|did://$SID_ECCLES/$did|$did|Eccles|" ;; *'|000065|') # Short token echo "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF1234567890ABCDE|did://$SID_ECCLES/$did|$did|Eccles|" ;; *'|000071|') # Mismatched DID echo "$token|sip://$SID_ECCLES/$did|99999|Eccles|" ;; *'|000072|') # Empty DID echo "$token|sip://$SID_ECCLES/$did||Eccles|" ;; *'|000073|') # Invalid DID echo "$token|sip://$SID_ECCLES/$did|9999X|Eccles|" ;; *'|000074|') # Long DID echo "$token|sip://$SID_ECCLES/$did|123456789012345678901234567890123|Eccles|" ;; *'|000075|') # Short DID echo "$token|sip://$SID_ECCLES/$did|9999|Eccles|" ;; *'|000081|') # Malformed reply, missing final delimiter echo "$token|sip://$SID_ECCLES/$did|9999|Eccles" ;; *'|000082|') # Malformed reply, long name echo "$token|sip://$SID_ECCLES/$did|9999|Abcd efgh ijkl mnop qrst uvwx yzab cdef ghij klmn opqr stuv wxyz abcd efgh ijkl|" ;; *'|000083|') # Malformed reply, empty line echo ;; *'|000084|') # Malformed reply, missing \n (which swallows the following DONE line) echo -n "$token|sip://$SID_JOE_A@10.1.1.1|$did|Joe A. Bloggs|" ;; *'|000085|') # Malformed reply, line too long for i in 1 2 3 4 5 6 7 8 9 0; do echo -n 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 echo -n 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 echo -n 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 echo -n 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 echo -n 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 echo -n 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 echo -n 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 echo -n 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 echo -n 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 echo -n 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 done echo ;; *'|00009|') # Take too long to respond sleep 2 echo "$token|sip://$SID_JOE_D@10.1.1.1|$did|Joe D. Bloggs|" ;; *'|00010|') # Spurious output after DONE echo "$token|sip://$SID_JOE_E@10.1.1.1|$did|Joe E. Bloggs|" echo DONE echo "$token|sip://$SID_JOE_F@10.1.1.1|$did|Joe F. Bloggs|" ;; *'|00011|') # Die unexpectedly echo "goodbye cruel world" >&2 exit 42 ;; *'|'*'|') echo "token=$token did=$did line=$line" >&2 ;; *) echo "garbage line" >&2 ;; esac echo DONE done EOF chmod 0755 "$dnahelper" executeOk "$dnahelper" <