mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-20 17:33:08 +00:00
Added more "Serval-Rhizome-Bundle-xxx" headers to /restful/rhizome/ responses, so that a more complete manifest can be constructed from them
188 lines
5.6 KiB
Bash
Executable File
188 lines
5.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Tests for Rhizome Java API.
|
|
#
|
|
# Copyright 2014 Serval Project Inc.
|
|
#
|
|
# 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_java.sh"
|
|
source "${0%/*}/../testdefs_rhizome.sh"
|
|
|
|
setup() {
|
|
setup_servald
|
|
setup_servald_so
|
|
compile_java_classes
|
|
set_instance +A
|
|
executeOk_servald config \
|
|
set log.console.level debug \
|
|
set debug.httpd on
|
|
create_identities 4
|
|
start_servald_server
|
|
}
|
|
|
|
teardown() {
|
|
stop_all_servald_servers
|
|
kill_all_servald_processes
|
|
assert_no_servald_processes
|
|
report_all_servald_servers
|
|
}
|
|
|
|
# Utility function:
|
|
#
|
|
# unset_vars_with_prefix PREFIX
|
|
#
|
|
# Unsets all shell variables whose names starting with the given PREFIX
|
|
unset_vars_with_prefix() {
|
|
local __prefix="${1?}"
|
|
local __varname
|
|
for __varname in $(declare -p | sed -n -e "s/^declare -[^ ]* \($__prefix[A-Za-z0-9_]\+\)=.*/\1/p"); do
|
|
unset $__varname
|
|
done
|
|
}
|
|
|
|
# Utility function:
|
|
#
|
|
# unpack_vars PREFIX TEXT
|
|
#
|
|
# parses the given TEXT which must have the form:
|
|
#
|
|
# ident1=..., ident2=...., ... identN=...
|
|
#
|
|
# into shell variables:
|
|
#
|
|
# PREFIXident1=...
|
|
# PREFIXident2=...
|
|
# ...
|
|
# PREFIXidentN=...
|
|
#
|
|
# Sets the UNPACKED_VAR_NAMES[] array variable to a list of the names of the
|
|
# variables that were set (names include the PREFIX).
|
|
#
|
|
# Warning: overwrites existing shell variables. Names of overwritten shell
|
|
# variables are derived directly from the output of the command, so cannot be
|
|
# controlled. PREFIX should be used to ensure that special variables cannot
|
|
# be clobbered by accident.
|
|
unpack_vars() {
|
|
local __prefix="${1?}"
|
|
local __text="${2?}"
|
|
local __oo
|
|
tfw_shopt __oo -s extglob
|
|
UNPACKED_VAR_NAMES=()
|
|
while [ -n "$__text" ]; do
|
|
case "$__text" in
|
|
[A-Za-z_.]+([A-Za-z_.0-9])=*)
|
|
local __ident="${__text%%=*}"
|
|
__ident="${__ident//./__}"
|
|
__text="${__text#*=}"
|
|
local __value="${__text%%, [A-Za-z_.]+([A-Za-z_.0-9])=*}"
|
|
__text="${__text:${#__value}}"
|
|
__text="${__text#, }"
|
|
UNPACKED_VAR_NAMES+=("$__ident")
|
|
eval ${__prefix}${__ident}=\"\$__value\"
|
|
;;
|
|
*)
|
|
fail "cannot unpack variable from '$__text'"
|
|
;;
|
|
esac
|
|
done
|
|
tfw_shopt_restore __oo
|
|
}
|
|
|
|
doc_RhizomeList="Java API Rhizome list 100 bundles"
|
|
setup_RhizomeList() {
|
|
setup
|
|
NBUNDLES=100
|
|
rhizome_add_bundles $SIDA1 0 $((NBUNDLES-1))
|
|
assert [ "$ROWID_MAX" -ge "$NBUNDLES" ]
|
|
}
|
|
test_RhizomeList() {
|
|
executeJavaOk org.servalproject.test.Rhizome rhizome-list
|
|
tfw_cat --stdout --stderr
|
|
assertStdoutLineCount == $NBUNDLES
|
|
let lnum=NBUNDLES
|
|
for ((n = 0; n != NBUNDLES; ++n)); do
|
|
line="$(sed -n -e ${lnum}p "$TFWSTDOUT")"
|
|
unset_vars_with_prefix XX_
|
|
unpack_vars XX_ "$line"
|
|
if [ "${ROWID[$n]}" -eq "$ROWID_MAX" ]; then
|
|
# The first row must contain a non-null token string.
|
|
assert [ -n "$XX__token" ]
|
|
assert [ "$lnum" -eq 1 ]
|
|
fi
|
|
assert [ "$XX_id" = "${BID[$n]}" ]
|
|
assert [ "$XX_version" = "${VERSION[$n]}" ]
|
|
assert [ "$XX_filesize" = "${SIZE[$n]}" ]
|
|
assert [ "$XX_filehash" = "${HASH[$n]}" ]
|
|
assert [ "$XX_date" = "${DATE[$n]}" ]
|
|
assert [ "$XX_service" = "file" ]
|
|
assert [ "$XX_name" = "file$n" ]
|
|
assert [ "$XX__rowId" = "${ROWID[$n]}" ]
|
|
assert [ "$XX__fromHere" = "1" ]
|
|
assert [ "$XX__author" = "$SIDA1" ]
|
|
assert [ "$XX__insertTime" = "${INSERTTIME[$n]}" ]
|
|
let --lnum
|
|
done
|
|
}
|
|
|
|
assert_metadata() {
|
|
local n=$1
|
|
assertStdoutGrep --matches=1 "^id=${BID[$n]}$CR\$"
|
|
assertStdoutGrep --matches=1 "^version=${VERSION[$n]}$CR\$"
|
|
assertStdoutGrep --matches=1 "^filesize=${SIZE[$n]}$CR\$"
|
|
assertStdoutGrep --matches=1 "^filehash=${HASH[$n]}$CR\$"
|
|
assertStdoutGrep --matches=1 "^BK=${BK[$n]}$CR\$"
|
|
assertStdoutGrep --matches=1 "^date=${DATE[$n]}$CR\$"
|
|
assertStdoutGrep --matches=1 "^name=${NAME[$n]}$CR\$"
|
|
assertStdoutGrep --matches=1 "^service=file$CR\$"
|
|
assertStdoutGrep --matches=1 "^_insertTime=${INSERTTIME[$n]}$CR\$"
|
|
assertStdoutGrep --matches=1 "^_author=${AUTHOR[$n]}$CR\$"
|
|
assertStdoutGrep --matches=1 "^_secret=${SECRET[$n]}$CR\$"
|
|
}
|
|
|
|
doc_RhizomeManifest="Java API fetch Rhizome manifest"
|
|
setup_RhizomeManifest() {
|
|
setup
|
|
rhizome_add_bundles $SIDA1 0 2
|
|
}
|
|
test_RhizomeManifest() {
|
|
for n in 0 1 2; do
|
|
executeJavaOk org.servalproject.test.Rhizome rhizome-manifest "${BID[$n]}" bundle$n.rhm
|
|
tfw_cat --stdout --stderr
|
|
assert_metadata $n
|
|
tfw_cat -v file$n.manifest -v bundle$n.rhm
|
|
assert diff file$n.manifest bundle$n.rhm
|
|
done
|
|
}
|
|
|
|
doc_RhizomePayloadRaw="Java API fetch Rhizome raw payload"
|
|
setup_RhizomePayloadRaw() {
|
|
setup
|
|
rhizome_add_bundles $SIDA1 0 1
|
|
rhizome_add_bundles --encrypted $SIDA1 2 3
|
|
}
|
|
test_RhizomePayloadRaw() {
|
|
for n in 0 1 2 3; do
|
|
executeJavaOk org.servalproject.test.Rhizome rhizome-payload-raw "${BID[$n]}" raw.bin$n
|
|
tfw_cat --stdout --stderr
|
|
assert_metadata $n
|
|
assert cmp raw$n raw.bin$n
|
|
done
|
|
}
|
|
|
|
runTests "$@"
|