aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_create_update.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-19 13:33:19 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-19 13:33:19 +0000
commit15f55fea6e6d2d1656e345eab131887efbd937b4 (patch)
tree4f73dcb99b65afaaec412b4a2969771497a6f876 /src/namestore/test_namestore_api_create_update.c
parent0f084973d63c46217d25e6660fba56755f26e6bb (diff)
downloadgnunet-15f55fea6e6d2d1656e345eab131887efbd937b4.tar.gz
gnunet-15f55fea6e6d2d1656e345eab131887efbd937b4.zip
-fixing IO-error bug in namestore tests on buildbots, simplifying testcases by using new testing API, eliminating dead code
Diffstat (limited to 'src/namestore/test_namestore_api_create_update.c')
-rw-r--r--src/namestore/test_namestore_api_create_update.c331
1 files changed, 34 insertions, 297 deletions
diff --git a/src/namestore/test_namestore_api_create_update.c b/src/namestore/test_namestore_api_create_update.c
index 93570e458..e898a3050 100644
--- a/src/namestore/test_namestore_api_create_update.c
+++ b/src/namestore/test_namestore_api_create_update.c
@@ -24,65 +24,48 @@
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_common.h" 25#include "gnunet_common.h"
26#include "gnunet_namestore_service.h" 26#include "gnunet_namestore_service.h"
27#include "gnunet_testing_lib-new.h"
27#include "namestore.h" 28#include "namestore.h"
28#include "gnunet_signatures.h" 29#include "gnunet_signatures.h"
29 30
30#define VERBOSE GNUNET_NO
31 31
32#define RECORDS 1 32#define RECORDS 1
33
33#define TEST_RECORD_TYPE 1234 34#define TEST_RECORD_TYPE 1234
35
34#define TEST_RECORD_DATALEN 123 36#define TEST_RECORD_DATALEN 123
37
35#define TEST_RECORD_DATA 'a' 38#define TEST_RECORD_DATA 'a'
36 39
37#define TEST_CREATE_RECORD_TYPE 4321 40#define TEST_CREATE_RECORD_TYPE 4321
41
38#define TEST_CREATE_RECORD_DATALEN 255 42#define TEST_CREATE_RECORD_DATALEN 255
43
39#define TEST_CREATE_RECORD_DATA 'b' 44#define TEST_CREATE_RECORD_DATA 'b'
40 45
41#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 46#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
42 47
48
43static struct GNUNET_NAMESTORE_Handle * nsh; 49static struct GNUNET_NAMESTORE_Handle * nsh;
44 50
45static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; 51static GNUNET_SCHEDULER_TaskIdentifier endbadly_task;
46static struct GNUNET_OS_Process *arm;
47 52
48static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; 53static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
54
49static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; 55static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
50struct GNUNET_CRYPTO_RsaSignature *s_signature; 56
51struct GNUNET_CRYPTO_RsaSignature *s_signature_updated; 57static struct GNUNET_CRYPTO_RsaSignature *s_signature;
58
52static struct GNUNET_CRYPTO_ShortHashCode s_zone; 59static struct GNUNET_CRYPTO_ShortHashCode s_zone;
53struct GNUNET_NAMESTORE_RecordData *s_first_record;
54struct GNUNET_NAMESTORE_RecordData *s_second_record;
55static char *s_name;
56 60
61static struct GNUNET_NAMESTORE_RecordData *s_first_record;
57 62
63static struct GNUNET_NAMESTORE_RecordData *s_second_record;
58 64
59static int res; 65static char *s_name;
60 66
61static void 67static int res;
62start_arm (const char *cfgname)
63{
64 arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
65 "gnunet-service-arm", "-c", cfgname,
66#if VERBOSE_PEERS
67 "-L", "DEBUG",
68#else
69 "-L", "ERROR",
70#endif
71 NULL);
72}
73 68
74static void
75stop_arm ()
76{
77 if (NULL != arm)
78 {
79 if (0 != GNUNET_OS_process_kill (arm, SIGTERM))
80 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
81 GNUNET_OS_process_wait (arm);
82 GNUNET_OS_process_destroy (arm);
83 arm = NULL;
84 }
85}
86 69
87/** 70/**
88 * Re-establish the connection to the service. 71 * Re-establish the connection to the service.
@@ -96,14 +79,9 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
96 if (nsh != NULL) 79 if (nsh != NULL)
97 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); 80 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
98 nsh = NULL; 81 nsh = NULL;
99
100 if (privkey != NULL) 82 if (privkey != NULL)
101 GNUNET_CRYPTO_rsa_key_free (privkey); 83 GNUNET_CRYPTO_rsa_key_free (privkey);
102 privkey = NULL; 84 privkey = NULL;
103
104 if (NULL != arm)
105 stop_arm();
106
107 res = 1; 85 res = 1;
108} 86}
109 87
@@ -116,208 +94,19 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
116 GNUNET_SCHEDULER_cancel (endbadly_task); 94 GNUNET_SCHEDULER_cancel (endbadly_task);
117 endbadly_task = GNUNET_SCHEDULER_NO_TASK; 95 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
118 } 96 }
119
120 GNUNET_free ((void *) s_first_record->data); 97 GNUNET_free ((void *) s_first_record->data);
121 GNUNET_free (s_first_record); 98 GNUNET_free (s_first_record);
122 GNUNET_free_non_null (s_second_record); 99 GNUNET_free_non_null (s_second_record);
123
124 if (privkey != NULL) 100 if (privkey != NULL)
125 GNUNET_CRYPTO_rsa_key_free (privkey); 101 GNUNET_CRYPTO_rsa_key_free (privkey);
126 privkey = NULL; 102 privkey = NULL;
127
128 if (nsh != NULL) 103 if (nsh != NULL)
129 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); 104 GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES);
130 nsh = NULL; 105 nsh = NULL;
131
132 if (NULL != arm)
133 stop_arm();
134} 106}
135 107
136void name_lookup_second_proc (void *cls,
137 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
138 struct GNUNET_TIME_Absolute expire,
139 const char *n,
140 unsigned int rd_count,
141 const struct GNUNET_NAMESTORE_RecordData *rd,
142 const struct GNUNET_CRYPTO_RsaSignature *signature)
143{
144 static int found = GNUNET_NO;
145 int failed = GNUNET_NO;
146 int c;
147
148 if (n != NULL)
149 {
150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking returned results\n");
151 if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
152 {
153 GNUNET_break (0);
154 failed = GNUNET_YES;
155 }
156
157 if (0 != strcmp(n, s_name))
158 {
159 GNUNET_break (0);
160 failed = GNUNET_YES;
161 }
162
163 if (2 != rd_count)
164 {
165 GNUNET_break (0);
166 failed = GNUNET_YES;
167 }
168
169 for (c = 0; c < rd_count; c++)
170 {
171 if ((GNUNET_NO == GNUNET_NAMESTORE_records_cmp(&rd[c], s_first_record)) &&
172 (GNUNET_NO == GNUNET_NAMESTORE_records_cmp(&rd[c], s_second_record)))
173 {
174 GNUNET_break (0);
175 failed = GNUNET_YES;
176 }
177 }
178
179 if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature(&pubkey, expire, n, rd_count, rd, signature))
180 {
181 GNUNET_break (0);
182 failed = GNUNET_YES;
183 }
184
185 struct GNUNET_NAMESTORE_RecordData rd_new[2];
186 rd_new[0] = *s_first_record;
187 rd_new[1] = *s_second_record;
188 s_signature_updated = GNUNET_NAMESTORE_create_signature(privkey, expire, s_name, rd_new, 2);
189
190 if (0 != memcmp (s_signature_updated, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
191 {
192 GNUNET_break (0);
193 failed = GNUNET_YES;
194 }
195
196 found = GNUNET_YES;
197 if (failed == GNUNET_NO)
198 res = 0;
199 else
200 res = 1;
201 }
202 else
203 {
204 if (found != GNUNET_YES)
205 {
206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to lookup records for name `%s'\n", s_name);
207 res = 1;
208 }
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup done for name %s'\n", s_name);
210 }
211 GNUNET_SCHEDULER_add_now(&end, NULL);
212}
213
214
215void
216create_second_cont (void *cls, int32_t success, const char *emsg)
217{
218 char *name = cls;
219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create second record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
220 if (success == GNUNET_OK)
221 {
222 res = 0;
223 GNUNET_NAMESTORE_lookup_record (nsh, &s_zone, name, 0, &name_lookup_second_proc, name);
224 }
225 else
226 {
227 res = 1;
228 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name);
229 GNUNET_SCHEDULER_add_now(&end, NULL);
230 }
231 108
232} 109static void
233
234void name_lookup_initial_proc (void *cls,
235 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
236 struct GNUNET_TIME_Absolute expire,
237 const char *n,
238 unsigned int rd_count,
239 const struct GNUNET_NAMESTORE_RecordData *rd,
240 const struct GNUNET_CRYPTO_RsaSignature *signature)
241{
242 char * name = cls;
243 static int found = GNUNET_NO;
244 int failed = GNUNET_NO;
245 int c;
246
247 if (n != NULL)
248 {
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking returned results\n");
250 if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
251 {
252 GNUNET_break (0);
253 failed = GNUNET_YES;
254 }
255
256 if (0 != strcmp(n, s_name))
257 {
258 GNUNET_break (0);
259 failed = GNUNET_YES;
260 }
261
262 if (RECORDS != rd_count)
263 {
264 GNUNET_break (0);
265 failed = GNUNET_YES;
266 }
267
268 for (c = 0; c < RECORDS; c++)
269 {
270 if (GNUNET_NO == GNUNET_NAMESTORE_records_cmp(&rd[c], &s_first_record[c]))
271 {
272 GNUNET_break (0);
273 failed = GNUNET_YES;
274 }
275 }
276
277 if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature(&pubkey, expire, n, rd_count, rd, signature))
278 {
279 GNUNET_break (0);
280 failed = GNUNET_YES;
281 }
282
283 if (0 != memcmp (s_signature, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
284 {
285 GNUNET_break (0);
286 failed = GNUNET_YES;
287 }
288
289 found = GNUNET_YES;
290 if (failed == GNUNET_NO)
291 res = 0;
292 else
293 res = 1;
294
295 /* create a second record */
296 s_second_record = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_RecordData) + TEST_CREATE_RECORD_DATALEN);
297 s_second_record->expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
298 s_second_record->record_type = TEST_CREATE_RECORD_TYPE;
299 s_second_record->flags = GNUNET_NAMESTORE_RF_AUTHORITY;
300 s_second_record->data = &s_second_record[1];
301 s_second_record->data_size = TEST_CREATE_RECORD_DATALEN;
302 memset ((char *) s_second_record->data, TEST_CREATE_RECORD_DATA, TEST_CREATE_RECORD_DATALEN);
303
304 GNUNET_NAMESTORE_record_create (nsh, privkey, name, s_second_record, &create_second_cont, name);
305
306 }
307 else
308 {
309 if (found != GNUNET_YES)
310 {
311 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to lookup records for name `%s'\n", s_name);
312 res = 1;
313 }
314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup done for name %s'\n", s_name);
315 GNUNET_SCHEDULER_add_now (&end, NULL);
316 }
317}
318
319
320void
321create_updated_cont (void *cls, int32_t success, const char *emsg) 110create_updated_cont (void *cls, int32_t success, const char *emsg)
322{ 111{
323 char *name = cls; 112 char *name = cls;
@@ -340,7 +129,8 @@ create_updated_cont (void *cls, int32_t success, const char *emsg)
340 GNUNET_SCHEDULER_add_now(&end, NULL); 129 GNUNET_SCHEDULER_add_now(&end, NULL);
341} 130}
342 131
343void 132
133static void
344create_identical_cont (void *cls, int32_t success, const char *emsg) 134create_identical_cont (void *cls, int32_t success, const char *emsg)
345{ 135{
346 char *name = cls; 136 char *name = cls;
@@ -360,7 +150,8 @@ create_identical_cont (void *cls, int32_t success, const char *emsg)
360 150
361} 151}
362 152
363void 153
154static void
364create_first_cont (void *cls, int32_t success, const char *emsg) 155create_first_cont (void *cls, int32_t success, const char *emsg)
365{ 156{
366 char *name = cls; 157 char *name = cls;
@@ -380,22 +171,6 @@ create_first_cont (void *cls, int32_t success, const char *emsg)
380 171
381} 172}
382 173
383void
384put_cont (void *cls, int32_t success, const char *emsg)
385{
386 char *name = cls;
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s `%s'\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL", emsg);
388 if (success == GNUNET_OK)
389 {
390
391 }
392 else
393 {
394 res = 1;
395 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name);
396 GNUNET_SCHEDULER_add_now(&end, NULL);
397 }
398}
399 174
400static struct GNUNET_NAMESTORE_RecordData * 175static struct GNUNET_NAMESTORE_RecordData *
401create_record (int count) 176create_record (int count)
@@ -416,41 +191,22 @@ create_record (int count)
416 return rd; 191 return rd;
417} 192}
418 193
419void
420delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
421{
422 char *afsdir;
423
424 if (GNUNET_OK ==
425 GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite",
426 "FILENAME", &afsdir))
427 {
428 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
429 if (GNUNET_OK == GNUNET_DISK_file_test (afsdir))
430 if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir))
431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir);
432 GNUNET_free (afsdir);
433 }
434
435}
436 194
437static void 195static void
438run (void *cls, char *const *args, const char *cfgfile, 196run (void *cls,
439 const struct GNUNET_CONFIGURATION_Handle *cfg) 197 const struct GNUNET_CONFIGURATION_Handle *cfg)
440{ 198{
441 delete_existing_db(cfg); 199 size_t rd_ser_len;
200 char *hostkey_file;
442 201
443 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); 202 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL);
444 size_t rd_ser_len;
445 203
446 /* load privat key */ 204 /* load privat key */
447 char *hostkey_file;
448 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 205 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
449 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 206 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
451 privkey = GNUNET_CRYPTO_rsa_key_create_from_file(hostkey_file); 208 privkey = GNUNET_CRYPTO_rsa_key_create_from_file(hostkey_file);
452 GNUNET_free (hostkey_file); 209 GNUNET_free (hostkey_file);
453
454 GNUNET_assert (privkey != NULL); 210 GNUNET_assert (privkey != NULL);
455 /* get public key */ 211 /* get public key */
456 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); 212 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
@@ -469,10 +225,6 @@ run (void *cls, char *const *args, const char *cfgfile,
469 GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); 225 GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone);
470 226
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name, GNUNET_short_h2s (&s_zone)); 227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name: `%s' Zone: `%s' \n", s_name, GNUNET_short_h2s (&s_zone));
472
473 start_arm (cfgfile);
474 GNUNET_assert (arm != NULL);
475
476 nsh = GNUNET_NAMESTORE_connect (cfg); 228 nsh = GNUNET_NAMESTORE_connect (cfg);
477 GNUNET_break (NULL != nsh); 229 GNUNET_break (NULL != nsh);
478 230
@@ -483,35 +235,20 @@ run (void *cls, char *const *args, const char *cfgfile,
483 GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record, &create_first_cont, s_name); 235 GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record, &create_first_cont, s_name);
484} 236}
485 237
486static int
487check ()
488{
489 static char *const argv[] = { "test-namestore-api",
490 "-c",
491 "test_namestore_api.conf",
492#if VERBOSE
493 "-L", "DEBUG",
494#endif
495 NULL
496 };
497 static struct GNUNET_GETOPT_CommandLineOption options[] = {
498 GNUNET_GETOPT_OPTION_END
499 };
500
501 res = 1;
502 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-namestore-api",
503 "nohelp", options, &run, &res);
504 return res;
505}
506 238
507int 239int
508main (int argc, char *argv[]) 240main (int argc, char *argv[])
509{ 241{
510 int ret; 242 res = 1;
511 243 if (0 !=
512 ret = check (); 244 GNUNET_TESTING_service_run ("test-namestore-api-create-update",
513 GNUNET_free (s_signature); 245 "namestore",
514 return ret; 246 "test_namestore_api.conf",
247 &run,
248 NULL))
249 return 1;
250 GNUNET_free_non_null (s_signature);
251 return res;
515} 252}
516 253
517/* end of test_namestore_api.c */ 254/* end of test_namestore_api_create_update.c */