serval-dna/tests/dnaprotocol

130 lines
4.3 KiB
Plaintext
Raw Normal View History

2012-06-21 03:58:21 +00:00
#!/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"
is_reachable() {
local sidvar="SID${1#+}"
grep "PEER REACHABLE, sid=${!sidvar}" "$instance_servald_log"
}
2012-06-21 03:58:21 +00:00
setup() {
setup_servald
assert_no_servald_processes
start_servald_instances +A +B
set_instance +B
wait_until --sleep=0.25 is_reachable +A
set_instance +A
wait_until --sleep=0.25 is_reachable +B
executeOk_servald config set debug.all Yes
2012-06-21 03:58:21 +00:00
}
teardown() {
stop_all_servald_servers
2012-06-21 03:58:21 +00:00
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 mdp.wifi.tick_ms 100
executeOk_servald config set mdp.selfannounce.ticks_per_full_address 1
executeOk_servald config set debug.interfaces Yes
executeOk_servald config set debug.packetformats No
executeOk_servald config set debug.routing Yes
executeOk_servald config set debug.tx No
executeOk_servald config set debug.rx No
executeOk_servald config set debug.mdprequests Yes
2012-06-21 05:34:34 +00:00
}
doc_MultiServer="Start three servald servers with dummy interfaces"
setup_MultiServer() {
setup_servald
assert_no_servald_processes
2012-06-21 05:34:34 +00:00
}
test_MultiServer() {
start_servald_instances +A +B +C
2012-06-21 03:58:21 +00:00
}
doc_LookupWildcard="Lookup by wildcard"
test_LookupWildcard() {
executeOk_servald dna lookup "*"
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "^sid://$SIDA/5550001:5550001:Agent A Smith$"
assertStdoutGrep --matches=1 "^sid://$SIDB/5550002:5550002:Agent B Smith$"
2012-06-21 03:58:21 +00:00
}
doc_LookupEmpty="Lookup by empty string"
test_LookupEmpty() {
executeOk_servald dna lookup ""
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "^sid://$SIDA/5550001:5550001:Agent A Smith$"
assertStdoutGrep --matches=1 "^sid://$SIDB/5550002:5550002:Agent B Smith$"
}
doc_LookupNumber="Lookup by phone number"
test_LookupNumber() {
executeOk_servald dna lookup "5551234"
assertStdoutLineCount '==' 0
executeOk_servald dna lookup "555000"
assertStdoutLineCount '==' 0
executeOk_servald dna lookup "55500011"
assertStdoutLineCount '==' 0
executeOk_servald dna lookup "5550001"
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "^sid://$SIDA/5550001:5550001:Agent A Smith$"
executeOk_servald dna lookup "5550002"
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "^sid://$SIDB/5550002:5550002:Agent B Smith$"
}
doc_NodeinfoLocal="Node info auto-resolves for local identities"
test_NodeinfoLocal() {
# node info for a local identity returns DID/Name since it is free, even
# if it isn't asked for.
executeOk_servald node info $SIDA
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "Agent A Smith"
assertStdoutGrep --matches=0 "did-not-resolved"
}
doc_NodeinfoRemote="Node info resolves remote identities"
test_NodeinfoRemote() {
# if resolvedid is not specified for a remote identity, then don't resolve
# it.
executeOk_servald node info $SIDB
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=0 "Agent B Smith"
assertStdoutGrep --matches=1 "did-not-resolved"
# But if it resolvedid is specified, then do resolve it using DNA
executeOk_servald node info $SIDB resolvedid
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "Agent B Smith"
assertStdoutGrep --matches=0 "did-not-resolved"
}
2012-06-21 03:58:21 +00:00
runTests "$@"