serval-dna/tests/dnaprotocol
Andrew Bettison 0022990e72 Add new dnaprotocol test
Dnahelpers on many nodes resolve the same DIDs

Currently fails, suspicious error from overlay_mdp_sanitytest_sourceaddr()
2012-08-02 17:18:04 +09:30

189 lines
6.2 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"
instances_reach_each_other() {
local I J
for I; do
for J; do
[ $I = $J ] && continue
local logvar=LOG${I#+}
local sidvar=SID${J#+}
if ! grep "PEER REACHABLE, sid=${!sidvar}" "${!logvar}"; then
return 1
fi
done
done
return 0
}
setup() {
setup_servald
assert_no_servald_processes
configure_servald_server() { set_server_vars; }
start_servald_instances +A +B
wait_until --sleep=0.25 instances_reach_each_other +A +B
set_instance +A
executeOk_servald config set debug.all Yes
}
teardown() {
stop_all_servald_servers
kill_all_servald_processes
assert_no_servald_processes
}
set_server_vars() {
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 No
executeOk_servald config set debug.tx No
executeOk_servald config set debug.rx No
executeOk_servald config set debug.mdprequests Yes
}
doc_MultiServer="Start three servald servers with dummy interfaces"
setup_MultiServer() {
setup_servald
assert_no_servald_processes
configure_servald_server() { set_server_vars; }
}
test_MultiServer() {
start_servald_instances +A +B +C
}
doc_LookupWildcard="Lookup by wildcard"
test_LookupWildcard() {
executeOk_servald dna lookup "*"
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "^sid://$SIDA/$DIDA:$DIDA:$NAMEA$"
assertStdoutGrep --matches=1 "^sid://$SIDB/$DIDB:$DIDB:$NAMEB$"
}
doc_LookupEmpty="Lookup by empty string"
test_LookupEmpty() {
executeOk_servald dna lookup ""
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "^sid://$SIDA/$DIDA:$DIDA:$NAMEA$"
assertStdoutGrep --matches=1 "^sid://$SIDB/$DIDB:$DIDB:$NAMEB$"
}
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 "$DIDA"
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "^sid://$SIDA/$DIDA:$DIDA:$NAMEA$"
executeOk_servald dna lookup "$DIDB"
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "^sid://$SIDB/$DIDB:$DIDB:$NAMEB$"
}
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 ":$SIDA:"
assertStdoutGrep --matches=1 ":$DIDA:"
assertStdoutGrep --matches=1 ":$NAMEA"
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=1 ":$SIDB:"
assertStdoutGrep --matches=0 ":$DIDB:"
assertStdoutGrep --matches=0 ":$NAMEB"
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 ":$SIDB:"
assertStdoutGrep --matches=1 ":$DIDB:"
assertStdoutGrep --matches=1 ":$NAMEB"
assertStdoutGrep --matches=0 "did-not-resolved"
}
doc_MultiLookupNumber="Lookup by phone number many nodes reply"
setup_MultiLookupNumber() {
setup_servald
assert_no_servald_processes
dnahelper="$TFWTMP/dnahelper"
cat >"$dnahelper" <<'EOF'
#!/bin/sh
echo STARTED
while read line
do
token="${line%%|*}"
case "$1:$line" in
A:*'|00001|') echo "$token|uri:A1|00001|Name One|";;
A:*'|00002|') echo "$token|uri:A2|00002|Name Two|";;
B:*'|00001|') echo "$token|uri:B1|00001|Name Three|";;
B:*'|00002|') echo "$token|uri:B2|00002|Name Four|";;
B:*'|00003|') echo "$token|uri:B3|00003|Name Five|";;
C:*'|00001|') echo "$token|uri:C1|00001|Name Six|";;
esac
echo DONE
done
EOF
chmod 0755 "$dnahelper"
configure_servald_server() {
set_server_vars
executeOk_servald config set debug.dnahelper on
executeOk_servald config set dna.helper.executable "$dnahelper"
executeOk_servald config set dna.helper.argv.1 "$instance_name"
}
start_servald_instances +A +B +C +D
wait_until --sleep=0.25 instances_reach_each_other +A +B +C +D
set_instance +D
}
test_MultiLookupNumber() {
executeOk_servald dna lookup 00001
assertStdoutLineCount '==' 3
assertStdoutGrep --matches=1 "uri:A1:00001:Name One$"
assertStdoutGrep --matches=1 "uri:B1:00001:Name Three$"
assertStdoutGrep --matches=1 "uri:C1:00001:Name Six$"
executeOk_servald dna lookup 00002
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "uri:A2:00002:Name Two$"
assertStdoutGrep --matches=1 "uri:B2:00002:Name Four$"
executeOk_servald dna lookup 00003
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "uri:B3:00003:Name Five$"
}
runTests "$@"