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"
|
|
|
|
|
2012-08-02 07:48:04 +00:00
|
|
|
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
|
2012-07-18 10:05:47 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 03:58:21 +00:00
|
|
|
setup() {
|
|
|
|
setup_servald
|
|
|
|
assert_no_servald_processes
|
2012-09-17 06:00:05 +00:00
|
|
|
foreach_instance +A +B create_single_identity
|
2012-08-02 07:48:04 +00:00
|
|
|
configure_servald_server() { set_server_vars; }
|
2012-07-04 04:42:36 +00:00
|
|
|
start_servald_instances +A +B
|
2012-08-02 07:48:04 +00:00
|
|
|
wait_until --sleep=0.25 instances_reach_each_other +A +B
|
2012-07-04 04:42:36 +00:00
|
|
|
set_instance +A
|
2012-07-31 08:17:59 +00:00
|
|
|
executeOk_servald config set debug.all Yes
|
2012-06-21 03:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
2012-06-26 07:14:34 +00:00
|
|
|
stop_all_servald_servers
|
2012-06-21 03:58:21 +00:00
|
|
|
kill_all_servald_processes
|
|
|
|
assert_no_servald_processes
|
|
|
|
}
|
|
|
|
|
2012-08-02 07:48:04 +00:00
|
|
|
set_server_vars() {
|
2012-07-27 08:34:20 +00:00
|
|
|
executeOk_servald config set log.show_pid on
|
|
|
|
executeOk_servald config set log.show_time on
|
2012-07-04 04:42:36 +00:00
|
|
|
executeOk_servald config set mdp.wifi.tick_ms 100
|
|
|
|
executeOk_servald config set mdp.selfannounce.ticks_per_full_address 1
|
2012-06-28 08:50:38 +00:00
|
|
|
executeOk_servald config set debug.interfaces Yes
|
2012-07-03 08:07:03 +00:00
|
|
|
executeOk_servald config set debug.packetformats No
|
2012-08-02 07:48:04 +00:00
|
|
|
executeOk_servald config set debug.routing No
|
2012-07-03 08:07:03 +00:00
|
|
|
executeOk_servald config set debug.tx No
|
|
|
|
executeOk_servald config set debug.rx No
|
2012-07-04 01:02:38 +00:00
|
|
|
executeOk_servald config set debug.mdprequests Yes
|
2012-08-14 04:36:59 +00:00
|
|
|
executeOk_servald config set debug.keyring Yes
|
2012-06-21 05:34:34 +00:00
|
|
|
}
|
|
|
|
|
2012-07-02 05:14:11 +00:00
|
|
|
doc_LookupWildcard="Lookup by wildcard"
|
|
|
|
test_LookupWildcard() {
|
2012-06-21 04:13:28 +00:00
|
|
|
executeOk_servald dna lookup "*"
|
2012-06-21 06:28:39 +00:00
|
|
|
assertStdoutLineCount '==' 2
|
2012-09-21 05:47:56 +00:00
|
|
|
assertStdoutGrep --matches=1 "^sid://$SIDA/local/$DIDA:$DIDA:$NAMEA\$"
|
|
|
|
assertStdoutGrep --matches=1 "^sid://$SIDB/local/$DIDB:$DIDB:$NAMEB\$"
|
2012-06-21 03:58:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-02 05:14:11 +00:00
|
|
|
doc_LookupEmpty="Lookup by empty string"
|
|
|
|
test_LookupEmpty() {
|
2012-06-21 04:13:28 +00:00
|
|
|
executeOk_servald dna lookup ""
|
2012-07-25 08:34:45 +00:00
|
|
|
assertStdoutLineCount '==' 2
|
2012-10-05 08:15:30 +00:00
|
|
|
assertStdoutGrep --matches=1 "^sid://$SIDA/local/$DIDA:$DIDA:$NAMEA\$"
|
|
|
|
assertStdoutGrep --matches=1 "^sid://$SIDB/local/$DIDB:$DIDB:$NAMEB\$"
|
2012-06-21 04:13:28 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 07:15:07 +00:00
|
|
|
doc_LookupNonExistent="Lookup non-existent phone number"
|
|
|
|
test_LookupNonExistent() {
|
2012-06-21 06:38:39 +00:00
|
|
|
executeOk_servald dna lookup "5551234"
|
|
|
|
assertStdoutLineCount '==' 0
|
2012-08-06 07:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_LookupLocal="Lookup local phone number"
|
|
|
|
test_LookupLocal() {
|
2012-08-02 06:16:53 +00:00
|
|
|
executeOk_servald dna lookup "$DIDA"
|
2012-07-05 05:27:28 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
2012-10-05 08:15:30 +00:00
|
|
|
assertStdoutGrep --matches=1 "^sid://$SIDA/local/$DIDA:$DIDA:$NAMEA\$"
|
2012-08-06 07:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_LookupRemote="Lookup remote phone number"
|
|
|
|
test_LookupRemote() {
|
2012-08-02 06:16:53 +00:00
|
|
|
executeOk_servald dna lookup "$DIDB"
|
2012-07-05 05:27:28 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
2012-10-05 08:15:30 +00:00
|
|
|
assertStdoutGrep --matches=1 "^sid://$SIDB/local/$DIDB:$DIDB:$NAMEB\$"
|
2012-06-21 06:38:39 +00:00
|
|
|
}
|
2012-06-21 04:13:28 +00:00
|
|
|
|
2012-07-02 05:14:11 +00:00
|
|
|
doc_NodeinfoLocal="Node info auto-resolves for local identities"
|
|
|
|
test_NodeinfoLocal() {
|
2012-06-21 06:51:16 +00:00
|
|
|
# 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
|
2012-08-02 06:16:53 +00:00
|
|
|
assertStdoutGrep --matches=1 ":$SIDA:"
|
|
|
|
assertStdoutGrep --matches=1 ":$DIDA:"
|
|
|
|
assertStdoutGrep --matches=1 ":$NAMEA"
|
2012-06-21 06:51:16 +00:00
|
|
|
assertStdoutGrep --matches=0 "did-not-resolved"
|
|
|
|
}
|
|
|
|
|
2012-07-02 05:14:11 +00:00
|
|
|
doc_NodeinfoRemote="Node info resolves remote identities"
|
|
|
|
test_NodeinfoRemote() {
|
2012-08-02 06:16:53 +00:00
|
|
|
# if resolvedid is not specified for a remote identity, then don't resolve it.
|
2012-06-21 06:51:16 +00:00
|
|
|
executeOk_servald node info $SIDB
|
|
|
|
assertStdoutLineCount '==' 1
|
2012-08-02 06:16:53 +00:00
|
|
|
assertStdoutGrep --matches=1 ":$SIDB:"
|
|
|
|
assertStdoutGrep --matches=0 ":$DIDB:"
|
|
|
|
assertStdoutGrep --matches=0 ":$NAMEB"
|
2012-06-21 06:51:16 +00:00
|
|
|
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
|
2012-08-02 06:16:53 +00:00
|
|
|
assertStdoutGrep --matches=1 ":$SIDB:"
|
|
|
|
assertStdoutGrep --matches=1 ":$DIDB:"
|
|
|
|
assertStdoutGrep --matches=1 ":$NAMEB"
|
2012-06-21 06:51:16 +00:00
|
|
|
assertStdoutGrep --matches=0 "did-not-resolved"
|
|
|
|
}
|
|
|
|
|
2012-08-06 07:15:07 +00:00
|
|
|
setup_multi_helper() {
|
2012-08-02 07:48:04 +00:00
|
|
|
setup_servald
|
|
|
|
assert_no_servald_processes
|
|
|
|
dnahelper="$TFWTMP/dnahelper"
|
2012-09-27 07:20:29 +00:00
|
|
|
echo "#!$BASH" >"$dnahelper"
|
|
|
|
cat >>"$dnahelper" <<'EOF'
|
2012-08-02 07:48:04 +00:00
|
|
|
echo STARTED
|
|
|
|
while read line
|
|
|
|
do
|
|
|
|
token="${line%%|*}"
|
|
|
|
case "$1:$line" in
|
2012-08-06 07:15:07 +00:00
|
|
|
A:*'|00003|') echo "$token|uri:A1|00003|Name One|";;
|
2012-08-02 07:48:04 +00:00
|
|
|
A:*'|00002|') echo "$token|uri:A2|00002|Name Two|";;
|
2012-08-06 07:15:07 +00:00
|
|
|
B:*'|00003|') echo "$token|uri:B1|00003|Name Three|";;
|
2012-08-02 07:48:04 +00:00
|
|
|
B:*'|00002|') echo "$token|uri:B2|00002|Name Four|";;
|
2012-08-06 07:15:07 +00:00
|
|
|
B:*'|00001|') echo "$token|uri:B3|00001|Name Five|";;
|
|
|
|
C:*'|00003|') echo "$token|uri:C1|00003|Name Six|";;
|
2012-08-02 07:48:04 +00:00
|
|
|
esac
|
|
|
|
echo DONE
|
|
|
|
done
|
|
|
|
EOF
|
|
|
|
chmod 0755 "$dnahelper"
|
2012-09-17 06:00:05 +00:00
|
|
|
foreach_instance +A +B +C +D create_single_identity
|
2012-08-02 07:48:04 +00:00
|
|
|
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
|
|
|
|
}
|
2012-08-06 07:15:07 +00:00
|
|
|
|
|
|
|
doc_MultiLookupHelperThree="Lookup phone number three nodes reply"
|
|
|
|
setup_MultiLookupHelperThree() {
|
|
|
|
setup_multi_helper
|
|
|
|
}
|
|
|
|
test_MultiLookupHelperThree() {
|
|
|
|
executeOk_servald dna lookup 00003
|
2012-08-02 07:48:04 +00:00
|
|
|
assertStdoutLineCount '==' 3
|
2012-08-06 07:15:07 +00:00
|
|
|
assertStdoutGrep --matches=1 "uri:A1:00003:Name One$"
|
|
|
|
assertStdoutGrep --matches=1 "uri:B1:00003:Name Three$"
|
|
|
|
assertStdoutGrep --matches=1 "uri:C1:00003:Name Six$"
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_MultiLookupHelperTwo="Lookup phone number two nodes reply"
|
|
|
|
setup_MultiLookupHelperTwo() {
|
|
|
|
setup_multi_helper
|
|
|
|
}
|
|
|
|
test_MultiLookupHelperTwo() {
|
2012-08-02 07:48:04 +00:00
|
|
|
executeOk_servald dna lookup 00002
|
|
|
|
assertStdoutLineCount '==' 2
|
2012-10-05 08:15:30 +00:00
|
|
|
assertStdoutGrep --matches=1 "uri:A2:00002:Name Two\$"
|
|
|
|
assertStdoutGrep --matches=1 "uri:B2:00002:Name Four\$"
|
2012-08-06 07:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_MultiLookupHelperOne="Lookup phone number one node replies"
|
|
|
|
setup_MultiLookupHelperOne() {
|
|
|
|
setup_multi_helper
|
|
|
|
}
|
|
|
|
test_MultiLookupHelperOne() {
|
|
|
|
executeOk_servald dna lookup 00001
|
2012-08-02 07:48:04 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
2012-10-05 08:15:30 +00:00
|
|
|
assertStdoutGrep --matches=1 "uri:B3:00001:Name Five\$"
|
2012-08-02 07:48:04 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 03:58:21 +00:00
|
|
|
runTests "$@"
|