]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
test/cell_formats: Expand the IPv6-only EXTEND2 test
authorteor <teor@torproject.org>
Tue, 14 Apr 2020 08:44:06 +0000 (18:44 +1000)
committerteor <teor@torproject.org>
Wed, 29 Apr 2020 12:43:09 +0000 (22:43 +1000)
Part of 33901.

src/test/test_cell_formats.c

index 3d3f151fcbe7136d70e8d2c108c1e08f957705b2..f9ff101c98c3f299de62f61c6ec57c4d4e32ab3e 100644 (file)
@@ -769,6 +769,40 @@ test_cfmt_extend_cells(void *arg)
   tt_mem_op("brownshoesdontmakeit/brownshoesd", OP_EQ,
             ec.ed_pubkey.pubkey, 32);
 
+  /* Now try IPv6 without IPv4 */
+  memset(p, 0, sizeof(p));
+  memcpy(p, "\x02", 1);
+  memcpy(p+1, "\x02\x14" "anthropomorphization", 22);
+  memcpy(p+23, "\x01\x12" "xxxxxxxxxxxxxxxxYY", 20);
+  memcpy(p+43, "\xff\xff\x00\x20", 4);
+  tt_int_op(0, OP_EQ, extend_cell_parse(&ec, RELAY_COMMAND_EXTEND2,
+                                         p, sizeof(p)));
+  tt_int_op(RELAY_COMMAND_EXTEND2, OP_EQ, ec.cell_type);
+  tt_assert(fast_mem_is_zero((const char *)&ec.orport_ipv4.addr,
+                             sizeof(tor_addr_t)));
+  tt_int_op(0, OP_EQ, ec.orport_ipv4.port);
+  tt_str_op("7878:7878:7878:7878:7878:7878:7878:7878",
+            OP_EQ, fmt_addr(&ec.orport_ipv6.addr));
+  tt_int_op(22873, OP_EQ, ec.orport_ipv6.port);
+  tt_assert(ed25519_public_key_is_zero(&ec.ed_pubkey));
+  tt_mem_op(ec.node_id,OP_EQ, "anthropomorphization", 20);
+  tt_int_op(cc->cell_type, OP_EQ, CELL_CREATE2);
+  tt_int_op(cc->handshake_type, OP_EQ, 0xffff);
+  tt_int_op(cc->handshake_len, OP_EQ, 32);
+  tt_int_op(0, OP_EQ, extend_cell_format(&p2_cmd, &p2_len, p2, &ec));
+  tt_int_op(p2_cmd, OP_EQ, RELAY_COMMAND_EXTEND2);
+  tt_int_op(p2_len, OP_EQ, 47+32);
+  test_memeq_hex(p2,
+                 /* Two items */
+                 "02"
+                 /* The next is an RSA digest: anthropomorphization */
+                 "0214" "616e7468726f706f6d6f727068697a6174696f6e"
+                 /*IPv6 address */
+                 "0112" "78787878787878787878787878787878" "5959"
+                 /* Now the handshake prologue */
+                 "ffff0020");
+  tt_int_op(0, OP_EQ, create_cell_format_relayed(&cell, cc));
+
   /* == Now try parsing some junk */
 
   /* Try a too-long handshake */
@@ -824,13 +858,6 @@ test_cfmt_extend_cells(void *arg)
   memcpy(p+48, "\xff\xff\x00\x20", 4);
   tt_int_op(-1, OP_EQ, extend_cell_parse(&ec, RELAY_COMMAND_EXTEND2,
                                       p, sizeof(p)));
-  memset(p, 0, sizeof(p));
-  memcpy(p, "\x02", 1);
-  memcpy(p+1, "\x02\x14" "anarchoindividualist", 22);
-  memcpy(p+23, "\x01\x12" "xxxxxxxxxxxxxxxxYY", 18);
-  memcpy(p+41, "\xff\xff\x00\x20", 4);
-  tt_int_op(0, OP_EQ, extend_cell_parse(&ec, RELAY_COMMAND_EXTEND2,
-                                      p, sizeof(p)));
 
   /* Running out of space in specifiers  */
   memset(p,0,sizeof(p));