mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-24 15:26:43 +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.
125 lines
4.3 KiB
Bash
Executable File
125 lines
4.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Tests for Serval DNA Route REST API
|
|
#
|
|
# Copyright 2018 Flinders University
|
|
#
|
|
# 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_rest.sh"
|
|
source "${0%/*}/../testdefs_routing.sh"
|
|
|
|
setup() {
|
|
setup_rest_utilities
|
|
setup_servald
|
|
assert_no_servald_processes
|
|
setup_rest_config +A
|
|
}
|
|
|
|
configure_servald_server() {
|
|
setup_route_config
|
|
}
|
|
|
|
finally() {
|
|
stop_all_servald_servers
|
|
}
|
|
|
|
teardown() {
|
|
foreach_instance_with_pidfile log_routing_table
|
|
stop_all_servald_servers
|
|
kill_all_servald_processes
|
|
assert_no_servald_processes
|
|
report_all_servald_servers
|
|
}
|
|
|
|
doc_AuthBasicMissing="REST API missing Basic Authentication credentials"
|
|
setup_AuthBasicMissing() {
|
|
setup
|
|
set_instance +A
|
|
start_servald_server
|
|
wait_until_rest_server_ready
|
|
}
|
|
test_AuthBasicMissing() {
|
|
rest_request GET "/restful/route/all.json" 401 --no-auth
|
|
assertGrep response.headers "^WWW-Authenticate: Basic realm=\"Serval RESTful API\"$CR\$"
|
|
assertJq response.json 'contains({"http_status_code": 401})'
|
|
assertJq response.json 'contains({"http_status_message": ""})'
|
|
}
|
|
|
|
doc_AuthBasicWrong="REST API incorrect Basic Authentication credentials"
|
|
setup_AuthBasicWrong() {
|
|
setup
|
|
set_instance +A
|
|
start_servald_server
|
|
wait_until_rest_server_ready
|
|
}
|
|
test_AuthBasicWrong() {
|
|
rest_request GET "/restful/route/all.json" 401 --user=fred:nurks
|
|
assertGrep response.headers "^WWW-Authenticate: Basic realm=\"Serval RESTful API\"$CR\$"
|
|
assertJq response.json 'contains({"http_status_code": 401})'
|
|
assertJq response.json 'contains({"http_status_message": ""})'
|
|
rest_request GET "/restful/route/all.json" 200 --user=ron:weasley
|
|
}
|
|
|
|
doc_RouteListAll="REST API list entire routing table"
|
|
setup_RouteListAll() {
|
|
setup
|
|
DIDA1=565656
|
|
NAMEA1="Neddy Seagoon"
|
|
DIDA2=3020304
|
|
NAMEA2="Spike Milligan"
|
|
foreach_instance +A +B create_identities 2
|
|
foreach_instance +A +B add_servald_interface 1
|
|
foreach_instance +A +B start_servald_server
|
|
wait_until_rest_server_ready +A
|
|
get_servald_primary_sid +B PRIMARY_SIDB
|
|
wait_until --timeout=20 path_exists +A +B
|
|
wait_until --timeout=10 path_exists +B +A
|
|
set_instance +A
|
|
}
|
|
test_RouteListAll() {
|
|
rest_request GET "/restful/route/all.json"
|
|
transform_list_json response.json routes.json
|
|
assert [ "$(jq 'length' routes.json)" = 4 ]
|
|
assertJq routes.json 'contains([{"sid": "'"$SIDA1"'",
|
|
"did": "'"$DIDA1"'",
|
|
"name": "'"$NAMEA1"'",
|
|
"is_self": true,
|
|
"hop_count": 0}])'
|
|
assertJq routes.json 'contains([{"sid": "'"$SIDA2"'",
|
|
"did": "'"$DIDA2"'",
|
|
"name": "'"$NAMEA2"'",
|
|
"is_self": true,
|
|
"hop_count": 0}])'
|
|
assertJq routes.json 'contains([{"sid": "'"$PRIMARY_SIDB"'",
|
|
"is_self": false,
|
|
"reachable_unicast": true,
|
|
"reachable_indirect": false,
|
|
"hop_count": 1}])'
|
|
for SID in "${SIDB[@]}"; do
|
|
if [ "$SID" != "$PRIMARY_SIDB" ]; then
|
|
assertJq routes.json 'contains([{"sid": "'"$SID"'",
|
|
"is_self": false,
|
|
"reachable_unicast": false,
|
|
"reachable_indirect": true,
|
|
"hop_count": 2}])'
|
|
fi
|
|
done
|
|
}
|
|
|
|
runTests "$@"
|