diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-04 21:24:26 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-04 21:24:26 +0900 |
commit | 4dec7372157611c36598b610857fb4e546c21a63 (patch) | |
tree | e2a92677ea6d4012107e4ad5abe4df595ee67403 | |
parent | d1c5194efcb7d470de3c537e860cfd2956e0d6ea (diff) | |
download | gnunet-4dec7372157611c36598b610857fb4e546c21a63.tar.gz gnunet-4dec7372157611c36598b610857fb4e546c21a63.zip |
-theses are not namestore tests, but GNS tests
-rw-r--r-- | src/namestore/Makefile.am | 43 | ||||
-rw-r--r-- | src/namestore/test_namestore_api_lookup_shadow.c | 288 | ||||
-rw-r--r-- | src/namestore/test_namestore_api_lookup_shadow_filter.c | 371 |
3 files changed, 0 insertions, 702 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index bfe4c6e22..d29d5b6d2 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -27,8 +27,6 @@ SQLITE_TESTS = test_plugin_namestore_sqlite \ | |||
27 | test_namestore_api_monitoring_sqlite \ | 27 | test_namestore_api_monitoring_sqlite \ |
28 | test_namestore_api_lookup_public_sqlite \ | 28 | test_namestore_api_lookup_public_sqlite \ |
29 | test_namestore_api_lookup_private_sqlite \ | 29 | test_namestore_api_lookup_private_sqlite \ |
30 | test_namestore_api_lookup_shadow_sqlite \ | ||
31 | test_namestore_api_lookup_shadow_filter_sqlite \ | ||
32 | test_namestore_api_remove_not_existing_record_sqlite \ | 30 | test_namestore_api_remove_not_existing_record_sqlite \ |
33 | test_namestore_api_zone_iteration_nick_sqlite \ | 31 | test_namestore_api_zone_iteration_nick_sqlite \ |
34 | test_namestore_api_zone_iteration_specific_zone_sqlite \ | 32 | test_namestore_api_zone_iteration_specific_zone_sqlite \ |
@@ -53,8 +51,6 @@ POSTGRES_TESTS = test_plugin_namestore_postgres \ | |||
53 | test_namestore_api_monitoring_postgres \ | 51 | test_namestore_api_monitoring_postgres \ |
54 | test_namestore_api_lookup_public_postgres \ | 52 | test_namestore_api_lookup_public_postgres \ |
55 | test_namestore_api_lookup_private_postgres \ | 53 | test_namestore_api_lookup_private_postgres \ |
56 | test_namestore_api_lookup_shadow_postgres \ | ||
57 | test_namestore_api_lookup_shadow_filter_postgres \ | ||
58 | test_namestore_api_remove_not_existing_record_postgres \ | 54 | test_namestore_api_remove_not_existing_record_postgres \ |
59 | test_namestore_api_zone_iteration_nick_postgres \ | 55 | test_namestore_api_zone_iteration_nick_postgres \ |
60 | test_namestore_api_zone_iteration_specific_zone_postgres \ | 56 | test_namestore_api_zone_iteration_specific_zone_postgres \ |
@@ -313,45 +309,6 @@ test_namestore_api_lookup_private_postgres_LDADD = \ | |||
313 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | 309 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ |
314 | libgnunetnamestore.la | 310 | libgnunetnamestore.la |
315 | 311 | ||
316 | test_namestore_api_lookup_shadow_sqlite_SOURCES = \ | ||
317 | test_namestore_api_lookup_shadow.c | ||
318 | test_namestore_api_lookup_shadow_sqlite_LDADD = \ | ||
319 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
320 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
321 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
322 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
323 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | ||
324 | libgnunetnamestore.la | ||
325 | |||
326 | test_namestore_api_lookup_shadow_postgres_SOURCES = \ | ||
327 | test_namestore_api_lookup_shadow.c | ||
328 | test_namestore_api_lookup_shadow_postgres_LDADD = \ | ||
329 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
330 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
331 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
332 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
333 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | ||
334 | libgnunetnamestore.la | ||
335 | |||
336 | test_namestore_api_lookup_shadow_filter_sqlite_SOURCES = \ | ||
337 | test_namestore_api_lookup_shadow_filter.c | ||
338 | test_namestore_api_lookup_shadow_filter_sqlite_LDADD = \ | ||
339 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
340 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
341 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
342 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
343 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | ||
344 | libgnunetnamestore.la | ||
345 | test_namestore_api_lookup_shadow_filter_postgres_SOURCES = \ | ||
346 | test_namestore_api_lookup_shadow_filter.c | ||
347 | test_namestore_api_lookup_shadow_filter_postgres_LDADD = \ | ||
348 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
349 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
350 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
351 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
352 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | ||
353 | libgnunetnamestore.la | ||
354 | |||
355 | test_namestore_api_remove_sqlite_SOURCES = \ | 312 | test_namestore_api_remove_sqlite_SOURCES = \ |
356 | test_namestore_api_remove.c | 313 | test_namestore_api_remove.c |
357 | test_namestore_api_remove_sqlite_LDADD = \ | 314 | test_namestore_api_remove_sqlite_LDADD = \ |
diff --git a/src/namestore/test_namestore_api_lookup_shadow.c b/src/namestore/test_namestore_api_lookup_shadow.c deleted file mode 100644 index 8f47d1280..000000000 --- a/src/namestore/test_namestore_api_lookup_shadow.c +++ /dev/null | |||
@@ -1,288 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2012 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file namestore/test_namestore_api_lookup_shadow.c | ||
22 | * @brief testcase for namestore_api.c: store a shadow record and perform a lookup | ||
23 | * test passes if test returns the record but without the shadow flag since no | ||
24 | * other valid record is available | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_namecache_service.h" | ||
28 | #include "gnunet_namestore_service.h" | ||
29 | #include "gnunet_testing_lib.h" | ||
30 | #include "gnunet_dnsparser_lib.h" | ||
31 | |||
32 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT | ||
33 | |||
34 | #define TEST_RECORD_DATALEN 123 | ||
35 | |||
36 | #define TEST_RECORD_DATA 'a' | ||
37 | |||
38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) | ||
39 | |||
40 | |||
41 | static struct GNUNET_NAMESTORE_Handle *nsh; | ||
42 | |||
43 | static struct GNUNET_NAMECACHE_Handle *nch; | ||
44 | |||
45 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | ||
46 | |||
47 | static struct GNUNET_IDENTITY_PrivateKey privkey; | ||
48 | |||
49 | static struct GNUNET_IDENTITY_PublicKey pubkey; | ||
50 | |||
51 | static int res; | ||
52 | |||
53 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | ||
54 | |||
55 | static struct GNUNET_NAMECACHE_QueueEntry *ncqe; | ||
56 | |||
57 | |||
58 | static void | ||
59 | cleanup () | ||
60 | { | ||
61 | if (NULL != nsh) | ||
62 | { | ||
63 | GNUNET_NAMESTORE_disconnect (nsh); | ||
64 | nsh = NULL; | ||
65 | } | ||
66 | if (NULL != nch) | ||
67 | { | ||
68 | GNUNET_NAMECACHE_disconnect (nch); | ||
69 | nch = NULL; | ||
70 | } | ||
71 | GNUNET_SCHEDULER_shutdown (); | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Re-establish the connection to the service. | ||
77 | * | ||
78 | * @param cls handle to use to re-connect. | ||
79 | */ | ||
80 | static void | ||
81 | endbadly (void *cls) | ||
82 | { | ||
83 | if (NULL != nsqe) | ||
84 | { | ||
85 | GNUNET_NAMESTORE_cancel (nsqe); | ||
86 | nsqe = NULL; | ||
87 | } | ||
88 | if (NULL != ncqe) | ||
89 | { | ||
90 | GNUNET_NAMECACHE_cancel (ncqe); | ||
91 | ncqe = NULL; | ||
92 | } | ||
93 | cleanup (); | ||
94 | res = 1; | ||
95 | } | ||
96 | |||
97 | |||
98 | static void | ||
99 | end (void *cls) | ||
100 | { | ||
101 | cleanup (); | ||
102 | res = 0; | ||
103 | } | ||
104 | |||
105 | |||
106 | static void | ||
107 | rd_decrypt_cb (void *cls, | ||
108 | unsigned int rd_count, | ||
109 | const struct GNUNET_GNSRECORD_Data *rd) | ||
110 | { | ||
111 | char rd_cmp_data[TEST_RECORD_DATALEN]; | ||
112 | |||
113 | if (1 != rd_count) | ||
114 | { | ||
115 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
116 | GNUNET_break (0); | ||
117 | return; | ||
118 | } | ||
119 | if (NULL == rd) | ||
120 | { | ||
121 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
122 | GNUNET_break (0); | ||
123 | return; | ||
124 | } | ||
125 | memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN); | ||
126 | |||
127 | if (TEST_RECORD_TYPE != rd[0].record_type) | ||
128 | { | ||
129 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
130 | GNUNET_break (0); | ||
131 | return; | ||
132 | } | ||
133 | if (TEST_RECORD_DATALEN != rd[0].data_size) | ||
134 | { | ||
135 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
136 | GNUNET_break (0); | ||
137 | return; | ||
138 | } | ||
139 | if (0 != memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)) | ||
140 | { | ||
141 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
142 | GNUNET_break (0); | ||
143 | return; | ||
144 | } | ||
145 | if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags)) | ||
146 | { | ||
147 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
148 | GNUNET_break (0); | ||
149 | return; | ||
150 | } | ||
151 | |||
152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
153 | "Block was decrypted successfully \n"); | ||
154 | |||
155 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
156 | } | ||
157 | |||
158 | |||
159 | static void | ||
160 | name_lookup_proc (void *cls, | ||
161 | const struct GNUNET_GNSRECORD_Block *block) | ||
162 | { | ||
163 | const char *name = cls; | ||
164 | |||
165 | ncqe = NULL; | ||
166 | GNUNET_assert (NULL != cls); | ||
167 | |||
168 | if (endbadly_task != NULL) | ||
169 | { | ||
170 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
171 | endbadly_task = NULL; | ||
172 | } | ||
173 | |||
174 | if (NULL == block) | ||
175 | { | ||
176 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
177 | _ ("Namestore returned no block\n")); | ||
178 | if (endbadly_task != NULL) | ||
179 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
180 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
181 | return; | ||
182 | } | ||
183 | |||
184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
185 | "Namestore returned block, decrypting \n"); | ||
186 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt (block, | ||
187 | &pubkey, name, | ||
188 | &rd_decrypt_cb, | ||
189 | (void *) name)); | ||
190 | } | ||
191 | |||
192 | |||
193 | static void | ||
194 | put_cont (void *cls, int32_t success, const char *emsg) | ||
195 | { | ||
196 | const char *name = cls; | ||
197 | struct GNUNET_HashCode derived_hash; | ||
198 | struct GNUNET_IDENTITY_PublicKey pubkey; | ||
199 | |||
200 | nsqe = NULL; | ||
201 | GNUNET_assert (NULL != cls); | ||
202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
203 | "Name store added record for `%s': %s\n", | ||
204 | name, | ||
205 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | ||
206 | |||
207 | /* Create derived hash */ | ||
208 | GNUNET_IDENTITY_key_get_public (&privkey, | ||
209 | &pubkey); | ||
210 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, | ||
211 | name, | ||
212 | &derived_hash); | ||
213 | |||
214 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, | ||
215 | &derived_hash, | ||
216 | &name_lookup_proc, (void *) name); | ||
217 | } | ||
218 | |||
219 | |||
220 | static void | ||
221 | run (void *cls, | ||
222 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
223 | struct GNUNET_TESTING_Peer *peer) | ||
224 | { | ||
225 | struct GNUNET_GNSRECORD_Data rd; | ||
226 | const char *name = "dummy"; | ||
227 | |||
228 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
229 | &endbadly, | ||
230 | NULL); | ||
231 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
232 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); | ||
233 | GNUNET_IDENTITY_key_get_public (&privkey, | ||
234 | &pubkey); | ||
235 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; | ||
236 | rd.record_type = TEST_RECORD_TYPE; | ||
237 | rd.data_size = TEST_RECORD_DATALEN; | ||
238 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); | ||
239 | rd.flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD; | ||
240 | memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); | ||
241 | |||
242 | nsh = GNUNET_NAMESTORE_connect (cfg); | ||
243 | nch = GNUNET_NAMECACHE_connect (cfg); | ||
244 | GNUNET_break (NULL != nsh); | ||
245 | GNUNET_break (NULL != nch); | ||
246 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | ||
247 | &privkey, | ||
248 | name, | ||
249 | 1, | ||
250 | &rd, | ||
251 | &put_cont, | ||
252 | (void *) name); | ||
253 | if (NULL == nsqe) | ||
254 | { | ||
255 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
256 | _ ("Namestore cannot store no block\n")); | ||
257 | } | ||
258 | GNUNET_free_nz ((void *) rd.data); | ||
259 | } | ||
260 | |||
261 | |||
262 | #include "test_common.c" | ||
263 | |||
264 | |||
265 | int | ||
266 | main (int argc, char *argv[]) | ||
267 | { | ||
268 | const char *plugin_name; | ||
269 | char *cfg_name; | ||
270 | |||
271 | SETUP_CFG (plugin_name, cfg_name); | ||
272 | res = 1; | ||
273 | if (0 != | ||
274 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow", | ||
275 | cfg_name, | ||
276 | &run, | ||
277 | NULL)) | ||
278 | { | ||
279 | res = 1; | ||
280 | } | ||
281 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
282 | "GNUNET_TEST_HOME"); | ||
283 | GNUNET_free (cfg_name); | ||
284 | return res; | ||
285 | } | ||
286 | |||
287 | |||
288 | /* end of test_namestore_api_lookup_shadow.c */ | ||
diff --git a/src/namestore/test_namestore_api_lookup_shadow_filter.c b/src/namestore/test_namestore_api_lookup_shadow_filter.c deleted file mode 100644 index 0bcd130f9..000000000 --- a/src/namestore/test_namestore_api_lookup_shadow_filter.c +++ /dev/null | |||
@@ -1,371 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2012 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file namestore/test_namestore_api_lookup_shadow_filter.c | ||
22 | * @brief testcase for namestore_api.c: store a record with short expiration | ||
23 | * and a shadow record, perform lookup: | ||
24 | * - when active record is valid, expect only active record | ||
25 | * - when active record is expired, expect shadow record only | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_namecache_service.h" | ||
29 | #include "gnunet_namestore_service.h" | ||
30 | #include "gnunet_testing_lib.h" | ||
31 | #include "gnunet_dnsparser_lib.h" | ||
32 | |||
33 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT | ||
34 | |||
35 | #define TEST_NAME "gnunet" | ||
36 | #define TEST_RECORD_DATALEN 123 | ||
37 | #define TEST_RECORD_DATA 'a' | ||
38 | #define TEST_SHADOW_RECORD_DATA 'b' | ||
39 | |||
40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) | ||
41 | #define EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
42 | |||
43 | static struct GNUNET_NAMESTORE_Handle *nsh; | ||
44 | |||
45 | static struct GNUNET_NAMECACHE_Handle *nch; | ||
46 | |||
47 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | ||
48 | |||
49 | static struct GNUNET_SCHEDULER_Task *delayed_lookup_task; | ||
50 | |||
51 | static struct GNUNET_IDENTITY_PrivateKey privkey; | ||
52 | |||
53 | static struct GNUNET_IDENTITY_PublicKey pubkey; | ||
54 | |||
55 | static int res; | ||
56 | |||
57 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | ||
58 | |||
59 | static struct GNUNET_NAMECACHE_QueueEntry *ncqe; | ||
60 | |||
61 | static struct GNUNET_NAMECACHE_QueueEntry *ncqe_shadow; | ||
62 | |||
63 | static struct GNUNET_GNSRECORD_Data records[2]; | ||
64 | |||
65 | static struct GNUNET_TIME_Absolute record_expiration; | ||
66 | |||
67 | static struct GNUNET_HashCode derived_hash; | ||
68 | |||
69 | static struct GNUNET_IDENTITY_PublicKey pubkey; | ||
70 | |||
71 | |||
72 | static void | ||
73 | cleanup () | ||
74 | { | ||
75 | if (NULL != nsh) | ||
76 | { | ||
77 | GNUNET_NAMESTORE_disconnect (nsh); | ||
78 | nsh = NULL; | ||
79 | } | ||
80 | if (NULL != nch) | ||
81 | { | ||
82 | GNUNET_NAMECACHE_disconnect (nch); | ||
83 | nch = NULL; | ||
84 | } | ||
85 | GNUNET_SCHEDULER_shutdown (); | ||
86 | } | ||
87 | |||
88 | |||
89 | /** | ||
90 | * Re-establish the connection to the service. | ||
91 | * | ||
92 | * @param cls handle to use to re-connect. | ||
93 | */ | ||
94 | static void | ||
95 | endbadly (void *cls) | ||
96 | { | ||
97 | if (NULL != delayed_lookup_task) | ||
98 | { | ||
99 | GNUNET_SCHEDULER_cancel (delayed_lookup_task); | ||
100 | delayed_lookup_task = NULL; | ||
101 | } | ||
102 | if (NULL != nsqe) | ||
103 | { | ||
104 | GNUNET_NAMESTORE_cancel (nsqe); | ||
105 | nsqe = NULL; | ||
106 | } | ||
107 | if (NULL != ncqe) | ||
108 | { | ||
109 | GNUNET_NAMECACHE_cancel (ncqe); | ||
110 | ncqe = NULL; | ||
111 | } | ||
112 | cleanup (); | ||
113 | res = 1; | ||
114 | } | ||
115 | |||
116 | |||
117 | static void | ||
118 | end (void *cls) | ||
119 | { | ||
120 | cleanup (); | ||
121 | res = 0; | ||
122 | } | ||
123 | |||
124 | |||
125 | static void | ||
126 | rd_decrypt_cb (void *cls, | ||
127 | unsigned int rd_count, | ||
128 | const struct GNUNET_GNSRECORD_Data *rd) | ||
129 | { | ||
130 | struct GNUNET_GNSRECORD_Data *expected_rd = cls; | ||
131 | char rd_cmp_data[TEST_RECORD_DATALEN]; | ||
132 | |||
133 | if (1 != rd_count) | ||
134 | { | ||
135 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
136 | GNUNET_break (0); | ||
137 | return; | ||
138 | } | ||
139 | if (NULL == rd) | ||
140 | { | ||
141 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
142 | GNUNET_break (0); | ||
143 | return; | ||
144 | } | ||
145 | if (expected_rd == &records[0]) | ||
146 | { | ||
147 | /* Expecting active record */ | ||
148 | memset (rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | ||
149 | if (TEST_RECORD_TYPE != rd[0].record_type) | ||
150 | { | ||
151 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
152 | GNUNET_break (0); | ||
153 | return; | ||
154 | } | ||
155 | if (TEST_RECORD_DATALEN != rd[0].data_size) | ||
156 | { | ||
157 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
158 | GNUNET_break (0); | ||
159 | return; | ||
160 | } | ||
161 | if (0 != memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)) | ||
162 | { | ||
163 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
164 | GNUNET_break (0); | ||
165 | return; | ||
166 | } | ||
167 | if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags)) | ||
168 | { | ||
169 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
170 | GNUNET_break (0); | ||
171 | return; | ||
172 | } | ||
173 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
174 | "Block was decrypted successfully with active record\n"); | ||
175 | } | ||
176 | if (expected_rd == &records[1]) | ||
177 | { | ||
178 | /* Expecting shadow record but without shadow flag*/ | ||
179 | memset (rd_cmp_data, TEST_SHADOW_RECORD_DATA, TEST_RECORD_DATALEN); | ||
180 | if (TEST_RECORD_TYPE != rd[0].record_type) | ||
181 | { | ||
182 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
183 | GNUNET_break (0); | ||
184 | return; | ||
185 | } | ||
186 | if (TEST_RECORD_DATALEN != rd[0].data_size) | ||
187 | { | ||
188 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
189 | GNUNET_break (0); | ||
190 | return; | ||
191 | } | ||
192 | if (0 != memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)) | ||
193 | { | ||
194 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
195 | GNUNET_break (0); | ||
196 | return; | ||
197 | } | ||
198 | if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags)) | ||
199 | { | ||
200 | GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
201 | GNUNET_break (0); | ||
202 | return; | ||
203 | } | ||
204 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
205 | "Block was decrypted successfully with former shadow record \n"); | ||
206 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
207 | } | ||
208 | } | ||
209 | |||
210 | |||
211 | static void | ||
212 | name_lookup_active_proc (void *cls, | ||
213 | const struct GNUNET_GNSRECORD_Block *block) | ||
214 | { | ||
215 | struct GNUNET_GNSRECORD_Data *expected_rd = cls; | ||
216 | |||
217 | GNUNET_assert (NULL != expected_rd); | ||
218 | |||
219 | ncqe = NULL; | ||
220 | ncqe_shadow = NULL; | ||
221 | if (endbadly_task != NULL) | ||
222 | { | ||
223 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
224 | endbadly_task = NULL; | ||
225 | } | ||
226 | |||
227 | if (NULL == block) | ||
228 | { | ||
229 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
230 | _ ("Namestore returned no block\n")); | ||
231 | if (endbadly_task != NULL) | ||
232 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
233 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
234 | return; | ||
235 | } | ||
236 | |||
237 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
238 | "Namestore returned block, decrypting \n"); | ||
239 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt (block, | ||
240 | &pubkey, | ||
241 | TEST_NAME, | ||
242 | &rd_decrypt_cb, | ||
243 | expected_rd)); | ||
244 | } | ||
245 | |||
246 | |||
247 | static void | ||
248 | name_lookup_shadow (void *cls) | ||
249 | { | ||
250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
251 | "Performing lookup for shadow record \n"); | ||
252 | delayed_lookup_task = NULL; | ||
253 | ncqe_shadow = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, | ||
254 | &name_lookup_active_proc, | ||
255 | &records[1]); | ||
256 | } | ||
257 | |||
258 | |||
259 | static void | ||
260 | put_cont (void *cls, int32_t success, const char *emsg) | ||
261 | { | ||
262 | nsqe = NULL; | ||
263 | |||
264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
265 | "Name store added record for `%s': %s\n", | ||
266 | TEST_NAME, | ||
267 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | ||
268 | |||
269 | /* Create derived hash */ | ||
270 | GNUNET_IDENTITY_key_get_public (&privkey, | ||
271 | &pubkey); | ||
272 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, TEST_NAME, &derived_hash); | ||
273 | |||
274 | if (0 == GNUNET_TIME_absolute_get_remaining (record_expiration).rel_value_us) | ||
275 | { | ||
276 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
277 | "Test to too long to store records, cannot run test!\n"); | ||
278 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
279 | return; | ||
280 | } | ||
281 | /* Lookup active record now */ | ||
282 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
283 | "Performing lookup for active record \n"); | ||
284 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, | ||
285 | &name_lookup_active_proc, &records[0]); | ||
286 | |||
287 | delayed_lookup_task = GNUNET_SCHEDULER_add_delayed ( | ||
288 | GNUNET_TIME_relative_multiply (EXPIRATION, 2), &name_lookup_shadow, NULL); | ||
289 | } | ||
290 | |||
291 | |||
292 | static void | ||
293 | run (void *cls, | ||
294 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
295 | struct GNUNET_TESTING_Peer *peer) | ||
296 | { | ||
297 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
298 | &endbadly, | ||
299 | NULL); | ||
300 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
301 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); | ||
302 | GNUNET_IDENTITY_key_get_public (&privkey, | ||
303 | &pubkey); | ||
304 | |||
305 | record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), | ||
306 | EXPIRATION); | ||
307 | records[0].expiration_time = record_expiration.abs_value_us; | ||
308 | records[0].record_type = TEST_RECORD_TYPE; | ||
309 | records[0].data_size = TEST_RECORD_DATALEN; | ||
310 | records[0].data = GNUNET_malloc (TEST_RECORD_DATALEN); | ||
311 | records[0].flags = GNUNET_GNSRECORD_RF_NONE; | ||
312 | memset ((char *) records[0].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | ||
313 | |||
314 | records[1].expiration_time = GNUNET_TIME_absolute_get ().abs_value_us | ||
315 | + 1000000000; | ||
316 | records[1].record_type = TEST_RECORD_TYPE; | ||
317 | records[1].data_size = TEST_RECORD_DATALEN; | ||
318 | records[1].data = GNUNET_malloc (TEST_RECORD_DATALEN); | ||
319 | records[1].flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD; | ||
320 | memset ((char *) records[1].data, TEST_SHADOW_RECORD_DATA, | ||
321 | TEST_RECORD_DATALEN); | ||
322 | |||
323 | nsh = GNUNET_NAMESTORE_connect (cfg); | ||
324 | nch = GNUNET_NAMECACHE_connect (cfg); | ||
325 | GNUNET_break (NULL != nsh); | ||
326 | GNUNET_break (NULL != nch); | ||
327 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | ||
328 | &privkey, | ||
329 | TEST_NAME, | ||
330 | 2, | ||
331 | records, | ||
332 | &put_cont, | ||
333 | NULL); | ||
334 | if (NULL == nsqe) | ||
335 | { | ||
336 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
337 | _ ("Namestore cannot store no block\n")); | ||
338 | } | ||
339 | |||
340 | GNUNET_free_nz ((void *) records[0].data); | ||
341 | GNUNET_free_nz ((void *) records[1].data); | ||
342 | } | ||
343 | |||
344 | |||
345 | #include "test_common.c" | ||
346 | |||
347 | |||
348 | int | ||
349 | main (int argc, char *argv[]) | ||
350 | { | ||
351 | const char *plugin_name; | ||
352 | char *cfg_name; | ||
353 | |||
354 | SETUP_CFG (plugin_name, cfg_name); | ||
355 | res = 1; | ||
356 | if (0 != | ||
357 | GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow-filter", | ||
358 | cfg_name, | ||
359 | &run, | ||
360 | NULL)) | ||
361 | { | ||
362 | res = 1; | ||
363 | } | ||
364 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
365 | "GNUNET_TEST_HOME"); | ||
366 | GNUNET_free (cfg_name); | ||
367 | return res; | ||
368 | } | ||
369 | |||
370 | |||
371 | /* end of test_namestore_api_lookup_shadow_filter.c */ | ||