aboutsummaryrefslogtreecommitdiff
path: root/src/rest-plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/rest-plugins')
-rw-r--r--src/rest-plugins/plugin_rest_namestore.c193
-rwxr-xr-xsrc/rest-plugins/test_plugin_rest_gns.sh50
-rwxr-xr-xsrc/rest-plugins/test_plugin_rest_identity.sh157
-rwxr-xr-xsrc/rest-plugins/test_plugin_rest_namestore.sh147
4 files changed, 500 insertions, 47 deletions
diff --git a/src/rest-plugins/plugin_rest_namestore.c b/src/rest-plugins/plugin_rest_namestore.c
index 1d72d13ff..2926f4b90 100644
--- a/src/rest-plugins/plugin_rest_namestore.c
+++ b/src/rest-plugins/plugin_rest_namestore.c
@@ -458,10 +458,7 @@ namestore_list_finished (void *cls)
458 handle->list_it = NULL; 458 handle->list_it = NULL;
459 459
460 if (NULL == handle->resp_object) 460 if (NULL == handle->resp_object)
461 { 461 handle->resp_object = json_array();
462 GNUNET_SCHEDULER_add_now (&do_error, handle);
463 return;
464 }
465 462
466 result_str = json_dumps (handle->resp_object, 0); 463 result_str = json_dumps (handle->resp_object, 0);
467 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 464 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
@@ -508,6 +505,48 @@ namestore_list_iteration (void *cls,
508 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1); 505 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1);
509} 506}
510 507
508/**
509 * @param cls closure
510 * @param ego ego handle
511 * @param ctx context for application to store data for this ego
512 * (during the lifetime of this process, initially NULL)
513 * @param identifier identifier assigned by the user for this ego,
514 * NULL if the user just deleted the ego and it
515 * must thus no longer be used
516 */
517static void
518default_ego_get (void *cls,
519 struct GNUNET_IDENTITY_Ego *ego,
520 void **ctx,
521 const char *identifier)
522{
523 struct RequestHandle *handle = cls;
524 handle->op = NULL;
525
526 if (ego == NULL)
527 {
528 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
529 GNUNET_SCHEDULER_add_now (&do_error, handle);
530 return;
531 }
532 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
533
534 handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
535 handle->zone_pkey,
536 &namestore_iteration_error,
537 handle,
538 &namestore_list_iteration,
539 handle,
540 &namestore_list_finished,
541 handle);
542 if (NULL == handle->list_it)
543 {
544 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
545 GNUNET_SCHEDULER_add_now (&do_error, handle);
546 return;
547 }
548}
549
511 550
512/** 551/**
513 * Handle namestore GET request 552 * Handle namestore GET request
@@ -546,10 +585,13 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
546 { 585 {
547 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); 586 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
548 } 587 }
588
549 if (NULL == handle->zone_pkey) 589 if (NULL == handle->zone_pkey)
550 { 590 {
551 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); 591 handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
552 GNUNET_SCHEDULER_add_now (&do_error, handle); 592 "namestore",
593 &default_ego_get,
594 handle);
553 return; 595 return;
554 } 596 }
555 handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, 597 handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
@@ -570,6 +612,48 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
570 612
571 613
572/** 614/**
615 * @param cls closure
616 * @param ego ego handle
617 * @param ctx context for application to store data for this ego
618 * (during the lifetime of this process, initially NULL)
619 * @param identifier identifier assigned by the user for this ego,
620 * NULL if the user just deleted the ego and it
621 * must thus no longer be used
622 */
623static void
624default_ego_post (void *cls,
625 struct GNUNET_IDENTITY_Ego *ego,
626 void **ctx,
627 const char *identifier)
628{
629 struct RequestHandle *handle = cls;
630 handle->op = NULL;
631
632 if (ego == NULL)
633 {
634 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
635 GNUNET_SCHEDULER_add_now (&do_error, handle);
636 return;
637 }
638 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
639
640 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
641 handle->zone_pkey,
642 handle->record_name,
643 1,
644 handle->rd,
645 &create_finished,
646 handle);
647 if (NULL == handle->add_qe)
648 {
649 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
650 GNUNET_SCHEDULER_add_now (&do_error, handle);
651 return;
652 }
653}
654
655
656/**
573 * Handle namestore POST request 657 * Handle namestore POST request
574 * 658 *
575 * @param con_handle the connection handle 659 * @param con_handle the connection handle
@@ -663,17 +747,61 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
663 } 747 }
664 if (NULL == handle->zone_pkey) 748 if (NULL == handle->zone_pkey)
665 { 749 {
750 handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
751 "namestore",
752 &default_ego_post,
753 handle);
754 return;
755 }
756 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
757 handle->zone_pkey,
758 handle->record_name,
759 1,
760 handle->rd,
761 &create_finished,
762 handle);
763 if (NULL == handle->add_qe)
764 {
765 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
766 GNUNET_SCHEDULER_add_now (&do_error, handle);
767 return;
768 }
769}
770
771
772/**
773 * @param cls closure
774 * @param ego ego handle
775 * @param ctx context for application to store data for this ego
776 * (during the lifetime of this process, initially NULL)
777 * @param identifier identifier assigned by the user for this ego,
778 * NULL if the user just deleted the ego and it
779 * must thus no longer be used
780 */
781static void
782default_ego_delete (void *cls,
783 struct GNUNET_IDENTITY_Ego *ego,
784 void **ctx,
785 const char *identifier)
786{
787 struct RequestHandle *handle = cls;
788 handle->op = NULL;
789
790 if (ego == NULL)
791 {
666 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); 792 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE);
667 GNUNET_SCHEDULER_add_now (&do_error, handle); 793 GNUNET_SCHEDULER_add_now (&do_error, handle);
668 return; 794 return;
669 } 795 }
796 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
797
670 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, 798 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
671 handle->zone_pkey, 799 handle->zone_pkey,
672 handle->record_name, 800 handle->record_name,
673 1, 801 0,
674 handle->rd, 802 NULL,
675 &create_finished, 803 &del_finished,
676 handle); 804 handle);
677 if (NULL == handle->add_qe) 805 if (NULL == handle->add_qe)
678 { 806 {
679 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); 807 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
@@ -736,8 +864,10 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle,
736 864
737 if (NULL == handle->zone_pkey) 865 if (NULL == handle->zone_pkey)
738 { 866 {
739 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); 867 handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
740 GNUNET_SCHEDULER_add_now (&do_error, handle); 868 "namestore",
869 &default_ego_delete,
870 handle);
741 return; 871 return;
742 } 872 }
743 873
@@ -811,30 +941,6 @@ init_cont (struct RequestHandle *handle)
811 } 941 }
812} 942}
813 943
814/**
815 * @param cls closure
816 * @param ego ego handle
817 * @param ctx context for application to store data for this ego
818 * (during the lifetime of this process, initially NULL)
819 * @param identifier identifier assigned by the user for this ego,
820 * NULL if the user just deleted the ego and it
821 * must thus no longer be used
822 */
823static void
824default_ego_cb (void *cls,
825 struct GNUNET_IDENTITY_Ego *ego,
826 void **ctx,
827 const char *identifier)
828{
829 struct RequestHandle *handle = cls;
830 handle->op = NULL;
831
832 if (ego != NULL)
833 {
834 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
835 }
836}
837
838 944
839/** 945/**
840 * This function is initially called for all egos and then again 946 * This function is initially called for all egos and then again
@@ -877,17 +983,10 @@ id_connect_cb (void *cls,
877 struct EgoEntry *ego_entry; 983 struct EgoEntry *ego_entry;
878 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 984 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
879 985
880 if ((NULL == ego) && (NULL == handle->zone_pkey))
881 {
882 handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
883 "namestore",
884 &default_ego_cb,
885 handle);
886 }
887 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) 986 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
888 { 987 {
889 handle->state = ID_REST_STATE_POST_INIT; 988 handle->state = ID_REST_STATE_POST_INIT;
890 init_cont (handle); 989 init_cont(handle);
891 return; 990 return;
892 } 991 }
893 if (ID_REST_STATE_INIT == handle->state) 992 if (ID_REST_STATE_INIT == handle->state)
@@ -934,8 +1033,8 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
934 handle->url[strlen (handle->url)-1] = '\0'; 1033 handle->url[strlen (handle->url)-1] = '\0';
935 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 1034 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
936 1035
937 handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle);
938 handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); 1036 handle->ns_handle = GNUNET_NAMESTORE_connect (cfg);
1037 handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle);
939 handle->timeout_task = 1038 handle->timeout_task =
940 GNUNET_SCHEDULER_add_delayed (handle->timeout, 1039 GNUNET_SCHEDULER_add_delayed (handle->timeout,
941 &do_error, 1040 &do_error,
diff --git a/src/rest-plugins/test_plugin_rest_gns.sh b/src/rest-plugins/test_plugin_rest_gns.sh
new file mode 100755
index 000000000..ec495a04b
--- /dev/null
+++ b/src/rest-plugins/test_plugin_rest_gns.sh
@@ -0,0 +1,50 @@
1#!/usr/bin/bash
2
3#First, start gnunet-arm and the rest-service.
4#Exit 0 means success, exit 1 means failed test
5
6gns_link="http://localhost:7776/gns"
7wrong_link="http://localhost:7776/gnsandmore"
8
9curl_get () {
10 #$1 is link
11 #$2 is grep
12 cache="$(curl -v "$1" 2>&1 | grep "$2")"
13 #echo $cache
14 if [ "" == "$cache" ]
15 then
16 exit 1
17 fi
18}
19
20gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1
21
22curl_get "$gns_link/www.test_plugin_rest_gns" "error"
23
24gnunet-identity -C "test_plugin_rest_gns"
25
26curl_get "$gns_link/www.test_plugin_rest_gns" "\[\]"
27
28gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.1 -t A
29
30curl_get "$gns_link/www.test_plugin_rest_gns" "1.1.1.1"
31
32gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1::1 -t AAAA
33
34curl_get "$gns_link/www.test_plugin_rest_gns" "1::1.*1.1.1.1"
35
36gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.2 -t A
37
38curl_get "$gns_link/www.test_plugin_rest_gns" "1.1.1.2.*1::1.*1.1.1.1"
39curl_get "$gns_link/www.test_plugin_rest_gns?record_type=A" "1.1.1.2.*1.1.1.1"
40curl_get "$gns_link/www.test_plugin_rest_gns?record_type=AAAA" "1::1"
41curl_get "$gns_link/www.test_plugin_rest_gns?record_type=WRONG_TYPE" "1.1.1.2.*1::1.*1.1.1.1"
42
43gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www1 -e 1d -V 1.1.1.1 -t A
44curl_get "$gns_link/www1.test_plugin_rest_gns" "1.1.1.1"
45
46gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1
47
48curl_get "$gns_link/www1.test_plugin_rest_gns" "error"
49
50exit 0
diff --git a/src/rest-plugins/test_plugin_rest_identity.sh b/src/rest-plugins/test_plugin_rest_identity.sh
new file mode 100755
index 000000000..a5879dd7e
--- /dev/null
+++ b/src/rest-plugins/test_plugin_rest_identity.sh
@@ -0,0 +1,157 @@
1#!/usr/bin/bash
2
3#First, start gnunet-arm and the rest-service.
4#Exit 0 means success, exit 1 means failed test
5
6identity_link="http://localhost:7776/identity"
7wrong_link="http://localhost:7776/identityandmore"
8
9
10curl_get () {
11 #$1 is link
12 #$2 is grep
13 cache="$(curl -v "$1" 2>&1 | grep "$2")"
14 #echo $cache
15 if [ "" == "$cache" ]
16 then
17 exit 1
18 fi
19}
20
21curl_post () {
22 #$1 is link
23 #$2 is data
24 #$3 is grep
25 cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")"
26 #echo $cache
27 if [ "" == "$cache" ]
28 then
29 exit 1
30 fi
31}
32
33curl_delete () {
34 #$1 is link
35 #$2 is grep
36 cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")"
37 #echo $cache
38 if [ "" == "$cache" ]
39 then
40 exit 1
41 fi
42}
43
44curl_put () {
45 #$1 is link
46 #$2 is data
47 #$3 is grep
48 cache="$(curl -v -X "PUT" "$1" --data "$2" 2>&1 | grep "$3")"
49 #echo $cache
50 if [ "" == "$cache" ]
51 then
52 exit 1
53 fi
54}
55
56#Test GET
57test="$(gnunet-identity -d)"
58#if no identity exists
59if [ "" == "$test" ]
60then
61 curl_get "$identity_link/all" "error"
62 gnunet-identity -C "test_plugin_rest_identity"
63 name="$(gnunet-identity -d | awk 'NR==1{print $1}')"
64 public="$(gnunet-identity -d | awk 'NR==1{print $3}')"
65
66 curl_get "${identity_link}/name/$name" "$public"
67 curl_get "${identity_link}/name/$public" "error"
68 curl_get "${identity_link}/name/" "error"
69
70 curl_get "${identity_link}/pubkey/$public" "$name"
71 curl_get "${identity_link}/pubkey/$name" "error"
72 curl_get "${identity_link}/pubkey/" "error"
73
74 gnunet-identity -D "test_plugin_rest_identity"
75else
76 name="$(gnunet-identity -d | awk 'NR==1{print $1}')"
77 public="$(gnunet-identity -d | awk 'NR==1{print $3}')"
78
79 curl_get "${identity_link}/name/$name" "$public"
80 curl_get "${identity_link}/name/$public" "error"
81 curl_get "${identity_link}/name/" "error"
82
83 curl_get "${identity_link}/pubkey/$public" "$name"
84 curl_get "${identity_link}/pubkey/$name" "error"
85 curl_get "${identity_link}/pubkey/" "error"
86fi
87
88#Test POST
89gnunet-identity -D "test_plugin_rest_identity" > /dev/null 2>&1
90gnunet-identity -D "test_plugin_rest_identity1" > /dev/null 2>&1
91
92curl_post "${identity_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 201 Created"
93curl_post "${identity_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 409"
94curl_post "${identity_link}" '{"name":"Test_plugin_rest_identity"}' "HTTP/1.1 409"
95curl_post "${identity_link}" '{}' "error"
96curl_post "${identity_link}" '' "error"
97curl_post "${identity_link}" '{"name":""}' "error"
98curl_post "${identity_link}" '{"name":123}' "error"
99curl_post "${identity_link}" '{"name":[]}' "error"
100curl_post "${identity_link}" '{"name1":"test_plugin_rest_identity"}' "error"
101curl_post "${identity_link}" '{"other":""}' "error"
102curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1", "other":"test_plugin_rest_identity2"}' "error"
103
104#Test PUT
105name="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $1}')"
106public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')"
107
108curl_put "${identity_link}/pubkey/$public" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 204"
109curl_put "${identity_link}/pubkey/$public" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 409"
110curl_put "${identity_link}/pubkey/${public}xx" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404"
111curl_put "${identity_link}/pubkey/" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404"
112curl_put "${identity_link}/pubke" '{"newname":"test_plugin_rest_identity1"}' "error"
113curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","other":"sdfdsf"}' "error"
114curl_put "${identity_link}/pubkey/$name" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404"
115curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"test_plugin_rest_identity"}' "HTTP/1.1 204"
116curl_put "${identity_link}/pubkey/$public" '{"newnam":"test_plugin_rest_identity"}' "error"
117curl_put "${identity_link}/name/test_plugin_rest_identity" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 204"
118curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"TEST_plugin_rest_identity1"}' "HTTP/1.1 409"
119curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 409"
120curl_put "${identity_link}/name/test_plugin_rest_identityxxx" '{"newname":"test_plugin_rest_identity"}' "HTTP/1.1 404"
121curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"test_plugin_rest_identity"}' "HTTP/1.1 204"
122curl_put "${identity_link}/name/test_plugin_rest_identity" '{"newnam":"test_plugin_rest_identityfail"}' "error"
123
124#Test subsystem
125curl_put "${identity_link}/subsystem/test_plugin_rest_identity" '{"subsystem":"namestore"}' "HTTP/1.1 204"
126curl_put "${identity_link}/subsystem/test_plugin_rest_identity" '{"subsystem":"namestore"}' "HTTP/1.1 204"
127curl_get "${identity_link}/subsystem/namestore" "test_plugin_rest_identity"
128public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')"
129curl_put "${identity_link}/subsystem/$public" '{"subsystem":"namestore"}' "HTTP/1.1 404"
130curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created"
131curl_get "${identity_link}/subsystem/test_plugin_rest_identity_no_subsystem" "error"
132curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsystem":"test_plugin_rest_identity_no_subsystem"}' "HTTP/1.1 204"
133curl_get "${identity_link}/subsystem/test_plugin_rest_identity_no_subsystem" "test_plugin_rest_identity1"
134
135curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsyste":"test_plugin_rest_identity_no_subsystem"}' "error"
136curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsystem":"test_plugin_rest_identity_no_subsystem"}' "HTTP/1.1 204"
137
138#Test DELETE
139curl_delete "${identity_link}/name/test_plugin_rest_identity" "HTTP/1.1 204"
140curl_get "${identity_link}/name/test_plugin_rest_identity" "error"
141curl_delete "${identity_link}/name/TEST_plugin_rest_identity1" "HTTP/1.1 204"
142curl_delete "${identity_link}/name/test_plugin_rest_identity1" "HTTP/1.1 404"
143curl_get "${identity_link}/name/test_plugin_rest_identity1" "error"
144curl_delete "${identity_link}/name/test_plugin_rest_identity_not_found" "HTTP/1.1 404"
145curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created"
146public="$(gnunet-identity -d | grep "test_plugin_rest_identity1" | awk 'NR==1{print $3}')"
147curl_delete "${identity_link}/pubkey/$public" "HTTP/1.1 204"
148curl_delete "${identity_link}/pubke/$public" "error"
149curl_delete "${identity_link}/pubkey/${public}other=232" "HTTP/1.1 404"
150
151#Test wrong_link
152curl_get "$wrong_link" "HTTP/1.1 404"
153curl_post "$wrong_link" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 404"
154curl_put "$wrong_link/name/test_plugin_rest_identity" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404"
155curl_delete "$wrong_link/name/test_plugin_rest_identity1" "HTTP/1.1 404"
156
157exit 0;
diff --git a/src/rest-plugins/test_plugin_rest_namestore.sh b/src/rest-plugins/test_plugin_rest_namestore.sh
new file mode 100755
index 000000000..532c7caae
--- /dev/null
+++ b/src/rest-plugins/test_plugin_rest_namestore.sh
@@ -0,0 +1,147 @@
1#!/usr/bin/bash
2
3#First, start gnunet-arm and the rest-service.
4#Exit 0 means success, exit 1 means failed test
5
6namestore_link="http://localhost:7776/namestore"
7wrong_link="http://localhost:7776/namestoreandmore"
8
9
10curl_get () {
11 #$1 is link
12 #$2 is grep
13 cache="$(curl -v "$1" 2>&1 | grep "$2")"
14 echo $cache
15 if [ "" == "$cache" ]
16 then
17 exit 1
18 fi
19}
20
21curl_post () {
22 #$1 is link
23 #$2 is data
24 #$3 is grep
25 cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")"
26 echo $cache
27 if [ "" == "$cache" ]
28 then
29 exit 1
30 fi
31}
32
33curl_delete () {
34 #$1 is link
35 #$2 is grep
36 cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")"
37 echo $cache
38 if [ "" == "$cache" ]
39 then
40 exit 1
41 fi
42}
43
44# curl_put () {
45# #$1 is link
46# #$2 is data
47# #$3 is grep
48# cache="$(curl -v -X "PUT" "$1" --data "$2" 2>&1 | grep "$3")"
49# #echo $cache
50# if [ "" == "$cache" ]
51# then
52# exit 1
53# fi
54# }
55
56#Test subsystem default identity
57
58#Test GET
59gnunet-identity -D "test_plugin_rest_namestore"
60gnunet-identity -C "test_plugin_rest_namestore"
61test="$(gnunet-namestore -D -z "test_plugin_rest_namestore")"
62name="test_plugin_rest_namestore"
63public="$(gnunet-identity -d | grep "test_plugin_rest_namestore" | awk 'NR==1{print $3}')"
64if [ "" == "$test" ]
65then
66 #if no entries for test_plugin_rest_namestore
67 curl_get "${namestore_link}/$name" "error"
68 curl_get "${namestore_link}/" "error"
69 curl_get "${namestore_link}/$public" "error"
70else
71 #if entries exists (that should not be possible)
72 curl_get "${namestore_link}" "HTTP/1.1 200 OK"
73 curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK"
74 curl_get "${namestore_link}/" "error"
75 curl_get "${namestore_link}/$public" "error"
76fi
77gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
78curl_get "${namestore_link}" "HTTP/1.1 200 OK"
79curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK"
80curl_get "${namestore_link}/" "error"
81curl_get "${namestore_link}/$public" "error"
82gnunet-namestore -z $name -d -n "test_entry"
83
84#Test POST with NAME
85curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
86gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
87#value
88curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
89gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
90curl_post "${namestore_link}/$name" '{"value":"", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
91gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
92curl_post "${namestore_link}/$name" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
93gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
94#time
95curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"0d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204"
96gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
97curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"10000d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204"
98gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
99curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"now","flag":0,"record_name":"test_entry"}' "error"
100gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
101curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"","flag":0,"record_name":"test_entry"}' "error"
102gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
103curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time_missing":"1d","flag":0,"record_name":"test_entry"}' "error"
104gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
105#flag
106curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
107gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
108curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":2,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
109gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
110curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":8,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
111gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
112curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":16,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
113gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
114curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":-1,"record_name":"test_entry"}' "error"
115gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
116curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":"Test","record_name":"test_entry"}' "error"
117gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
118curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":,"record_name":"test_entry"}' "error"
119gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
120curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag_missing":0,"record_name":"test_entry"}' "error"
121gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
122#record_name
123curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
124curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content"
125gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
126curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":""}' "error"
127gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
128curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name_missing":"test_entry"}' "error"
129gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
130
131#wrong zone
132curl_post "${namestore_link}/$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error"
133gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1
134
135#Test DELETE
136gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
137curl_delete "${namestore_link}/$name?record_name=test_entry" "HTTP/1.1 204"
138curl_delete "${namestore_link}/$name?record_name=test_entry" "error"
139gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY"
140curl_delete "${namestore_link}/$public?record_name=test_entry" "error"
141
142
143#Test default identity
144#not possible without defining
145
146exit 0;
147