Commit f6c8a8c5 authored by teor's avatar teor
Browse files

test/cell_formats: Expand the IPv6-only EXTEND2 test

Part of 33901.
parent bd6ab90a
Loading
Loading
Loading
Loading
+34 −7
Original line number Diff line number Diff line
@@ -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));