[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] 04/75: identity rest api - finished and added test
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] 04/75: identity rest api - finished and added test_script |
Date: |
Thu, 09 Aug 2018 23:58:01 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
commit 4ab30f893f22c75d1aafcc9584cd7eac6c4d82a0
Author: Phil <address@hidden>
AuthorDate: Mon Jun 4 23:50:00 2018 +0200
identity rest api - finished and added test_script
---
src/identity/plugin_rest_identity.c | 34 +++-
src/identity/test_plugin_identity_rest.sh | 252 ++++++++++++++++++++++++++++++
2 files changed, 282 insertions(+), 4 deletions(-)
diff --git a/src/identity/plugin_rest_identity.c
b/src/identity/plugin_rest_identity.c
index 3fe749a52..49d7b58af 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -492,7 +492,7 @@ do_finished (void *cls, const char *emsg)
return;
}
resp = GNUNET_REST_create_response (NULL);
- handle->proc (handle->proc_cls, resp, MHD_HTTP_CREATED);
+ handle->proc (handle->proc_cls, resp, handle->response_code);
cleanup_handle (handle);
}
@@ -616,15 +616,16 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con,
//instead of parse
if (!json_is_object(data_js))
{
+ json_decref(data_js);
handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
- if (1 != json_object_size(data_js))
+ if (1 != json_object_size (data_js))
{
json_decref (data_js);
- handle->emsg = GNUNET_strdup ("Provided resource count invalid");
+ handle->emsg = GNUNET_strdup("Provided resource count invalid");
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
@@ -638,6 +639,13 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con,
return;
}
egoname = json_string_value (egoname_json);
+ if(0 >= strlen(egoname))
+ {
+ json_decref (data_js);
+ handle->emsg = GNUNET_strdup ("No name provided");
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
for (ego_entry = handle->ego_head;
NULL != ego_entry;
ego_entry = ego_entry->next)
@@ -653,6 +661,7 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con,
}
GNUNET_asprintf (&handle->name, "%s", egoname);
json_decref (data_js);
+ handle->response_code = MHD_HTTP_CREATED;
handle->op = GNUNET_IDENTITY_create (handle->identity_handle,
handle->name,
&do_finished,
@@ -752,6 +761,13 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
if ((NULL != name_json) && json_is_string (name_json))
{
newname = json_string_value (name_json);
+ if(0 >= strlen(newname))
+ {
+ json_decref (data_js);
+ handle->emsg = GNUNET_strdup ("No name provided");
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
for (ego_entry_tmp = handle->ego_head;
NULL != ego_entry_tmp;
ego_entry_tmp = ego_entry_tmp->next)
@@ -767,6 +783,7 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
return;
}
}
+ handle->response_code = MHD_HTTP_NO_CONTENT;
handle->op = GNUNET_IDENTITY_rename (handle->identity_handle,
ego_entry->identifier,
newname,
@@ -781,8 +798,16 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
if ( (NULL != subsys_json) && json_is_string (subsys_json))
{
subsys = json_string_value (subsys_json);
+ if(0 >= strlen(subsys))
+ {
+ json_decref (data_js);
+ handle->emsg = GNUNET_strdup ("No name provided");
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
GNUNET_asprintf (&handle->subsys, "%s", subsys);
json_decref (data_js);
+ handle->response_code = MHD_HTTP_NO_CONTENT;
handle->op = GNUNET_IDENTITY_set (handle->identity_handle,
handle->subsys,
ego_entry->ego,
@@ -837,6 +862,7 @@ ego_delete_cont (struct GNUNET_REST_RequestHandle
*con_handle,
cleanup_handle (handle);
return;
}
+ handle->response_code = MHD_HTTP_NO_CONTENT;
handle->op = GNUNET_IDENTITY_delete (handle->identity_handle,
ego_entry->identifier,
&do_finished,
@@ -980,7 +1006,7 @@ rest_identity_process_request(struct
GNUNET_REST_RequestHandle *conndata_handle,
handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
-
+ handle->response_code = MHD_HTTP_OK;
handle->proc_cls = proc_cls;
handle->proc = proc;
handle->state = ID_REST_STATE_INIT;
diff --git a/src/identity/test_plugin_identity_rest.sh
b/src/identity/test_plugin_identity_rest.sh
new file mode 100755
index 000000000..d43f4206b
--- /dev/null
+++ b/src/identity/test_plugin_identity_rest.sh
@@ -0,0 +1,252 @@
+#!/usr/bin/bash
+
+#First, start gnunet-arm and the rest-service. Make sure, no identity exists
+
+link_to_api="http://localhost:7776/identity"
+wrong_link="http://localhost:7776/idenmmmy"
+
+#Test GET (multiple identities) for error when no identity exists
+
+echo "No test for subsystem available"
+echo "The next test case can be ignored if you have already added identities"
+cache="$(curl --silent "$link_to_api" | grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for GET request when
missing identity\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for GET request when
missing identity\n"
+fi
+
+#Test POST success code, error response code and error json
+echo "The next test case can be ignored if you have already added an identity
with the name Test"
+cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}" 2>&1 |
grep "HTTP/1.1 201")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Error for good POST request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Success for good POST request\n"
+fi
+
+cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}" 2>&1 |
grep "HTTP/1.1 409")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for duplicate name POST
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for duplicate name POST
request\n"
+fi
+
+cache="$(curl -v -X "POST" "$link_to_api" 2>&1 | grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for no data POST
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for no data POST request\n"
+fi
+
+cache="$(curl -v -X "POST" "$link_to_api" --data "wrong" 2>&1 | grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong data POST
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong data POST
request\n"
+fi
+
+cache="$(curl -v -X "POST" "$link_to_api" --data "[{}]" 2>&1 | grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for json array input POST
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for json array input POST
request\n"
+fi
+
+cache="$(curl -v -X "POST" "$link_to_api" --data
"{\"name\":\"Test\",\"other\":\"Test\"}" 2>&1 | grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for multi element json
POST request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for multi element json POST
request\n"
+fi
+
+cache="$(curl -v -X "POST" "$link_to_api" --data "{\"nam\":\"Test\"}" 2>&1 |
grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong json POST
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong json POST
request\n"
+fi
+
+cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":123}" 2>&1 | grep
"error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong json type POST
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong json type POST
request\n"
+fi
+
+cache="$(curl -v -X "POST" "$link_to_api" --data "{\"name\":""}" 2>&1 | grep
"error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for no name POST
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for no name POST request\n"
+fi
+
+
+#Test GET (multiple identities) for success and error json
+cache="$(curl --silent "$link_to_api" | grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Success for good GET request
(multiple identities)\n"
+else
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Error for good GET request
(multiple identities)\n"
+fi
+
+
+id="$(gnunet-identity -d | grep "Test - " | sed "s/Test - //g")"
+#Test GET (one identity) for success and error json
+cache="$(curl --silent "${link_to_api}/$id" | grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Success for good GET request (one
identity)\n"
+else
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Error for good GET request (one
identity)\n"
+fi
+
+
+#Test DELETE success code, error response code and error json
+echo "Next tests for DELETE will probably fail when POST fails"
+cache="$(curl -v -X "DELETE" "${link_to_api}/$id" 2>&1 | grep "HTTP/1.1 404")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Success for good DELETE request\n"
+else
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Error for good DELETE request\n"
+fi
+
+curl --silent -X "POST" "$link_to_api" --data "{\"name\":\"Test\"}"
+id="$(gnunet-identity -d | grep "Test - " | sed "s/Test - //g")"
+
+cache="$(curl -v -X "DELETE" "${link_to_api}/df1" 2>&1 | grep "HTTP/1.1 404")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong DELETE
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong DELETE request\n"
+fi
+
+#Test PUT success code, error response codes and error json
+cache="$(curl -v -X "PUT" "${link_to_api}/$id" --data
"{\"newname\":\"NewTest\"}" 2>&1 | grep "HTTP/1.1 204")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Error for good PUT request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Success for good PUT request\n"
+fi
+
+cache="$(curl -v -X "PUT" "${link_to_api}/${id}1" --data
"{\"newname\":\"NewNewTest\"}" 2>&1 | grep "HTTP/1.1 404")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong identity PUT
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong identity PUT
request\n"
+fi
+
+cache="$(curl -v -X "PUT" "$link_to_api/$id" --data
"{\"newname\":\"NewTest\"}" 2>&1 | grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for duplicate name PUT
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for duplicate name PUT
request\n"
+fi
+
+cache="$(curl -v -X "PUT" "$link_to_api/$id" 2>&1 | grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for no data PUT request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for no data PUT request\n"
+fi
+
+cache="$(curl -v -X "PUT" "$link_to_api/$id" --data "wrong" 2>&1 | grep
"error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong data PUT
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong data PUT
request\n"
+fi
+
+cache="$(curl -v -X "PUT" "$link_to_api/$id" --data "[{}]" 2>&1 | grep
"error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for json array input PUT
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for json array input PUT
request\n"
+fi
+
+cache="$(curl -v -X "PUT" "$link_to_api/$id" --data
"{\"newname\":\"Test\",\"other\":\"Test\"}" 2>&1 | grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for multi element json
PUT request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for multi element json PUT
request\n"
+fi
+
+cache="$(curl -v -X "PUT" "$link_to_api/$id" --data "{\"newnam\":\"Test\"}"
2>&1 | grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong json PUT
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong json PUT
request\n"
+fi
+
+cache="$(curl -v -X "PUT" "$link_to_api/$id" --data "{\"newname\":123}" 2>&1 |
grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong json type PUT
request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong json type PUT
request\n"
+fi
+
+cache="$(curl -v -X "PUT" "$link_to_api/$id" --data "{\"newname\":""}" 2>&1 |
grep "error")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for no name PUT request\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for no name PUT request\n"
+fi
+#TODO Missing subsystem test
+
+#Missing OPTIONS success - nothing can really go wrong here
+
+#Test wrong url
+cache="$(curl -v "$wrong_link" 2>&1 | grep "HTTP/1.1 404")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong url GET request
\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong url GET request
\n"
+fi
+
+cache="$(curl -X "PUT" -v "$wrong_link/$id" --data "{\"newname\":\"Testing\"}"
2>&1 | grep "HTTP/1.1 404")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong url GET request
\n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong url GET request
\n"
+fi
+
+cache="$(curl -X "POST" -v "$wrong_link/$id" --data "{\"name\":\"Test\"}" 2>&1
| grep "HTTP/1.1 404")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong url POST
request \n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong url POST request
\n"
+fi
+
+cache="$(curl -X "DELETE" -v "${wrong_link}/$id" 2>&1 | grep "HTTP/1.1 404")"
+if [ "" == "$cache" ]
+then
+ echo -n -e "[\033[0;31m FAILURE\033[0m ] Success for wrong url DELETE
request \n"
+else
+ echo -n -e "[\033[0;32m SUCCESS\033[0m ] Error for wrong url DELETE
request \n"
+fi
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnunet] branch master updated (389f49398 -> 08c410658), gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 01/75: -wip remove jsonapi from identity, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 05/75: -merge branch 'master' of ssh://gnunet.org/gnunet into gsoc2018/rest_api, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 03/75: contrib: rename scripts/report.sh to scripts/gnunet-bugreport and install it., gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 04/75: identity rest api - finished and added test_script,
gnunet <=
- [GNUnet-SVN] [gnunet] 02/75: removed jsonapi structures, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 08/75: Add GPL2 licensed openrc service file, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 09/75: gnunet-bugreport: GNUtls->GnuTLS, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 10/75: fix NPE, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 14/75: guix-env.scm: Add python2-future., gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 15/75: rps profiler: summarize statistics, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 16/75: add option to disable v6, do not pass chunked encoding along, enable bypass of cert validation, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 06/75: extend the list of known package maintainers, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 07/75: cleanup identity rest api, removed jsonapi includes, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 18/75: add -z option to gnunet-namestore-fcfsd, gnunet, 2018/08/09