diff options
Diffstat (limited to 'src/rest-plugins')
-rw-r--r-- | src/rest-plugins/plugin_rest_namestore.c | 193 | ||||
-rwxr-xr-x | src/rest-plugins/test_plugin_rest_gns.sh | 50 | ||||
-rwxr-xr-x | src/rest-plugins/test_plugin_rest_identity.sh | 157 | ||||
-rwxr-xr-x | src/rest-plugins/test_plugin_rest_namestore.sh | 147 |
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 | */ | ||
517 | static void | ||
518 | default_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 | */ | ||
623 | static void | ||
624 | default_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 | */ | ||
781 | static void | ||
782 | default_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 | */ | ||
823 | static void | ||
824 | default_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 | |||
6 | gns_link="http://localhost:7776/gns" | ||
7 | wrong_link="http://localhost:7776/gnsandmore" | ||
8 | |||
9 | curl_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 | |||
20 | gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1 | ||
21 | |||
22 | curl_get "$gns_link/www.test_plugin_rest_gns" "error" | ||
23 | |||
24 | gnunet-identity -C "test_plugin_rest_gns" | ||
25 | |||
26 | curl_get "$gns_link/www.test_plugin_rest_gns" "\[\]" | ||
27 | |||
28 | gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.1 -t A | ||
29 | |||
30 | curl_get "$gns_link/www.test_plugin_rest_gns" "1.1.1.1" | ||
31 | |||
32 | gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1::1 -t AAAA | ||
33 | |||
34 | curl_get "$gns_link/www.test_plugin_rest_gns" "1::1.*1.1.1.1" | ||
35 | |||
36 | gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.2 -t A | ||
37 | |||
38 | curl_get "$gns_link/www.test_plugin_rest_gns" "1.1.1.2.*1::1.*1.1.1.1" | ||
39 | curl_get "$gns_link/www.test_plugin_rest_gns?record_type=A" "1.1.1.2.*1.1.1.1" | ||
40 | curl_get "$gns_link/www.test_plugin_rest_gns?record_type=AAAA" "1::1" | ||
41 | curl_get "$gns_link/www.test_plugin_rest_gns?record_type=WRONG_TYPE" "1.1.1.2.*1::1.*1.1.1.1" | ||
42 | |||
43 | gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www1 -e 1d -V 1.1.1.1 -t A | ||
44 | curl_get "$gns_link/www1.test_plugin_rest_gns" "1.1.1.1" | ||
45 | |||
46 | gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1 | ||
47 | |||
48 | curl_get "$gns_link/www1.test_plugin_rest_gns" "error" | ||
49 | |||
50 | exit 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 | |||
6 | identity_link="http://localhost:7776/identity" | ||
7 | wrong_link="http://localhost:7776/identityandmore" | ||
8 | |||
9 | |||
10 | curl_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 | |||
21 | curl_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 | |||
33 | curl_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 GET | ||
57 | test="$(gnunet-identity -d)" | ||
58 | #if no identity exists | ||
59 | if [ "" == "$test" ] | ||
60 | then | ||
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" | ||
75 | else | ||
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" | ||
86 | fi | ||
87 | |||
88 | #Test POST | ||
89 | gnunet-identity -D "test_plugin_rest_identity" > /dev/null 2>&1 | ||
90 | gnunet-identity -D "test_plugin_rest_identity1" > /dev/null 2>&1 | ||
91 | |||
92 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 201 Created" | ||
93 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 409" | ||
94 | curl_post "${identity_link}" '{"name":"Test_plugin_rest_identity"}' "HTTP/1.1 409" | ||
95 | curl_post "${identity_link}" '{}' "error" | ||
96 | curl_post "${identity_link}" '' "error" | ||
97 | curl_post "${identity_link}" '{"name":""}' "error" | ||
98 | curl_post "${identity_link}" '{"name":123}' "error" | ||
99 | curl_post "${identity_link}" '{"name":[]}' "error" | ||
100 | curl_post "${identity_link}" '{"name1":"test_plugin_rest_identity"}' "error" | ||
101 | curl_post "${identity_link}" '{"other":""}' "error" | ||
102 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1", "other":"test_plugin_rest_identity2"}' "error" | ||
103 | |||
104 | #Test PUT | ||
105 | name="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $1}')" | ||
106 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')" | ||
107 | |||
108 | curl_put "${identity_link}/pubkey/$public" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 204" | ||
109 | curl_put "${identity_link}/pubkey/$public" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 409" | ||
110 | curl_put "${identity_link}/pubkey/${public}xx" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404" | ||
111 | curl_put "${identity_link}/pubkey/" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404" | ||
112 | curl_put "${identity_link}/pubke" '{"newname":"test_plugin_rest_identity1"}' "error" | ||
113 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","other":"sdfdsf"}' "error" | ||
114 | curl_put "${identity_link}/pubkey/$name" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404" | ||
115 | curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"test_plugin_rest_identity"}' "HTTP/1.1 204" | ||
116 | curl_put "${identity_link}/pubkey/$public" '{"newnam":"test_plugin_rest_identity"}' "error" | ||
117 | curl_put "${identity_link}/name/test_plugin_rest_identity" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 204" | ||
118 | curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"TEST_plugin_rest_identity1"}' "HTTP/1.1 409" | ||
119 | curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 409" | ||
120 | curl_put "${identity_link}/name/test_plugin_rest_identityxxx" '{"newname":"test_plugin_rest_identity"}' "HTTP/1.1 404" | ||
121 | curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"test_plugin_rest_identity"}' "HTTP/1.1 204" | ||
122 | curl_put "${identity_link}/name/test_plugin_rest_identity" '{"newnam":"test_plugin_rest_identityfail"}' "error" | ||
123 | |||
124 | #Test subsystem | ||
125 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity" '{"subsystem":"namestore"}' "HTTP/1.1 204" | ||
126 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity" '{"subsystem":"namestore"}' "HTTP/1.1 204" | ||
127 | curl_get "${identity_link}/subsystem/namestore" "test_plugin_rest_identity" | ||
128 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')" | ||
129 | curl_put "${identity_link}/subsystem/$public" '{"subsystem":"namestore"}' "HTTP/1.1 404" | ||
130 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created" | ||
131 | curl_get "${identity_link}/subsystem/test_plugin_rest_identity_no_subsystem" "error" | ||
132 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsystem":"test_plugin_rest_identity_no_subsystem"}' "HTTP/1.1 204" | ||
133 | curl_get "${identity_link}/subsystem/test_plugin_rest_identity_no_subsystem" "test_plugin_rest_identity1" | ||
134 | |||
135 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsyste":"test_plugin_rest_identity_no_subsystem"}' "error" | ||
136 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsystem":"test_plugin_rest_identity_no_subsystem"}' "HTTP/1.1 204" | ||
137 | |||
138 | #Test DELETE | ||
139 | curl_delete "${identity_link}/name/test_plugin_rest_identity" "HTTP/1.1 204" | ||
140 | curl_get "${identity_link}/name/test_plugin_rest_identity" "error" | ||
141 | curl_delete "${identity_link}/name/TEST_plugin_rest_identity1" "HTTP/1.1 204" | ||
142 | curl_delete "${identity_link}/name/test_plugin_rest_identity1" "HTTP/1.1 404" | ||
143 | curl_get "${identity_link}/name/test_plugin_rest_identity1" "error" | ||
144 | curl_delete "${identity_link}/name/test_plugin_rest_identity_not_found" "HTTP/1.1 404" | ||
145 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created" | ||
146 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity1" | awk 'NR==1{print $3}')" | ||
147 | curl_delete "${identity_link}/pubkey/$public" "HTTP/1.1 204" | ||
148 | curl_delete "${identity_link}/pubke/$public" "error" | ||
149 | curl_delete "${identity_link}/pubkey/${public}other=232" "HTTP/1.1 404" | ||
150 | |||
151 | #Test wrong_link | ||
152 | curl_get "$wrong_link" "HTTP/1.1 404" | ||
153 | curl_post "$wrong_link" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 404" | ||
154 | curl_put "$wrong_link/name/test_plugin_rest_identity" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404" | ||
155 | curl_delete "$wrong_link/name/test_plugin_rest_identity1" "HTTP/1.1 404" | ||
156 | |||
157 | exit 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 | |||
6 | namestore_link="http://localhost:7776/namestore" | ||
7 | wrong_link="http://localhost:7776/namestoreandmore" | ||
8 | |||
9 | |||
10 | curl_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 | |||
21 | curl_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 | |||
33 | curl_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 | ||
59 | gnunet-identity -D "test_plugin_rest_namestore" | ||
60 | gnunet-identity -C "test_plugin_rest_namestore" | ||
61 | test="$(gnunet-namestore -D -z "test_plugin_rest_namestore")" | ||
62 | name="test_plugin_rest_namestore" | ||
63 | public="$(gnunet-identity -d | grep "test_plugin_rest_namestore" | awk 'NR==1{print $3}')" | ||
64 | if [ "" == "$test" ] | ||
65 | then | ||
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" | ||
70 | else | ||
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" | ||
76 | fi | ||
77 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" | ||
78 | curl_get "${namestore_link}" "HTTP/1.1 200 OK" | ||
79 | curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK" | ||
80 | curl_get "${namestore_link}/" "error" | ||
81 | curl_get "${namestore_link}/$public" "error" | ||
82 | gnunet-namestore -z $name -d -n "test_entry" | ||
83 | |||
84 | #Test POST with NAME | ||
85 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
86 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
87 | #value | ||
88 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error" | ||
89 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
90 | curl_post "${namestore_link}/$name" '{"value":"", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error" | ||
91 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
92 | curl_post "${namestore_link}/$name" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error" | ||
93 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
94 | #time | ||
95 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"0d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204" | ||
96 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
97 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"10000d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204" | ||
98 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
99 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"now","flag":0,"record_name":"test_entry"}' "error" | ||
100 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
101 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"","flag":0,"record_name":"test_entry"}' "error" | ||
102 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
103 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time_missing":"1d","flag":0,"record_name":"test_entry"}' "error" | ||
104 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
105 | #flag | ||
106 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
107 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
108 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":2,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
109 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
110 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":8,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
111 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
112 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":16,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
113 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
114 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":-1,"record_name":"test_entry"}' "error" | ||
115 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
116 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":"Test","record_name":"test_entry"}' "error" | ||
117 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
118 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":,"record_name":"test_entry"}' "error" | ||
119 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
120 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag_missing":0,"record_name":"test_entry"}' "error" | ||
121 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
122 | #record_name | ||
123 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
124 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
125 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
126 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":""}' "error" | ||
127 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
128 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name_missing":"test_entry"}' "error" | ||
129 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
130 | |||
131 | #wrong zone | ||
132 | curl_post "${namestore_link}/$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error" | ||
133 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
134 | |||
135 | #Test DELETE | ||
136 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" | ||
137 | curl_delete "${namestore_link}/$name?record_name=test_entry" "HTTP/1.1 204" | ||
138 | curl_delete "${namestore_link}/$name?record_name=test_entry" "error" | ||
139 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" | ||
140 | curl_delete "${namestore_link}/$public?record_name=test_entry" "error" | ||
141 | |||
142 | |||
143 | #Test default identity | ||
144 | #not possible without defining | ||
145 | |||
146 | exit 0; | ||
147 | |||