summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/helpers.h3
-rw-r--r--auto_tests/onion_test.c56
2 files changed, 34 insertions, 25 deletions
diff --git a/auto_tests/helpers.h b/auto_tests/helpers.h
index 20085d6e..745c5d22 100644
--- a/auto_tests/helpers.h
+++ b/auto_tests/helpers.h
@@ -51,8 +51,7 @@ static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *path, uint3
51 return; 51 return;
52 } 52 }
53 53
54 if (strncmp(message, "Bound successfully to ", strlen("Bound successfully to ")) || 54 if (strncmp(message, "Bound successfully to ", strlen("Bound successfully to "))) {
55 strncmp(message, "Found node in LAN: ", strlen("Found node in LAN: "))) {
56 return; 55 return;
57 } 56 }
58 57
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c
index 28fcbb40..7db683de 100644
--- a/auto_tests/onion_test.c
+++ b/auto_tests/onion_test.c
@@ -102,7 +102,8 @@ static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, ui
102#if 0 102#if 0
103 print_client_id(packet, length); 103 print_client_id(packet, length);
104#endif 104#endif
105 int len = decrypt_data(test_3_pub_key, onion->dht->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, 105 int len = decrypt_data(test_3_pub_key, dht_get_self_secret_key(onion->dht),
106 packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH,
106 packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE, 107 packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE,
107 1 + CRYPTO_SHA256_SIZE + CRYPTO_MAC_SIZE, plain); 108 1 + CRYPTO_SHA256_SIZE + CRYPTO_MAC_SIZE, plain);
108 109
@@ -140,7 +141,7 @@ static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, ui
140 return 1; 141 return 1;
141 } 142 }
142 143
143 int len = decrypt_data(packet + 1 + CRYPTO_NONCE_SIZE, onion->dht->self_secret_key, packet + 1, 144 int len = decrypt_data(packet + 1 + CRYPTO_NONCE_SIZE, dht_get_self_secret_key(onion->dht), packet + 1,
144 packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, sizeof("Install gentoo") + CRYPTO_MAC_SIZE, plain); 145 packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, sizeof("Install gentoo") + CRYPTO_MAC_SIZE, plain);
145 146
146 if (len == -1) { 147 if (len == -1) {
@@ -165,12 +166,12 @@ START_TEST(test_basic)
165 166
166 IP_Port on1 = {ip, net_port(onion1->net)}; 167 IP_Port on1 = {ip, net_port(onion1->net)};
167 Node_format n1; 168 Node_format n1;
168 memcpy(n1.public_key, onion1->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); 169 memcpy(n1.public_key, dht_get_self_public_key(onion1->dht), CRYPTO_PUBLIC_KEY_SIZE);
169 n1.ip_port = on1; 170 n1.ip_port = on1;
170 171
171 IP_Port on2 = {ip, net_port(onion2->net)}; 172 IP_Port on2 = {ip, net_port(onion2->net)};
172 Node_format n2; 173 Node_format n2;
173 memcpy(n2.public_key, onion2->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); 174 memcpy(n2.public_key, dht_get_self_public_key(onion2->dht), CRYPTO_PUBLIC_KEY_SIZE);
174 n2.ip_port = on2; 175 n2.ip_port = on2;
175 176
176 Node_format nodes[4]; 177 Node_format nodes[4];
@@ -208,9 +209,12 @@ START_TEST(test_basic)
208 uint64_t s; 209 uint64_t s;
209 memcpy(&s, sb_data, sizeof(uint64_t)); 210 memcpy(&s, sb_data, sizeof(uint64_t));
210 memcpy(test_3_pub_key, nodes[3].public_key, CRYPTO_PUBLIC_KEY_SIZE); 211 memcpy(test_3_pub_key, nodes[3].public_key, CRYPTO_PUBLIC_KEY_SIZE);
211 ret = send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, 212 ret = send_announce_request(onion1->net, &path, nodes[3],
212 onion1->dht->self_secret_key, 213 dht_get_self_public_key(onion1->dht),
213 zeroes, onion1->dht->self_public_key, onion1->dht->self_public_key, s); 214 dht_get_self_secret_key(onion1->dht),
215 zeroes,
216 dht_get_self_public_key(onion1->dht),
217 dht_get_self_public_key(onion1->dht), s);
214 ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet."); 218 ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet.");
215 handled_test_3 = 0; 219 handled_test_3 = 0;
216 220
@@ -222,13 +226,18 @@ START_TEST(test_basic)
222 226
223 random_bytes(sb_data, sizeof(sb_data)); 227 random_bytes(sb_data, sizeof(sb_data));
224 memcpy(&s, sb_data, sizeof(uint64_t)); 228 memcpy(&s, sb_data, sizeof(uint64_t));
225 memcpy(onion_announce_entry_public_key(onion2_a, 1), onion2->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); 229 memcpy(onion_announce_entry_public_key(onion2_a, 1), dht_get_self_public_key(onion2->dht), CRYPTO_PUBLIC_KEY_SIZE);
226 onion_announce_entry_set_time(onion2_a, 1, unix_time()); 230 onion_announce_entry_set_time(onion2_a, 1, unix_time());
227 networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1); 231 networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1);
228 send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, onion1->dht->self_secret_key, 232 send_announce_request(onion1->net, &path, nodes[3],
229 test_3_ping_id, onion1->dht->self_public_key, onion1->dht->self_public_key, s); 233 dht_get_self_public_key(onion1->dht),
230 234 dht_get_self_secret_key(onion1->dht),
231 while (memcmp(onion_announce_entry_public_key(onion2_a, ONION_ANNOUNCE_MAX_ENTRIES - 2), onion1->dht->self_public_key, 235 test_3_ping_id,
236 dht_get_self_public_key(onion1->dht),
237 dht_get_self_public_key(onion1->dht), s);
238
239 while (memcmp(onion_announce_entry_public_key(onion2_a, ONION_ANNOUNCE_MAX_ENTRIES - 2),
240 dht_get_self_public_key(onion1->dht),
232 CRYPTO_PUBLIC_KEY_SIZE) != 0) { 241 CRYPTO_PUBLIC_KEY_SIZE) != 0) {
233 do_onion(onion1); 242 do_onion(onion1);
234 do_onion(onion2); 243 do_onion(onion2);
@@ -240,8 +249,9 @@ START_TEST(test_basic)
240 ck_assert_msg((onion3 != NULL), "Onion failed initializing."); 249 ck_assert_msg((onion3 != NULL), "Onion failed initializing.");
241 250
242 random_nonce(nonce); 251 random_nonce(nonce);
243 ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->self_public_key, 252 ret = send_data_request(onion3->net, &path, nodes[3].ip_port,
244 onion1->dht->self_public_key, 253 dht_get_self_public_key(onion1->dht),
254 dht_get_self_public_key(onion1->dht),
245 nonce, (const uint8_t *)"Install gentoo", sizeof("Install gentoo")); 255 nonce, (const uint8_t *)"Install gentoo", sizeof("Install gentoo"));
246 ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet."); 256 ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet.");
247 handled_test_4 = 0; 257 handled_test_4 = 0;
@@ -258,7 +268,7 @@ START_TEST(test_basic)
258 { 268 {
259 Onion *onion = onion1; 269 Onion *onion = onion1;
260 270
261 Networking_Core *net = onion->dht->net; 271 Networking_Core *net = dht_get_net(onion->dht);
262 DHT *dht = onion->dht; 272 DHT *dht = onion->dht;
263 kill_onion(onion); 273 kill_onion(onion);
264 kill_DHT(dht); 274 kill_DHT(dht);
@@ -268,7 +278,7 @@ START_TEST(test_basic)
268 { 278 {
269 Onion *onion = onion2; 279 Onion *onion = onion2;
270 280
271 Networking_Core *net = onion->dht->net; 281 Networking_Core *net = dht_get_net(onion->dht);
272 DHT *dht = onion->dht; 282 DHT *dht = onion->dht;
273 kill_onion(onion); 283 kill_onion(onion);
274 kill_DHT(dht); 284 kill_DHT(dht);
@@ -278,7 +288,7 @@ START_TEST(test_basic)
278 { 288 {
279 Onion *onion = onion3; 289 Onion *onion = onion3;
280 290
281 Networking_Core *net = onion->dht->net; 291 Networking_Core *net = dht_get_net(onion->dht);
282 DHT *dht = onion->dht; 292 DHT *dht = onion->dht;
283 kill_onion(onion); 293 kill_onion(onion);
284 kill_DHT(dht); 294 kill_DHT(dht);
@@ -361,7 +371,7 @@ static void do_onions(Onions *on)
361 371
362static void kill_onions(Onions *on) 372static void kill_onions(Onions *on)
363{ 373{
364 Networking_Core *net = on->onion->dht->net; 374 Networking_Core *net = dht_get_net(on->onion->dht);
365 DHT *dht = on->onion->dht; 375 DHT *dht = on->onion->dht;
366 Net_Crypto *c = onion_get_net_crypto(on->onion_c); 376 Net_Crypto *c = onion_get_net_crypto(on->onion_c);
367 kill_onion_client(on->onion_c); 377 kill_onion_client(on->onion_c);
@@ -444,11 +454,11 @@ START_TEST(test_announce)
444 454
445 for (i = 3; i < NUM_ONIONS; ++i) { 455 for (i = 3; i < NUM_ONIONS; ++i) {
446 IP_Port ip_port = {ip, net_port(onions[i - 1]->onion->net)}; 456 IP_Port ip_port = {ip, net_port(onions[i - 1]->onion->net)};
447 DHT_bootstrap(onions[i]->onion->dht, ip_port, onions[i - 1]->onion->dht->self_public_key); 457 DHT_bootstrap(onions[i]->onion->dht, ip_port, dht_get_self_public_key(onions[i - 1]->onion->dht));
448 IP_Port ip_port1 = {ip, net_port(onions[i - 2]->onion->net)}; 458 IP_Port ip_port1 = {ip, net_port(onions[i - 2]->onion->net)};
449 DHT_bootstrap(onions[i]->onion->dht, ip_port1, onions[i - 2]->onion->dht->self_public_key); 459 DHT_bootstrap(onions[i]->onion->dht, ip_port1, dht_get_self_public_key(onions[i - 2]->onion->dht));
450 IP_Port ip_port2 = {ip, net_port(onions[i - 3]->onion->net)}; 460 IP_Port ip_port2 = {ip, net_port(onions[i - 3]->onion->net)};
451 DHT_bootstrap(onions[i]->onion->dht, ip_port2, onions[i - 3]->onion->dht->self_public_key); 461 DHT_bootstrap(onions[i]->onion->dht, ip_port2, dht_get_self_public_key(onions[i - 3]->onion->dht));
452 } 462 }
453 463
454 uint32_t connected = 0; 464 uint32_t connected = 0;
@@ -474,8 +484,8 @@ START_TEST(test_announce)
474 c_sleep(50); 484 c_sleep(50);
475 } 485 }
476 486
477 memcpy(first_dht_pk, onions[NUM_FIRST]->onion->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); 487 memcpy(first_dht_pk, dht_get_self_public_key(onions[NUM_FIRST]->onion->dht), CRYPTO_PUBLIC_KEY_SIZE);
478 memcpy(last_dht_pk, onions[NUM_LAST]->onion->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); 488 memcpy(last_dht_pk, dht_get_self_public_key(onions[NUM_LAST]->onion->dht), CRYPTO_PUBLIC_KEY_SIZE);
479 489
480 printf("adding friend\n"); 490 printf("adding friend\n");
481 int frnum_f = onion_addfriend(onions[NUM_FIRST]->onion_c, 491 int frnum_f = onion_addfriend(onions[NUM_FIRST]->onion_c,