diff options
author | teor <teor@torproject.org> | 2019-06-13 21:22:27 +1000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-06-26 09:55:37 -0400 |
commit | 1d3d6bf6b18ff7d3462d48d33d3e982f063f35d6 (patch) | |
tree | d0279c546c14b4930c477b8e145148f891d2a949 /src/test | |
parent | adb8538e7b6a7a2531233797990f6d11be86a718 (diff) | |
download | tor-1d3d6bf6b18ff7d3462d48d33d3e982f063f35d6.tar.gz tor-1d3d6bf6b18ff7d3462d48d33d3e982f063f35d6.zip |
test/addr: Add unit tests for the fixes in 30721
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test_addr.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/test/test_addr.c b/src/test/test_addr.c index 05d8bf6c7b..a961a46854 100644 --- a/src/test/test_addr.c +++ b/src/test/test_addr.c @@ -788,6 +788,10 @@ test_addr_parse(void *arg) r= tor_addr_parse(&addr, "11:22:33:44:55:66:77:88:1.2.3.4"); tt_int_op(r,OP_EQ, -1); + /* IPv6 address with port and no brackets */ + r= tor_addr_parse(&addr, "11:22::33:44:12345"); + tt_int_op(r, OP_EQ, -1); + /* Correct call. */ r= tor_addr_port_parse(LOG_DEBUG, "192.0.2.1:1234", @@ -834,6 +838,18 @@ test_addr_parse(void *arg) tt_int_op(r, OP_EQ, 0); tt_int_op(port,OP_EQ,400); + /* Allow IPv6 without square brackets, when there is no port */ + r= tor_addr_port_parse(LOG_DEBUG, + "::1", + &addr, &port, -1); + tt_int_op(r, OP_EQ, -1); + + r= tor_addr_port_parse(LOG_DEBUG, + "::1", + &addr, &port, 600); + tt_int_op(r, OP_EQ, 0); + tt_int_op(port,OP_EQ,600); + /* Bad port. */ r= tor_addr_port_parse(LOG_DEBUG, "192.0.2.2:66666", @@ -854,12 +870,29 @@ test_addr_parse(void *arg) &addr, &port, 200); tt_int_op(r, OP_EQ, -1); - /* Bad IP address */ + /* Bad IPv4 address */ r= tor_addr_port_parse(LOG_DEBUG, "192.0.2:1234", &addr, &port, -1); tt_int_op(r, OP_EQ, -1); + /* Bad IPv4 address and port: brackets */ + r= tor_addr_port_parse(LOG_DEBUG, + "[192.0.2.3]:12345", + &addr, &port, -1); + tt_int_op(r, OP_EQ, -1); + + /* Bad IPv6 addresses and ports: no brackets */ + r= tor_addr_port_parse(LOG_DEBUG, + "::1:12345", + &addr, &port, -1); + tt_int_op(r, OP_EQ, -1); + + r= tor_addr_port_parse(LOG_DEBUG, + "11:22::33:44:12345", + &addr, &port, -1); + tt_int_op(r, OP_EQ, -1); + /* Make sure that the default port has lower priority than the real one */ r= tor_addr_port_parse(LOG_DEBUG, |