diff options
Diffstat (limited to 'auto_tests/onion_test.c')
-rw-r--r-- | auto_tests/onion_test.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 61ba07fa..865a6d33 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -42,12 +42,22 @@ static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, ui | |||
42 | { | 42 | { |
43 | Onion *onion = (Onion *)object; | 43 | Onion *onion = (Onion *)object; |
44 | 44 | ||
45 | if (memcmp(packet, "\x83 Install Gentoo", sizeof("\x83 Install Gentoo")) != 0) { | 45 | const char req_message[] = "Install Gentoo"; |
46 | uint8_t req_packet[1 + sizeof(req_message)]; | ||
47 | req_packet[0] = NET_PACKET_ANNOUNCE_REQUEST; | ||
48 | memcpy(req_packet + 1, req_message, sizeof(req_message)); | ||
49 | |||
50 | if (memcmp(packet, req_packet, sizeof(req_packet)) != 0) { | ||
46 | return 1; | 51 | return 1; |
47 | } | 52 | } |
48 | 53 | ||
49 | if (send_onion_response(onion->net, source, (const uint8_t *)"\x84 install gentoo", sizeof("\x84 install gentoo"), | 54 | const char res_message[] = "install gentoo"; |
50 | packet + sizeof("\x84 install gentoo")) == -1) { | 55 | uint8_t res_packet[1 + sizeof(res_message)]; |
56 | res_packet[0] = NET_PACKET_ANNOUNCE_RESPONSE; | ||
57 | memcpy(res_packet + 1, res_message, sizeof(res_message)); | ||
58 | |||
59 | if (send_onion_response(onion->net, source, res_packet, sizeof(res_packet), | ||
60 | packet + sizeof(res_packet)) == -1) { | ||
51 | return 1; | 61 | return 1; |
52 | } | 62 | } |
53 | 63 | ||
@@ -58,11 +68,16 @@ static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, ui | |||
58 | static int handled_test_2; | 68 | static int handled_test_2; |
59 | static int handle_test_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) | 69 | static int handle_test_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
60 | { | 70 | { |
61 | if (length != sizeof("\x84 install gentoo")) { | 71 | const char res_message[] = "install gentoo"; |
72 | uint8_t res_packet[1 + sizeof(res_message)]; | ||
73 | res_packet[0] = NET_PACKET_ANNOUNCE_RESPONSE; | ||
74 | memcpy(res_packet + 1, res_message, sizeof(res_message)); | ||
75 | |||
76 | if (length != sizeof(res_packet)) { | ||
62 | return 1; | 77 | return 1; |
63 | } | 78 | } |
64 | 79 | ||
65 | if (memcmp(packet, (const uint8_t *)"\x84 install gentoo", sizeof("\x84 install gentoo")) != 0) { | 80 | if (memcmp(packet, res_packet, sizeof(res_packet)) != 0) { |
66 | return 1; | 81 | return 1; |
67 | } | 82 | } |
68 | 83 | ||
@@ -179,6 +194,11 @@ static void test_basic(void) | |||
179 | memcpy(n2.public_key, dht_get_self_public_key(onion2->dht), CRYPTO_PUBLIC_KEY_SIZE); | 194 | memcpy(n2.public_key, dht_get_self_public_key(onion2->dht), CRYPTO_PUBLIC_KEY_SIZE); |
180 | n2.ip_port = on2; | 195 | n2.ip_port = on2; |
181 | 196 | ||
197 | const char req_message[] = "Install Gentoo"; | ||
198 | uint8_t req_packet[1 + sizeof(req_message)]; | ||
199 | req_packet[0] = NET_PACKET_ANNOUNCE_REQUEST; | ||
200 | memcpy(req_packet + 1, req_message, sizeof(req_message)); | ||
201 | |||
182 | Node_format nodes[4]; | 202 | Node_format nodes[4]; |
183 | nodes[0] = n1; | 203 | nodes[0] = n1; |
184 | nodes[1] = n2; | 204 | nodes[1] = n2; |
@@ -186,8 +206,7 @@ static void test_basic(void) | |||
186 | nodes[3] = n2; | 206 | nodes[3] = n2; |
187 | Onion_Path path; | 207 | Onion_Path path; |
188 | create_onion_path(onion1->dht, &path, nodes); | 208 | create_onion_path(onion1->dht, &path, nodes); |
189 | int ret = send_onion_packet(onion1->net, &path, nodes[3].ip_port, (const uint8_t *)"\x83 Install Gentoo", | 209 | int ret = send_onion_packet(onion1->net, &path, nodes[3].ip_port, req_packet, sizeof(req_packet)); |
190 | sizeof("\x83 Install Gentoo")); | ||
191 | ck_assert_msg(ret == 0, "Failed to create/send onion packet."); | 210 | ck_assert_msg(ret == 0, "Failed to create/send onion packet."); |
192 | 211 | ||
193 | handled_test_1 = 0; | 212 | handled_test_1 = 0; |