2012-07-06 05:09:25 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Tests for Serval rhizome protocol.
|
|
|
|
#
|
|
|
|
# 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"
|
|
|
|
source "${0%/*}/../testdefs_rhizome.sh"
|
|
|
|
|
|
|
|
shopt -s extglob
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
stop_all_servald_servers
|
|
|
|
kill_all_servald_processes
|
|
|
|
assert_no_servald_processes
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_rhizome() {
|
2012-09-14 06:39:28 +00:00
|
|
|
foreach_instance +A +B create_single_identity
|
2012-07-06 05:09:25 +00:00
|
|
|
set_instance +B
|
|
|
|
}
|
|
|
|
|
2012-07-11 07:13:21 +00:00
|
|
|
# Called by start_servald_instances for each instance.
|
2012-07-06 05:09:25 +00:00
|
|
|
configure_servald_server() {
|
2012-07-11 07:39:50 +00:00
|
|
|
executeOk_servald config set log.show_pid on
|
|
|
|
executeOk_servald config set log.show_time on
|
2012-07-06 05:09:25 +00:00
|
|
|
executeOk_servald config set debug.rhizome on
|
2012-07-13 01:36:10 +00:00
|
|
|
executeOk_servald config set debug.rhizometx on
|
2012-07-12 07:09:01 +00:00
|
|
|
executeOk_servald config set debug.rhizomerx on
|
2012-07-25 07:31:47 +00:00
|
|
|
executeOk_servald config set server.respawn_on_signal off
|
2012-07-10 10:30:20 +00:00
|
|
|
executeOk_servald config set mdp.wifi.tick_ms 100
|
|
|
|
executeOk_servald config set mdp.selfannounce.ticks_per_full_address 1
|
2012-07-11 07:20:50 +00:00
|
|
|
executeOk_servald config set rhizome.fetch_interval_ms 100
|
2012-07-06 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 08:12:30 +00:00
|
|
|
# Predicate function:
|
2012-08-27 06:59:46 +00:00
|
|
|
# - return true if the file bundle identified by arg1=BID and arg2=VERSION has been
|
2012-07-11 08:12:30 +00:00
|
|
|
# received by all the given instances
|
|
|
|
# - does this by examining the server log files of the respective instances
|
|
|
|
# for tell-tale INFO messages
|
|
|
|
bundle_received_by() {
|
2012-08-27 06:59:46 +00:00
|
|
|
local BID="$1"
|
|
|
|
local VERSION="$2"
|
|
|
|
shift 2
|
2012-07-11 08:12:30 +00:00
|
|
|
local I
|
|
|
|
for I; do
|
2012-08-27 06:59:46 +00:00
|
|
|
case "$I" in
|
|
|
|
+*)
|
|
|
|
logvar="LOG${I#+}"
|
|
|
|
grep "RHIZOME ADD MANIFEST service=file bid=$BID version=$VERSION" "${!logvar}" || return 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
error "invalid instance argument: $I"
|
|
|
|
;;
|
|
|
|
esac
|
2012-07-11 08:12:30 +00:00
|
|
|
done
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2012-09-27 08:06:22 +00:00
|
|
|
assert_have_curl_7() {
|
|
|
|
case "$(curl --version | tr '\n' ' ')" in
|
|
|
|
curl\ @(7|8|9|[1-9][0-1]).*\ Protocols:*\ http\ *) ;;
|
|
|
|
'') fail "curl(1) command is not present";;
|
|
|
|
*) fail "curl(1) version is not adequate (expecting 7 or higher)";;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2012-07-17 04:39:35 +00:00
|
|
|
setup_common() {
|
2012-07-06 05:09:25 +00:00
|
|
|
setup_servald
|
|
|
|
setup_rhizome
|
|
|
|
assert_no_servald_processes
|
2012-07-16 08:59:29 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 04:39:35 +00:00
|
|
|
extract_manifest_vars() {
|
|
|
|
local manifest="${1?}"
|
|
|
|
extract_manifest_id BID "$manifest"
|
|
|
|
extract_manifest_version VERSION "$manifest"
|
|
|
|
extract_manifest_filesize FILESIZE "$manifest"
|
|
|
|
FILEHASH=
|
|
|
|
if [ "$FILESIZE" != '0' ]; then
|
|
|
|
extract_manifest_filehash FILEHASH "$manifest"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
add_file() {
|
|
|
|
local name="$1"
|
|
|
|
[ -e "$name" ] || echo 'File $name' >"$name"
|
|
|
|
local sidvar="SID$instance_name"
|
|
|
|
executeOk_servald rhizome add file "${!sidvar}" '' "$name" "$name.manifest"
|
|
|
|
executeOk_servald rhizome list ''
|
|
|
|
assert_rhizome_list "$name"
|
|
|
|
extract_manifest_vars "$name.manifest"
|
|
|
|
}
|
|
|
|
|
|
|
|
update_file() {
|
|
|
|
local orig_name="$1"
|
|
|
|
local new_name="$2"
|
|
|
|
[ -e "$new_name" ] || echo 'File $new_name' >"$new_name"
|
|
|
|
local sidvar="SID$instance_name"
|
|
|
|
[ "$new_name" != "$orig_name" ] && cp "$orig_name.manifest" "$new_name.manifest"
|
2012-09-27 05:44:43 +00:00
|
|
|
$SED -i -e '/^date=/d;/^filehash=/d;/^filesize=/d;/^version=/d;/^name=/d' "$new_name.manifest"
|
2012-07-17 04:39:35 +00:00
|
|
|
executeOk_servald rhizome add file "${!sidvar}" '' "$new_name" "$new_name.manifest"
|
|
|
|
executeOk_servald rhizome list ''
|
|
|
|
assert_rhizome_list "$new_name"
|
|
|
|
extract_manifest_vars "$new_name.manifest"
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_FileTransfer="New bundle and update transfer to one node"
|
|
|
|
setup_FileTransfer() {
|
|
|
|
setup_common
|
|
|
|
set_instance +A
|
|
|
|
add_file file1
|
2012-07-16 08:59:29 +00:00
|
|
|
start_servald_instances +A +B
|
2012-09-14 06:39:28 +00:00
|
|
|
foreach_instance +A assert_peers_are_instances +B
|
|
|
|
foreach_instance +B assert_peers_are_instances +A
|
2012-07-17 04:39:35 +00:00
|
|
|
}
|
|
|
|
test_FileTransfer() {
|
2012-08-27 06:59:46 +00:00
|
|
|
wait_until bundle_received_by $BID $VERSION +B
|
2012-07-17 04:39:35 +00:00
|
|
|
set_instance +B
|
|
|
|
assert_received file1
|
|
|
|
set_instance +A
|
|
|
|
update_file file1 file2
|
2012-07-11 07:13:21 +00:00
|
|
|
set_instance +B
|
2012-08-27 06:59:46 +00:00
|
|
|
wait_until bundle_received_by $BID $VERSION +B
|
2012-07-17 04:39:35 +00:00
|
|
|
assert_received file2
|
2012-07-06 05:09:25 +00:00
|
|
|
}
|
2012-07-17 04:39:35 +00:00
|
|
|
|
|
|
|
doc_FileTransferBig="Big new bundle transfers to one node"
|
|
|
|
setup_FileTransferBig() {
|
|
|
|
setup_common
|
|
|
|
set_instance +A
|
|
|
|
dd if=/dev/urandom of=file1 bs=1k count=1k 2>&1
|
|
|
|
echo x >>file1
|
|
|
|
ls -l file1
|
|
|
|
add_file file1
|
|
|
|
start_servald_instances +A +B
|
2012-09-14 06:39:28 +00:00
|
|
|
foreach_instance +A assert_peers_are_instances +B
|
|
|
|
foreach_instance +B assert_peers_are_instances +A
|
2012-07-17 04:39:35 +00:00
|
|
|
}
|
|
|
|
test_FileTransferBig() {
|
2012-08-27 06:59:46 +00:00
|
|
|
wait_until bundle_received_by $BID $VERSION +B
|
2012-07-17 04:39:35 +00:00
|
|
|
set_instance +B
|
|
|
|
assert_received file1
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_received() {
|
|
|
|
local name="${1?}"
|
2012-07-06 05:09:25 +00:00
|
|
|
executeOk_servald rhizome list ''
|
2012-07-17 04:39:35 +00:00
|
|
|
assert_rhizome_list "$name!"
|
|
|
|
local _hash
|
|
|
|
if [ -s "$name" ]; then
|
|
|
|
extract_manifest_filehash _hash "$name.manifest"
|
|
|
|
executeOk_servald rhizome extract file "$_hash" extracted
|
|
|
|
assert cmp "$name" extracted
|
|
|
|
fi
|
2012-07-06 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 04:39:35 +00:00
|
|
|
doc_FileTransferMulti="New bundle transfers to four nodes"
|
|
|
|
setup_FileTransferMulti() {
|
|
|
|
setup_common
|
|
|
|
set_instance +A
|
|
|
|
add_file file1
|
2012-07-11 08:12:30 +00:00
|
|
|
start_servald_instances +A +B +C +D +E
|
2012-09-14 06:39:28 +00:00
|
|
|
foreach_instance +A assert_peers_are_instances +B +C +D +E
|
|
|
|
foreach_instance +B assert_peers_are_instances +A +C +D +E
|
|
|
|
foreach_instance +C assert_peers_are_instances +A +B +D +E
|
|
|
|
foreach_instance +D assert_peers_are_instances +A +B +C +E
|
2012-07-11 08:12:30 +00:00
|
|
|
}
|
2012-07-17 04:39:35 +00:00
|
|
|
test_FileTransferMulti() {
|
2012-08-27 06:59:46 +00:00
|
|
|
wait_until bundle_received_by $BID $VERSION +B +C +D +E
|
2012-07-11 08:12:30 +00:00
|
|
|
local I
|
|
|
|
for I in +B +C +D +E; do
|
|
|
|
set_instance $I
|
2012-07-17 04:39:35 +00:00
|
|
|
assert_received file1
|
2012-07-11 08:12:30 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2012-07-17 04:39:35 +00:00
|
|
|
doc_FileTransferDelete="Payload deletion transfers to one node"
|
2012-07-16 08:59:29 +00:00
|
|
|
setup_FileTransferDelete() {
|
2012-07-17 04:39:35 +00:00
|
|
|
setup_common
|
|
|
|
set_instance +A
|
|
|
|
add_file file1
|
2012-07-16 08:59:29 +00:00
|
|
|
start_servald_instances +A +B
|
2012-09-14 06:39:28 +00:00
|
|
|
foreach_instance +A assert_peers_are_instances +B
|
|
|
|
foreach_instance +B assert_peers_are_instances +A
|
2012-08-27 06:59:46 +00:00
|
|
|
wait_until bundle_received_by $BID $VERSION +B
|
2012-07-16 08:59:29 +00:00
|
|
|
set_instance +A
|
|
|
|
>file1_2
|
2012-07-17 04:39:35 +00:00
|
|
|
update_file file1 file1_2
|
2012-07-16 08:59:29 +00:00
|
|
|
}
|
|
|
|
test_FileTransferDelete() {
|
2012-08-27 06:59:46 +00:00
|
|
|
wait_until bundle_received_by $BID $VERSION +B
|
2012-07-16 08:59:29 +00:00
|
|
|
set_instance +B
|
2012-07-17 04:39:35 +00:00
|
|
|
assert_received file1_2
|
2012-07-16 08:59:29 +00:00
|
|
|
}
|
|
|
|
|
2012-08-27 06:59:46 +00:00
|
|
|
setup_sync() {
|
|
|
|
set_instance +A
|
|
|
|
add_file file1
|
|
|
|
BID1=$BID
|
|
|
|
VERSION1=$VERSION
|
|
|
|
start_servald_instances dummy1 +A
|
|
|
|
wait_until rhizome_http_server_started +A
|
|
|
|
get_rhizome_server_port PORTA +A
|
|
|
|
set_instance +B
|
|
|
|
add_file file2
|
|
|
|
BID2=$BID
|
|
|
|
VERSION2=$VERSION
|
|
|
|
executeOk_servald config set rhizome.direct.address "$addr_localhost"
|
|
|
|
executeOk_servald config set rhizome.direct.port "$PORTA"
|
|
|
|
start_servald_instances dummy2 +B
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_Push="One way push bundle to unconnected node"
|
|
|
|
setup_Push() {
|
|
|
|
setup_common
|
|
|
|
setup_sync
|
|
|
|
}
|
|
|
|
test_Push() {
|
|
|
|
executeOk_servald rhizome push
|
|
|
|
assert bundle_received_by $BID1 $VERSION1 +B
|
|
|
|
assert ! bundle_received_by $BID2 $VERSION2 +A
|
|
|
|
set_instance +B
|
|
|
|
assert_received file1
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_Pull="One way pull bundle from unconnected node"
|
|
|
|
setup_Pull() {
|
|
|
|
setup_common
|
|
|
|
setup_sync
|
|
|
|
}
|
|
|
|
test_Pull() {
|
|
|
|
executeOk_servald rhizome pull
|
|
|
|
assert bundle_received_by $BID2 $VERSION2 +A
|
|
|
|
assert ! bundle_received_by $BID1 $VERSION1 +B
|
|
|
|
set_instance +A
|
|
|
|
assert_received file2
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_Sync="Two-way sync bundles between unconnected nodes"
|
|
|
|
setup_Sync() {
|
|
|
|
setup_common
|
|
|
|
setup_sync
|
|
|
|
}
|
|
|
|
test_Sync() {
|
|
|
|
executeOk_servald rhizome sync
|
|
|
|
assert bundle_received_by $BID2 $VERSION2 +A
|
|
|
|
assert bundle_received_by $BID1 $VERSION1 +B
|
|
|
|
set_instance +A
|
|
|
|
assert_received file2
|
|
|
|
set_instance +B
|
|
|
|
assert_received file1
|
|
|
|
}
|
|
|
|
|
2012-09-06 06:59:39 +00:00
|
|
|
doc_HttpImport="Import bundle using HTTP POST multi-part form."
|
|
|
|
setup_HttpImport() {
|
2012-09-27 08:06:22 +00:00
|
|
|
assert_have_curl_7
|
|
|
|
cat >README.WHYNOTSIPS <<'EOF'
|
2012-09-06 06:59:39 +00:00
|
|
|
When we were looking at implementing secure calls for OpenBTS it was suggested
|
|
|
|
that we configure Asterisk to use SIPS/ZRTP. This would have been relatively
|
|
|
|
easy to setup, however there are a few problems.
|
|
|
|
|
|
|
|
Number one is that when Asterisk checks the certificates it will either
|
|
|
|
validate the certificate (checking the chain of trust and so on) and then
|
|
|
|
check that the common name attribute on the certificate matches the hostname
|
|
|
|
of the peer, or it will do none of these checks. This code is in main/tcptls.c
|
|
|
|
line 206 (in version 1.8.14.1).
|
|
|
|
|
|
|
|
This is undesirable in a setup where there is limited or no infrastructure as
|
|
|
|
there is not likely to be a DNS server setup, or even rigid IP assignments
|
|
|
|
that would allow a static hosts file based setup. This situation would force
|
|
|
|
the administrator to disable the checks completely which would allow a trivial
|
|
|
|
man in the middle attack.
|
|
|
|
|
|
|
|
It would be possible to modify Asterisk to have a third way where it validates
|
|
|
|
the certificate and checks the chain of trust but does not look at the common
|
|
|
|
name. We decided against this approach as the VOMP channel driver was written
|
|
|
|
in time to avoid it.
|
|
|
|
EOF
|
2012-09-27 08:06:22 +00:00
|
|
|
setup_common
|
|
|
|
set_instance +B
|
|
|
|
create_identity
|
|
|
|
executeOk_servald rhizome add file $SIDB '' README.WHYNOTSIPS README.WHYNOTSIPS.manifest
|
|
|
|
assert_manifest_complete README.WHYNOTSIPS.manifest
|
|
|
|
assert_stdout_add_file README.WHYNOTSIPS
|
|
|
|
set_instance +A
|
|
|
|
start_servald_instances +A
|
|
|
|
wait_until rhizome_http_server_started +A
|
|
|
|
get_rhizome_server_port PORTA +A
|
|
|
|
}
|
|
|
|
test_HttpImport() {
|
|
|
|
executeOk curl --silent --form 'data=@README.WHYNOTSIPS' --form 'manifest=@README.WHYNOTSIPS.manifest' "$addr_localhost:$PORTA" --output http.output
|
2012-09-06 06:59:39 +00:00
|
|
|
executeOk_servald rhizome list ''
|
2012-09-27 08:06:22 +00:00
|
|
|
assert_rhizome_list README.WHYNOTSIPS
|
2012-09-06 06:59:39 +00:00
|
|
|
}
|
|
|
|
|
2012-08-27 08:27:41 +00:00
|
|
|
doc_HttpAddLocal="Add file locally using HTTP, returns manifest"
|
|
|
|
setup_HttpAddLocal() {
|
2012-09-27 08:06:22 +00:00
|
|
|
assert_have_curl_7
|
2012-08-27 08:27:41 +00:00
|
|
|
setup_common
|
|
|
|
start_servald_instances +A
|
|
|
|
wait_until rhizome_http_server_started +A
|
|
|
|
get_rhizome_server_port PORTA +A
|
|
|
|
}
|
|
|
|
test_HttpAddLocal() {
|
|
|
|
echo 'File file1' >file1
|
2012-09-06 06:59:39 +00:00
|
|
|
executeOk curl --silent --form 'data=@file1' "$addr_localhost:$PORTA" --output file1.manifest
|
2012-08-27 08:27:41 +00:00
|
|
|
assert_manifest_complete file1.manifest
|
|
|
|
executeOk_servald rhizome list ''
|
|
|
|
assert_rhizome_list file1
|
|
|
|
extract_manifest_name name file1.manifest
|
|
|
|
assert [ "$name" = file1 ]
|
|
|
|
}
|
|
|
|
|
2012-07-06 05:09:25 +00:00
|
|
|
runTests "$@"
|