2 This file is part of GNUnet.
3 Copyright (C) 2013, 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file identity/test_identity.c
23 * @brief testcase for identity service
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_identity_service.h"
29 #include "gnunet_testing_lib.h"
32 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
36 * Return value from 'main'.
41 * Handle to identity service.
43 static struct GNUNET_IDENTITY_Handle *h;
46 * Handle to identity operation.
48 static struct GNUNET_IDENTITY_Operation *op;
51 * Handle for task for timeout termination.
53 static struct GNUNET_SCHEDULER_Task *endbadly_task;
68 * Clean up all resources used.
76 GNUNET_IDENTITY_cancel (op);
81 GNUNET_IDENTITY_disconnect (h);
88 * Termiante the testcase (failure).
95 GNUNET_SCHEDULER_shutdown ();
100 * Finish the testcase (successfully).
105 if (NULL != endbadly_task)
107 GNUNET_SCHEDULER_cancel (endbadly_task);
108 endbadly_task = NULL;
110 GNUNET_SCHEDULER_shutdown ();
115 * Called with events about egos.
118 * @param ego ego handle
119 * @param ego_ctx context for application to store data for this ego
120 * (during the lifetime of this process, initially NULL)
121 * @param identifier identifier assigned by the user for this ego,
122 * NULL if the user just deleted the ego and it
123 * must thus no longer be used
126 notification_cb (void *cls,
127 struct GNUNET_IDENTITY_Ego *ego,
129 const char *identifier)
131 static struct GNUNET_IDENTITY_Ego *my_ego;
136 case 0: /* end of initial iteration */
138 CHECK (NULL == identifier);
143 CHECK (NULL != identifier);
144 CHECK (0 == strcmp (identifier, "test-id"));
150 CHECK (my_ego == ego);
151 CHECK (NULL != identifier);
152 CHECK (0 == strcmp (identifier, "test"));
153 CHECK (*ctx == &round);
156 case 3: /* reconnect-down */
157 CHECK (my_ego == ego);
158 CHECK (NULL == identifier);
159 CHECK (*ctx == &round);
163 case 4: /* reconnect-up */
164 CHECK (NULL != identifier);
165 CHECK (0 == strcmp (identifier, "test"));
170 case 5: /* end of iteration after reconnect */
172 CHECK (NULL == identifier);
176 CHECK (my_ego == ego);
177 CHECK (*ctx == &round);
189 * Continuation called from successful delete operation.
192 * @param emsg (should also be NULL)
195 delete_cont (void *cls, const char *emsg)
198 CHECK (NULL == emsg);
205 * Continue by deleting the "test" identity.
210 finally_delete (void *cls)
212 op = GNUNET_IDENTITY_delete (h, "test", &delete_cont, NULL);
217 * Continuation called from expected-to-fail rename operation.
220 * @param emsg (should also be NULL)
223 fail_rename_cont (void *cls, const char *emsg)
225 CHECK (NULL != emsg);
227 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
234 * Continuation called from successful rename operation.
237 * @param emsg (should also be NULL)
240 success_rename_cont (void *cls, const char *emsg)
242 CHECK (NULL == emsg);
243 op = GNUNET_IDENTITY_rename (h, "test-id", "test", &fail_rename_cont, NULL);
248 * Called with events about created ego.
251 * @param pk private key of the ego, or NULL on error
252 * @param emsg error message
255 create_cb (void *cls,
256 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
260 CHECK (NULL == emsg);
262 GNUNET_IDENTITY_rename (h, "test-id", "test", &success_rename_cont, NULL);
267 * Main function of the test, run from scheduler.
270 * @param cfg configuration we use (also to connect to identity service)
271 * @param peer handle to access more of the peer (not used)
275 const struct GNUNET_CONFIGURATION_Handle *cfg,
276 struct GNUNET_TESTING_Peer *peer)
278 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
279 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
280 h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL);
282 op = GNUNET_IDENTITY_create (h, "test-id", NULL, &create_cb, NULL);
287 main (int argc, char *argv[])
289 GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service");
291 if (0 != GNUNET_TESTING_service_run ("test-identity",
293 "test_identity.conf",
297 GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service");
302 /* end of test_identity.c */