2016-10-05 00:17:51 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
source "${0%/*}/../testframework.sh"
|
|
|
|
source "${0%/*}/../testdefs.sh"
|
|
|
|
source "${0%/*}/../testdefs_json.sh"
|
|
|
|
|
|
|
|
setup_instance() {
|
|
|
|
set_instance $1
|
|
|
|
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 debug.http_server on \
|
|
|
|
set debug.httpd on \
|
|
|
|
set debug.meshmb on \
|
2016-10-10 03:04:18 +00:00
|
|
|
set debug.meshms on \
|
2016-10-05 00:17:51 +00:00
|
|
|
set debug.verbose on \
|
|
|
|
set log.console.level debug
|
|
|
|
set_extra_config
|
|
|
|
if [ -z "$IDENTITY_COUNT" ]; then
|
|
|
|
create_single_identity
|
|
|
|
else
|
|
|
|
create_identities $IDENTITY_COUNT
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
set_extra_config() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_curl 7
|
|
|
|
setup_json
|
|
|
|
setup_servald
|
|
|
|
export SERVALD_RHIZOME_DB_RETRY_LIMIT_MS=60000
|
|
|
|
setup_instance +A
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-10-10 03:04:18 +00:00
|
|
|
doc_MeshMBRestSend="Restful send of a broadcast message"
|
|
|
|
test_MeshMBRestSend() {
|
2016-10-05 00:17:51 +00:00
|
|
|
executeOk curl \
|
|
|
|
-H "Expect:" \
|
|
|
|
--silent --fail --show-error \
|
|
|
|
--output sendmessage.json \
|
|
|
|
--basic --user harry:potter \
|
|
|
|
--form "message=Hello World;type=text/plain;charset=utf-8" \
|
|
|
|
"http://$addr_localhost:$PORTA/restful/meshmb/$IDA1/sendmessage"
|
|
|
|
executeOk_servald rhizome export bundle $IDA1 broadcast.manifest broadcast
|
|
|
|
tfw_cat -h broadcast.manifest
|
|
|
|
tfw_cat -h broadcast
|
|
|
|
}
|
|
|
|
|
2016-10-10 03:04:18 +00:00
|
|
|
doc_MeshMBRestList="Restful list of meshmb messages"
|
|
|
|
setup_MeshMBRestList() {
|
|
|
|
setup
|
|
|
|
executeOk_servald meshmb send $IDA1 "Message 1"
|
|
|
|
executeOk_servald meshmb send $IDA1 "Message 2"
|
|
|
|
}
|
|
|
|
test_MeshMBRestList() {
|
|
|
|
executeOk curl \
|
|
|
|
-H "Expect:" \
|
|
|
|
--silent --fail --show-error \
|
|
|
|
--output listmessages.json \
|
|
|
|
--dump-header http.headers \
|
|
|
|
--basic --user harry:potter \
|
|
|
|
"http://$addr_localhost:$PORTA/restful/meshmb/$IDA1/messagelist.json"
|
|
|
|
tfw_cat http.headers listmessages.json
|
|
|
|
tfw_preserve listmessages.json
|
|
|
|
assert [ "$(jq '.rows | length' listmessages.json)" = 2 ]
|
|
|
|
transform_list_json listmessages.json list.json
|
|
|
|
tfw_preserve list.json
|
|
|
|
assertJq list.json \
|
|
|
|
"contains([
|
|
|
|
{ offset: 12,
|
|
|
|
text: \"Message 1\"
|
|
|
|
}
|
|
|
|
])"
|
|
|
|
assertJq list.json \
|
|
|
|
"contains([
|
|
|
|
{ offset: 30,
|
|
|
|
text: \"Message 2\"
|
|
|
|
}
|
|
|
|
])"
|
|
|
|
}
|
2016-12-13 01:55:38 +00:00
|
|
|
|
|
|
|
doc_MeshMBRestFollow="Restful follow another feed"
|
|
|
|
setup_MeshMBRestFollow() {
|
|
|
|
IDENTITY_COUNT=3
|
|
|
|
setup
|
|
|
|
executeOk_servald meshmb send $IDA1 "Message 1"
|
|
|
|
executeOk_servald meshmb send $IDA2 "Message 2"
|
|
|
|
executeOk_servald meshmb send $IDA3 "Message 3"
|
|
|
|
}
|
|
|
|
test_MeshMBRestFollow() {
|
|
|
|
executeOk curl \
|
|
|
|
-H "Expect:" \
|
|
|
|
--silent --fail --show-error \
|
|
|
|
--output follow.json \
|
|
|
|
--basic --user harry:potter \
|
|
|
|
--request POST \
|
|
|
|
"http://$addr_localhost:$PORTA/restful/meshmb/$IDA1/follow/$IDA2"
|
|
|
|
executeOk_servald meshmb list following $IDA1
|
2017-02-06 02:23:12 +00:00
|
|
|
assertStdoutGrep --matches=1 ":$IDA2:$SIDA2::[0-9]\+:Message 2\$"
|
|
|
|
assertStdoutGrep --matches=0 ":$IDA3:$SIDA3::[0-9]\+:Message 3\$"
|
2016-12-13 01:55:38 +00:00
|
|
|
executeOk curl \
|
|
|
|
-H "Expect:" \
|
|
|
|
--silent --fail --show-error \
|
|
|
|
--output follow.json \
|
|
|
|
--basic --user harry:potter \
|
|
|
|
--request POST \
|
|
|
|
"http://$addr_localhost:$PORTA/restful/meshmb/$IDA1/follow/$IDA3"
|
|
|
|
executeOk_servald meshmb list following $IDA1
|
2017-02-06 02:23:12 +00:00
|
|
|
assertStdoutGrep --matches=1 ":$IDA2:$SIDA2::[0-9]\+:Message 2\$"
|
|
|
|
assertStdoutGrep --matches=1 ":$IDA3:$SIDA3::[0-9]\+:Message 3\$"
|
2016-12-13 01:55:38 +00:00
|
|
|
executeOk curl \
|
|
|
|
-H "Expect:" \
|
|
|
|
--silent --fail --show-error \
|
|
|
|
--output follow.json \
|
|
|
|
--basic --user harry:potter \
|
|
|
|
--request POST \
|
|
|
|
"http://$addr_localhost:$PORTA/restful/meshmb/$IDA1/ignore/$IDA2"
|
|
|
|
executeOk_servald meshmb list following $IDA1
|
2017-02-06 02:23:12 +00:00
|
|
|
assertStdoutGrep --matches=0 ":$IDA2:$SIDA2::[0-9]\+:Message 2\$"
|
|
|
|
assertStdoutGrep --matches=1 ":$IDA3:$SIDA3::[0-9]\+:Message 3\$"
|
2016-12-13 01:55:38 +00:00
|
|
|
}
|
|
|
|
|
2017-01-10 01:14:37 +00:00
|
|
|
doc_MeshMBRestFeeds="Restful list subscribed feeds"
|
|
|
|
setup_MeshMBRestFeeds() {
|
|
|
|
IDENTITY_COUNT=3
|
|
|
|
setup
|
|
|
|
executeOk_servald meshmb send $IDA1 "Message 1"
|
|
|
|
executeOk_servald meshmb send $IDA2 "Message 2"
|
|
|
|
executeOk_servald meshmb send $IDA3 "Message 3"
|
|
|
|
executeOk_servald meshmb follow $IDA1 $IDA2
|
|
|
|
executeOk_servald meshmb follow $IDA1 $IDA3
|
|
|
|
}
|
|
|
|
test_MeshMBRestFeeds() {
|
|
|
|
executeOk curl \
|
|
|
|
-H "Expect:" \
|
|
|
|
--silent --fail --show-error \
|
|
|
|
--output feedlist.json \
|
|
|
|
--dump-header http.headers \
|
|
|
|
--basic --user harry:potter \
|
|
|
|
"http://$addr_localhost:$PORTA/restful/meshmb/$IDA1/feedlist.json"
|
|
|
|
tfw_cat http.headers feedlist.json
|
|
|
|
tfw_preserve feedlist.json
|
|
|
|
assert [ "$(jq '.rows | length' feedlist.json)" = 2 ]
|
|
|
|
transform_list_json feedlist.json list.json
|
|
|
|
tfw_preserve list.json
|
|
|
|
assertJq list.json \
|
|
|
|
"contains([
|
|
|
|
{ id: \"$IDA2\",
|
|
|
|
last_message: \"Message 2\"
|
|
|
|
}
|
|
|
|
])"
|
|
|
|
assertJq list.json \
|
|
|
|
"contains([
|
|
|
|
{ id: \"$IDA3\",
|
|
|
|
last_message: \"Message 3\"
|
|
|
|
}
|
|
|
|
])"
|
|
|
|
}
|
|
|
|
|
2016-10-05 00:17:51 +00:00
|
|
|
runTests "$@"
|
|
|
|
|