serval-dna/tests/dnahelper

105 lines
4.2 KiB
Plaintext
Raw Normal View History

#!/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
}
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 dna.helper "$TFWTMP/dnahelper"
}
setup_dnahelper() {
cat >"$TFWTMP/dnahelper" <<EOF
#!/usr/bin/env python
# Sample DNA Helper application for testing
import sys;
def main():
print "STARTED"
while True:
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")
if number == "5551234":
# Single result, SIP URI
print "%s|sip://5551234@10.1.2.3|%s|%s|" % (token, number, "Will Smith")
if number == "5551001":
# Empty URI field
print "%s||%s|%s|" % (token, number, "Empty URI")
if number == "5551002":
# Empty DID field
print "%s|sip://123@1.2.3.4||%s|" % (token, "Empty DID")
if number == "5551003":
# Empty CALLERID field
print "%s|sip://empty-callerid@1.2.3.4|%s||" % (token, number)
if number == "5551004":
# Excessively long callerid
print "%s|sip://long-callerid@1.2.3.4|%s|askjdhfkjashdfkljahsdflkjhasdljkfhasldjkfhaslkjdfhalskdjfhklajsdhflkajsdhflkjasdhflkjashdflkjashdflkjahsdflkjahsdfjklhasdljkfhasjkdfhakljsdfhklajsdhflkjashdfljkashdflkjashdf|" % (token, number)
if number == "5551005":
# Excessively long DID
print "%s|sip://long-did@1.2.3.4|askjdhfkjashdfkljahsdflkjhasdljkfhasldjkfhaslkjdfhalskdjfhklajsdhflkajsdhflkjasdhflkjashdflkjashdflkjahsdflkjahsdfjklhasdljkfhasjkdfhakljsdfhklajsdhflkjashdfljkashdflkjashdf|%s|" % (token, "Agent Smith")
if number == "5551006":
# Excessively long URI
print "%s|sip://askjdhfkjashdfkljahsdflkjhasdljkfhasldjkfhaslkjdfhalskdjfhklajsdhflkajsdhflkjasdhflkjashdflkjashdflkjahsdflkjahsdfjklhasdljkfhasjkdfhakljsdfhklajsdhflkjashdfljkashdflkjashdfasdjfkjahsdfjkhasdfkjlhasjldkfhajksdhflkjasdhfkljashdfkljahsdfkljhasdfkljhasdlkjfhasdlkjfhaslkjdfhakljsdhfklajshdfkljashdfljkashdflkjashdflkjahsdfkjlahsdflkjhasdfljkhasdkfjlhaslkdjfhaslkjdfhaklsjdfhaklsjdhflkajsdhflkjasdhflkjashdfljkashdfkljashdflkjashdflkjashdflkjashdflkjashdflkjashdfljkahsdflkjahsdfjklahsdfljkahsdflkjhasdflkjhasdjkfhaskjdlfhaslkjdfhaskljdfhasljkdfhalskdfhalkjsdhflkjasdhflkjahsdflkjahsdflkjahsdflkjhasdflkjahsdflkjahsdflkjahsdfkljashdflkajshdflkajsdhflaksjdfhalksjdfhlasdkjfh|%s|%s|" % (token, number, "Agent Smith")
if number == "5551007":
# Incorrect token
print "cheeseburger|sip://incorrect-token@1.2.3.4|%s||" % (token, number)
print "DONE"
if __name__ == "__main__":
main()
EOF
}
doc_MultiServer="Start three servald servers with dna helper"
test_MultiServer() {
start_servald_instances +A +B +C
}
runTests "$@"