2014-07-23 08:01:47 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Tests for Serval DNA HTTP RESTful interface
|
|
|
|
#
|
|
|
|
# Copyright 2013-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_json.sh"
|
|
|
|
|
|
|
|
shopt -s extglob
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_curl 7
|
|
|
|
setup_json
|
|
|
|
setup_servald
|
|
|
|
set_instance +A
|
2015-08-10 08:38:42 +00:00
|
|
|
set_keyring_config
|
2014-07-23 08:01:47 +00:00
|
|
|
executeOk_servald config \
|
|
|
|
set api.restful.users.harry.password potter \
|
|
|
|
set api.restful.users.ron.password weasley \
|
|
|
|
set api.restful.users.hermione.password grainger
|
|
|
|
set_extra_config
|
|
|
|
if [ -z "$IDENTITY_COUNT" ]; then
|
|
|
|
create_single_identity
|
|
|
|
else
|
|
|
|
create_identities $IDENTITY_COUNT
|
|
|
|
fi
|
|
|
|
start_servald_instances +A
|
|
|
|
wait_until servald_restful_http_server_started +A
|
|
|
|
get_servald_restful_http_server_port PORTA +A
|
|
|
|
}
|
|
|
|
|
|
|
|
finally() {
|
|
|
|
stop_all_servald_servers
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
kill_all_servald_processes
|
|
|
|
assert_no_servald_processes
|
|
|
|
report_all_servald_servers
|
|
|
|
}
|
|
|
|
|
|
|
|
set_extra_config() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
|
|
|
set_keyring_config() {
|
|
|
|
executeOk_servald config \
|
|
|
|
set debug.httpd on \
|
|
|
|
set debug.rhizome_manifest on \
|
|
|
|
set debug.rhizome_store on \
|
|
|
|
set debug.rhizome on \
|
|
|
|
set debug.keyring on \
|
|
|
|
set debug.verbose on \
|
|
|
|
set log.console.level debug
|
|
|
|
}
|
|
|
|
|
2015-08-10 08:38:42 +00:00
|
|
|
doc_keyringList="HTTP RESTful list keyring identities as JSON"
|
|
|
|
setup_keyringList() {
|
2014-07-23 08:01:47 +00:00
|
|
|
IDENTITY_COUNT=10
|
|
|
|
setup
|
|
|
|
}
|
2015-08-10 08:38:42 +00:00
|
|
|
test_keyringList() {
|
2014-07-23 08:01:47 +00:00
|
|
|
executeOk curl \
|
|
|
|
--silent --fail --show-error \
|
2015-08-10 08:38:42 +00:00
|
|
|
--output list.json \
|
2014-07-23 08:01:47 +00:00
|
|
|
--dump-header http.headers \
|
|
|
|
--basic --user harry:potter \
|
|
|
|
"http://$addr_localhost:$PORTA/restful/keyring/identities.json"
|
2015-08-10 08:38:42 +00:00
|
|
|
tfw_cat http.headers list.json
|
|
|
|
tfw_preserve list.json
|
|
|
|
assert [ "$(jq '.rows | length' list.json)" = $IDENTITY_COUNT ]
|
|
|
|
assert [ "$(jq -r '.rows[0][0]' list.json)" = $SIDA1 ]
|
|
|
|
assert [ "$(jq -r '.rows[4][0]' list.json)" = $SIDA5 ]
|
|
|
|
assert [ "$(jq -r '.rows[9][0]' list.json)" = $SIDA10 ]
|
|
|
|
}
|
2014-07-23 08:01:47 +00:00
|
|
|
|
2015-08-10 08:38:42 +00:00
|
|
|
doc_keyringAdd="HTTP RESTful add keyring identity with empty PIN"
|
|
|
|
setup_keyringAdd() {
|
|
|
|
IDENTITY_COUNT=2
|
|
|
|
setup
|
|
|
|
}
|
|
|
|
test_keyringAdd() {
|
|
|
|
executeOk curl \
|
|
|
|
--silent --show-error --write-out '%{http_code}' \
|
|
|
|
--output add.json \
|
|
|
|
--dump-header http.headers \
|
|
|
|
--basic --user harry:potter \
|
|
|
|
"http://$addr_localhost:$PORTA/restful/keyring/add"
|
|
|
|
tfw_cat http.headers add.json
|
|
|
|
tfw_preserve add.json
|
|
|
|
assertStdoutIs '200'
|
|
|
|
SID="$(jq -r '.sid' add.json)"
|
|
|
|
assert matches_rexp "^${rexp_sid}$" "$SID"
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 3
|
|
|
|
assertStdoutGrep --stderr --matches=1 "^$SID::\$"
|
2014-07-23 08:01:47 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 08:12:26 +00:00
|
|
|
doc_keyringAddPin="HTTP RESTful add keyring identity with non-empty PIN"
|
|
|
|
setup_keyringAddPin() {
|
|
|
|
IDENTITY_COUNT=2
|
|
|
|
setup
|
|
|
|
}
|
|
|
|
test_keyringAddPin() {
|
|
|
|
executeOk curl \
|
|
|
|
--silent --fail --show-error \
|
|
|
|
--output add.json \
|
|
|
|
--dump-header http.headers \
|
|
|
|
--basic --user harry:potter \
|
|
|
|
"http://$addr_localhost:$PORTA/restful/keyring/add?pin=1234"
|
|
|
|
tfw_cat http.headers add.json
|
|
|
|
tfw_preserve add.json
|
|
|
|
SID="$(jq -r '.sid' add.json)"
|
|
|
|
executeOk_servald keyring list
|
|
|
|
assert_keyring_list 2
|
|
|
|
assertStdoutGrep --stderr --matches=0 "^$SID::\$"
|
|
|
|
executeOk_servald keyring list --entry-pin=1234
|
|
|
|
assert_keyring_list 3
|
|
|
|
assertStdoutGrep --stderr --matches=1 "^$SID::\$"
|
|
|
|
}
|
|
|
|
|
2014-07-23 08:01:47 +00:00
|
|
|
runTests "$@"
|