mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-25 07:41:10 +00:00
dce8b378d2
Add some servald config set-up functions to 'testdefs_routing.sh' and 'testdefs_swift.sh' that can be re-used in the Swift Routing API tests. Improve some commenting on existing functions, for consistency.
162 lines
4.9 KiB
Bash
Executable File
162 lines
4.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Tests for Keyring Java API.
|
|
#
|
|
# Copyright 2015 Serval Project Inc.
|
|
# Copyright 2018 Flinders Univerity
|
|
#
|
|
# 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"
|
|
|
|
setup() {
|
|
setup_servald
|
|
setup_servald_so
|
|
assert_java_classes_exist
|
|
set_instance +A
|
|
setup_keyring_config
|
|
set_extra_config
|
|
if [ -z "$IDENTITY_COUNT" ]; then
|
|
create_single_identity
|
|
else
|
|
create_identities $IDENTITY_COUNT
|
|
fi
|
|
export SERVALD_RHIZOME_DB_RETRY_LIMIT_MS=60000
|
|
start_servald_server
|
|
wait_until servald_restful_http_server_started +A
|
|
get_servald_restful_http_server_port PORTA +A
|
|
}
|
|
|
|
teardown() {
|
|
stop_all_servald_servers
|
|
kill_all_servald_processes
|
|
assert_no_servald_processes
|
|
report_all_servald_servers
|
|
}
|
|
|
|
setup_keyring_config() {
|
|
executeOk_servald config \
|
|
set log.console.level debug \
|
|
set debug.httpd on \
|
|
set debug.keyring on \
|
|
set debug.verbose on
|
|
}
|
|
|
|
set_extra_config() {
|
|
:
|
|
}
|
|
|
|
doc_keyringList="Java API list keyring identities"
|
|
setup_keyringList() {
|
|
IDENTITY_COUNT=10
|
|
DIDA1=123123123
|
|
NAMEA1='Joe Bloggs'
|
|
DIDA5=567567567
|
|
setup
|
|
}
|
|
test_keyringList() {
|
|
executeJavaOk org.servalproject.test.Keyring list-identities
|
|
tfw_cat --stdout --stderr
|
|
assertStdoutLineCount == $IDENTITY_COUNT
|
|
for ((n = 1; n != IDENTITY_COUNT + 1; ++n)); do
|
|
local sidvar=SIDA$n
|
|
local didvar=DIDA$n
|
|
local namevar=NAMEA$n
|
|
assertStdoutGrep --matches=1 "^sid=${!sidvar}, did=${!didvar-null}, name=${!namevar-null}$"
|
|
done
|
|
}
|
|
|
|
doc_keyringListPin="Java API list keyring identities, with PIN"
|
|
setup_keyringListPin() {
|
|
IDENTITY_COUNT=3
|
|
PINA1='wif waf'
|
|
setup
|
|
}
|
|
test_keyringListPin() {
|
|
# First, list without supplying the PIN
|
|
executeJavaOk org.servalproject.test.Keyring list-identities
|
|
tfw_cat --stdout --stderr
|
|
assertStdoutLineCount == $((IDENTITY_COUNT - 1))
|
|
assertStdoutGrep --matches=0 "sid=$SIDA1"
|
|
assertStdoutGrep --matches=1 "sid=$SIDA2"
|
|
assertStdoutGrep --matches=1 "sid=$SIDA3"
|
|
# Then, list supplying the PIN
|
|
executeJavaOk org.servalproject.test.Keyring list-identities "$PINA1"
|
|
tfw_cat --stdout --stderr
|
|
assertStdoutLineCount == $IDENTITY_COUNT
|
|
assertStdoutGrep --matches=1 "sid=$SIDA1"
|
|
assertStdoutGrep --matches=1 "sid=$SIDA2"
|
|
assertStdoutGrep --matches=1 "sid=$SIDA3"
|
|
}
|
|
|
|
doc_keyringGet="Java API query single keyring identity"
|
|
test_keyringGet() {
|
|
executeJavaOk org.servalproject.test.Keyring get "$SIDA1"
|
|
tfw_cat --stdout --stderr
|
|
assertStdoutLineCount == 1
|
|
assertStdoutGrep --matches=1 "^sid=$SIDA1, did=$DIDA1, name=$NAMEA1$"
|
|
}
|
|
|
|
doc_keyringAddDidName="Java API add new identity"
|
|
setup_keyringAddDidName() {
|
|
IDENTITY_COUNT=1
|
|
setup
|
|
}
|
|
test_keyringAddDidName() {
|
|
executeJavaOk org.servalproject.test.Keyring add 987654321 'Joe Bloggs'
|
|
tfw_cat --stdout --stderr
|
|
assertStdoutGrep --matches=1 "sid=${rexp_sid}, did=987654321, name=Joe Bloggs$"
|
|
executeOk_servald keyring list
|
|
assert_keyring_list 2
|
|
assertStdoutGrep --stderr --matches=1 "^${rexp_sid}:${rexp_id}:987654321:Joe Bloggs\$"
|
|
}
|
|
|
|
doc_keyringRemove="Java API remove existing identity"
|
|
setup_keyringRemove() {
|
|
IDENTITY_COUNT=2
|
|
setup
|
|
}
|
|
test_keyringRemove() {
|
|
executeJavaOk org.servalproject.test.Keyring remove "$SIDA1"
|
|
tfw_cat --stdout --stderr
|
|
assertStdoutGrep --matches=1 "sid=$SIDA1, did=${DIDA1:-null}, name=${NAMEA1:-null}$"
|
|
executeOk_servald keyring list
|
|
assert_keyring_list 1
|
|
assertStdoutGrep --stderr --matches=0 "$SIDA1"
|
|
assertStdoutGrep --stderr --matches=1 "^$SIDA2:${rexp_id}:$DIDA2:$NAMEA2\$"
|
|
executeJavaOk org.servalproject.test.Keyring remove "$SIDA2"
|
|
tfw_cat --stdout --stderr
|
|
executeOk_servald keyring list
|
|
assert_keyring_list 0
|
|
}
|
|
|
|
doc_keyringSetDidName="Java API set DID and name"
|
|
setup_keyringSetDidName() {
|
|
IDENTITY_COUNT=2
|
|
setup
|
|
}
|
|
test_keyringSetDidName() {
|
|
executeJavaOk --stdout --stderr org.servalproject.test.Keyring set "$SIDA1" 987654321 'Joe Bloggs'
|
|
tfw_cat --stdout --stderr
|
|
assertStdoutGrep --matches=1 "sid=$SIDA1, did=987654321, name=Joe Bloggs$"
|
|
executeOk_servald keyring list
|
|
assert_keyring_list 2
|
|
assertStdoutGrep --stderr --matches=1 "^$SIDA1:$IDA1:987654321:Joe Bloggs\$"
|
|
}
|
|
|
|
runTests "$@"
|