serval-dna/tests/dnahelper
2012-07-19 17:59:45 +09:30

128 lines
3.8 KiB
Bash
Executable File

#!/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
}
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() {
dnahelper="$TFWTMP/dnahelper"
cat >"$dnahelper" <<EOF
#!/usr/bin/env python
# Sample DNA Helper application for testing
import sys
def main():
print "STARTED"
sys.stdout.flush()
while True:
sys.stderr.write("wah\n")
line = sys.stdin.readline().strip()
if line == "":
# EOF detection is broken :(
break
s = line.split('|')
if len(s) != 3:
print "ERROR"
continue
(token, number, xxx) = s
if number == "12345":
# Multiple results (SID/VoMP results)
print "%s|sid:%s|%s|%s|" % (token, token, number, "Agent A. Smith")
print "%s|sid:%s|%s|%s|" % (token, token, number, "Agent B. Smith")
elif number == "5551234":
# Single result, SIP URI
print "%s|sip://5551234@10.1.2.3|%s|%s|" % (token, number, "Will Smith")
elif number == "5551001":
# Empty URI field
print "%s||%s|%s|" % (token, number, "Empty URI")
elif number == "5551002":
# Empty DID field
print "%s|sip://123@1.2.3.4||%s|" % (token, "Empty DID")
elif number == "5551003":
# Empty CALLERID field
print "%s|sip://empty-callerid@1.2.3.4|%s||" % (token, number)
elif number == "5551004":
# Excessively long callerid
print "%s|sip://long-callerid@1.2.3.4|%s|%s|" % (token, 'x' * 200, number)
elif number == "5551005":
# Excessively long DID
print "%s|sip://long-did@1.2.3.4|%s|%s|" % (token, 'x' * 200, "Agent Smith")
elif number == "5551006":
# Excessively long URI
print "%s|sip://%s|%s|%s|" % (token, 'x' * 1000, number, "Agent Smith")
elif number == "5551007":
# Incorrect token
print "cheeseburger|sip://incorrect-token@1.2.3.4|%s||" % (token, number)
elif number == "11111":
print "%s|A|%s|B|" % (token, number)
print "DONE"
sys.stdout.flush()
if __name__ == "__main__":
main()
EOF
chmod 0755 "$dnahelper"
executeOk "$dnahelper" <<EOF
ToKeN|11111|
EOF
assertStdoutIs -e "STARTED\nToKeN|A|11111|B|\nDONE\n"
}
doc_ExecError="Non-existent DNA helper executable"
setup_ExecError() {
setup
dnahelper=/non/existent
assert [ ! -e "$dnahelper" ]
start_servald_instances +A
}
test_ExecError() {
executeOk_servald dna lookup 12345
}
doc_Simple="Simple DNA helper test"
setup_Simple() {
setup
setup_dnahelper
start_servald_instances +A
}
test_Simple() {
executeOk_servald dna lookup 12345
}
runTests "$@"