serval-dna/tests/dnaprotocol
2012-07-03 17:38:54 +09:30

183 lines
5.6 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
}
start_servald_instance() {
push_instance
set_instance "$1"
executeOk_servald config set debug.interfaces Yes
executeOk_servald config set debug.packetformats No
executeOk_servald config set debug.routing No
executeOk_servald config set debug.tx No
executeOk_servald config set debug.rx No
executeOk_servald config set interfaces "+>$2"
executeOk_servald config set monitor.socket "org.servalproject.servald.monitor.socket.$TFWUNIQUE.$instance_name"
executeOk_servald config set mdp.socket "org.servalproject.servald.mdp.socket.$TFWUNIQUE.$instance_name"
executeOk_servald config set mdp.wifi.tick_ms 100
executeOk_servald config set mdp.selfannounce.ticks_per_full_address 1
executeOk_servald keyring add
assert [ -e "$SERVALINSTANCE_PATH/serval.keyring" ]
executeOk_servald keyring list
tfw_cat --stdout
sid=$(replayStdout | sed -ne "1s/^\($rexp_sid\):.*\$/\1/p")
assert --message='main identity known' [ -n "$sid" ]
executeOk_servald set did $sid 5550001 "Agent $instance_name Smith"
start_servald_server
log="$instance_servald_log"
pop_instance
}
start_servald_instances() {
DUMMYNET=$PWD/dummy
>$DUMMYNET
start_servald_instance +A $DUMMYNET
SIDA=$sid
LOGA="$log"
start_servald_instance +B $DUMMYNET
SIDB=$sid
LOGB="$log"
# Now wait until they see each other.
sleep 30 &
local timeout_pid=$!
tfw_log "Wait for instances to see each other"
while ! grep "^INFO:.*ADD OVERLAY NODE sid=$SIDB" "$LOGA" || ! grep "^INFO:.*ADD OVERLAY NODE sid=$SIDA" "$LOGB"; do
kill -0 $timeout_pid 2>/dev/null || fail "timeout"
tfw_log "Sleep"
sleep 0.1
done
tfw_log "# Dummynet file:" $(ls -l $DUMMYNET)
set_instance +A
executeOk_servald id peers
assertStdoutLineCount '==' 1
assertStdoutGrep "$SIDB"
set_instance +B
executeOk_servald id peers
assertStdoutLineCount '==' 1
assertStdoutGrep "$SIDA"
set_instance +A
}
doc_MultiServer="Start two servald instances with dummy interface"
setup_MultiServer() {
setup
}
test_MultiServer() {
start_servald_instances
}
doc_LookupWildcard="Lookup by wildcard"
setup_LookupWildcard() {
setup
start_servald_instances
set_instance +A
}
test_LookupWildcard() {
executeOk_servald dna lookup "*"
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "^sid://$SIDA/5550001:5550001:Agent A Smith$"
assertStdoutGrep --matches=1 "^sid://$SIDB/5550001:5550001:Agent B Smith$"
}
doc_LookupEmpty="Lookup by empty string"
setup_LookupEmpty() {
setup
start_servald_instances
set_instance +A
}
test_LookupEmpty() {
executeOk_servald dna lookup ""
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "^sid://$SIDA/5550001:5550001:Agent A Smith$"
assertStdoutGrep --matches=1 "^sid://$SIDB/5550001:5550001:Agent B Smith$"
}
doc_LookupNumber="Lookup by phone number"
setup_LookupNumber() {
setup
start_servald_instances
set_instance +A
}
test_LookupNumber() {
# Make sure we get no false positives
executeOk_servald dna lookup "5551234"
assertStdoutLineCount '==' 0
executeOk_servald dna lookup "555000"
assertStdoutLineCount '==' 0
executeOk_servald dna lookup "55500011"
assertStdoutLineCount '==' 0
# Make sure we get the right results, and no duplicates
executeOk_servald dna lookup "5550001"
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "^sid://$SIDA/5550001:5550001:Agent A Smith$"
assertStdoutGrep --matches=1 "^sid://$SIDB/5550001:5550001:Agent B Smith$"
}
doc_NodeinfoLocal="Node info auto-resolves for local identities"
setup_NodeinfoLocal() {
setup
start_servald_instances
set_instance +A
}
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"
setup_NodeinfoRemote() {
setup
start_servald_instances
set_instance +A
}
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"
}
runTests "$@"