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"
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_servald
|
|
|
|
assert_no_servald_processes
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_servald_instance() {
|
2012-06-22 06:26:28 +00:00
|
|
|
push_instance
|
|
|
|
set_instance "$1"
|
2012-06-28 08:50:38 +00:00
|
|
|
executeOk_servald config set debug.interfaces Yes
|
|
|
|
executeOk_servald config set debug.packetformats Yes
|
2012-06-21 05:34:34 +00:00
|
|
|
executeOk_servald config set interfaces "+>$2"
|
2012-07-02 01:30:06 +00:00
|
|
|
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"
|
2012-07-02 02:56:01 +00:00
|
|
|
executeOk_servald config set mdp.wifi.tick_ms 50
|
2012-06-28 08:50:38 +00:00
|
|
|
executeOk_servald config set mdp.selfannounce.ticks_per_full_address 1
|
2012-06-21 03:58:21 +00:00
|
|
|
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" ]
|
2012-06-22 06:26:28 +00:00
|
|
|
executeOk_servald set did $sid 5550001 "Agent $instance_name Smith"
|
|
|
|
start_servald_server
|
2012-06-21 05:05:05 +00:00
|
|
|
executeOk_servald status
|
|
|
|
tfw_cat --stdout
|
2012-06-22 06:26:28 +00:00
|
|
|
pop_instance
|
2012-06-21 05:34:34 +00:00
|
|
|
}
|
2012-06-21 04:28:31 +00:00
|
|
|
|
2012-06-21 05:34:34 +00:00
|
|
|
setup_servald_instances() {
|
2012-06-28 08:50:38 +00:00
|
|
|
DUMMYNET=$PWD/dummy
|
|
|
|
>$DUMMYNET
|
2012-06-22 06:26:28 +00:00
|
|
|
setup_servald_instance +A $DUMMYNET
|
2012-06-21 06:34:14 +00:00
|
|
|
SIDA=$sid
|
2012-06-22 06:26:28 +00:00
|
|
|
setup_servald_instance +B $DUMMYNET
|
2012-06-21 06:34:14 +00:00
|
|
|
SIDB=$sid
|
2012-06-21 05:34:34 +00:00
|
|
|
# Now make sure that they can see each other
|
2012-07-02 02:56:01 +00:00
|
|
|
secs=1
|
2012-06-28 08:50:38 +00:00
|
|
|
sleep $secs # Should be plenty of time
|
2012-07-02 02:56:58 +00:00
|
|
|
tfw_log "# Dummynet file after $secs seconds: "`ls -l $DUMMYNET`
|
2012-06-22 06:26:28 +00:00
|
|
|
set_instance +A
|
2012-06-21 05:34:34 +00:00
|
|
|
executeOk_servald id peers
|
2012-06-21 06:28:39 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
2012-06-21 05:34:34 +00:00
|
|
|
}
|
|
|
|
|
2012-06-22 03:49:28 +00:00
|
|
|
doc_MultipleServalDTest="Start two servald instances with dummy interface"
|
2012-06-21 05:34:34 +00:00
|
|
|
|
|
|
|
setup_MultipleServalDTest() {
|
|
|
|
setup
|
|
|
|
}
|
|
|
|
|
|
|
|
test_MultipleServalDTest() {
|
|
|
|
setup_servald_instances
|
2012-06-21 03:58:21 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 06:28:39 +00:00
|
|
|
doc_DNAWildcardSearchFindsSelf="DNA lookup of wildcard finds (star method)"
|
2012-06-21 04:06:27 +00:00
|
|
|
setup_DNAWildcardSearchFindsSelf() {
|
2012-06-21 03:58:21 +00:00
|
|
|
setup
|
2012-06-21 05:34:34 +00:00
|
|
|
setup_servald_instances
|
2012-06-22 06:26:28 +00:00
|
|
|
set_instance +A
|
2012-06-22 03:49:28 +00:00
|
|
|
}
|
|
|
|
test_DNAWildcardSearchFindsSelf() {
|
2012-06-21 04:13:28 +00:00
|
|
|
executeOk_servald dna lookup "*"
|
2012-06-21 06:28:39 +00:00
|
|
|
assertStdoutLineCount '==' 2
|
2012-06-21 06:34:14 +00:00
|
|
|
assertStdoutGrep --matches=1 "^sid://$SIDA/5550001:5550001:Agent A Smith$"
|
|
|
|
assertStdoutGrep --matches=1 "^sid://$SIDB/5550001:5550001:Agent B Smith$"
|
2012-06-21 03:58:21 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 06:28:39 +00:00
|
|
|
doc_DNAWildcardSearchFindsSelfEmpty="DNA lookup of wildcard (empty query method)"
|
2012-06-21 04:13:28 +00:00
|
|
|
setup_DNAWildcardSearchFindsSelfEmpty() {
|
|
|
|
setup
|
2012-06-21 05:34:34 +00:00
|
|
|
setup_servald_instances
|
2012-06-22 06:26:28 +00:00
|
|
|
set_instance +A
|
2012-06-22 03:49:28 +00:00
|
|
|
}
|
|
|
|
test_DNAWildcardSearchFindsSelfEmpty() {
|
2012-06-21 04:13:28 +00:00
|
|
|
executeOk_servald dna lookup ""
|
2012-06-21 06:28:39 +00:00
|
|
|
assertStdoutLineCount '==' 2
|
2012-06-21 06:34:14 +00:00
|
|
|
assertStdoutGrep --matches=1 "^sid://$SIDA/5550001:5550001:Agent A Smith$"
|
|
|
|
assertStdoutGrep --matches=1 "^sid://$SIDB/5550001:5550001:Agent B Smith$"
|
2012-06-21 04:13:28 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 06:38:39 +00:00
|
|
|
doc_DNASpecificLookup="DNA Lookup by phone number"
|
|
|
|
setup_DNASpecificLookup() {
|
|
|
|
setup
|
|
|
|
setup_servald_instances
|
2012-06-22 06:26:28 +00:00
|
|
|
set_instance +A
|
2012-06-22 03:49:28 +00:00
|
|
|
}
|
|
|
|
test_DNASpecificLookup() {
|
2012-06-21 06:38:39 +00:00
|
|
|
# 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$"
|
|
|
|
}
|
2012-06-21 04:13:28 +00:00
|
|
|
|
2012-06-21 06:51:16 +00:00
|
|
|
doc_DNANodeInfoLocalResolution="'node info' auto-resolves for local identities"
|
|
|
|
setup_DNANodeInfoLocalResolution() {
|
|
|
|
setup
|
|
|
|
setup_servald_instances
|
2012-06-22 06:26:28 +00:00
|
|
|
set_instance +A
|
2012-06-22 03:49:28 +00:00
|
|
|
}
|
|
|
|
test_DNANodeInfoLocalResolution() {
|
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
|
|
|
|
assertStdoutGrep --matches=1 "Agent A Smith"
|
|
|
|
assertStdoutGrep --matches=0 "did-not-resolved"
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_DNANodeInfoRemoteResolution="'node info' for remote identities"
|
|
|
|
setup_DNANodeInfoRemoteResolution() {
|
|
|
|
setup
|
|
|
|
setup_servald_instances
|
2012-06-22 06:26:28 +00:00
|
|
|
set_instance +A
|
2012-06-22 03:49:28 +00:00
|
|
|
}
|
|
|
|
test_DNANodeInfoRemoteResolution() {
|
2012-06-21 06:51:16 +00:00
|
|
|
# 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 "$@"
|