Ticket #23080: 0001-Add-additional-tests-for-ExtORPort-USERADDR.patch

File 0001-Add-additional-tests-for-ExtORPort-USERADDR.patch, 1.8 KB (added by dcf, 2 years ago)
  • src/test/test_extorport.c

    From 93fea7f70c75427da92dc0b46f858da111edc58e Mon Sep 17 00:00:00 2001
    From: David Fifield <david@bamsoftware.com>
    Date: Wed, 2 Aug 2017 00:55:13 -0700
    Subject: [PATCH] Add additional tests for ExtORPort USERADDR.
    
    IPv4 and IPv6 (with and without brackets), with and without port.
    ---
     src/test/test_extorport.c | 30 ++++++++++++++++++++++++++++++
     1 file changed, 30 insertions(+)
    
    diff --git a/src/test/test_extorport.c b/src/test/test_extorport.c
    index fc9f27a5a..82a5e864d 100644
    a b test_ext_or_handshake(void *arg) 
    546546  close_closeable_connections();
    547547  conn = NULL;
    548548
     549  /* Try various formats of USERADDR. */
     550  const struct {
     551    const char *data;
     552    size_t n;
     553    const char *expected_addr;
     554    uint16_t port;
     555  } useraddrs[] = {
     556    {"\x00\x01\x00\x07""1.2.3.4", 11, "1.2.3.4", 0},
     557    {"\x00\x01\x00\x0c""1.2.3.4:5678", 16, "1.2.3.4", 5678},
     558    {"\x00\x01\x00\x08""1:2::3:4", 12, "1:2::3:4", 0},
     559    {"\x00\x01\x00\x0a""[1:2::3:4]", 14, "1:2::3:4", 0},
     560    {"\x00\x01\x00\x0f""[1:2::3:4]:5678", 19, "1:2::3:4", 5678},
     561  };
     562  size_t i;
     563  for (i = 0; i < ARRAY_LENGTH(useraddrs); i++) {
     564    tor_addr_t expected_addr;
     565    int af;
     566
     567    conn = or_connection_new(CONN_TYPE_EXT_OR, AF_INET);
     568    do_ext_or_handshake(conn);
     569    WRITE(useraddrs[i].data, useraddrs[i].n);
     570    tt_int_op(0, OP_EQ, connection_ext_or_process_inbuf(conn));
     571    tt_int_op(TO_CONN(conn)->port, OP_EQ, useraddrs[i].port);
     572    af = tor_addr_parse(&expected_addr, useraddrs[i].expected_addr);
     573    tt_int_op(af, OP_GT, 0);
     574    tt_assert(tor_addr_eq(&TO_CONN(conn)->addr, &expected_addr));
     575    close_closeable_connections();
     576    conn = NULL;
     577  }
     578
    549579  /* Okay, this time let's succeed the handshake but fail the USERADDR
    550580     command. */
    551581  conn = or_connection_new(CONN_TYPE_EXT_OR, AF_INET);