From 23a38d766780f4749945d84316b4e0a71e707b15 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 4 Mar 2018 17:04:11 -0800 Subject: fixes #262 NNG_OPT_URL should be resolved This causes TCP, TLS, and ZT endpoints to resolve any wildcards, and even IP addresses, when reporting the listen URL. The dialer URL is reported unresolved. Test cases for this are added as well, and nngcat actually reports this if --verbose is supplied. --- tests/tcp.c | 19 +++++++++++++++++++ tests/tls.c | 22 ++++++++++++++++++++++ tests/zt.c | 16 +++++++++++++++- 3 files changed, 56 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/tcp.c b/tests/tcp.c index ef572c9d..42be028d 100644 --- a/tests/tcp.c +++ b/tests/tcp.c @@ -80,6 +80,25 @@ TestMain("TCP Transport", { So(nng_dial(s2, addr, NULL, 0) == 0); }); + Convey("We can bind to port zero", { + nng_socket s1; + nng_socket s2; + nng_listener l; + char addr[NNG_MAXADDRLEN]; + size_t sz; + + So(nng_pair_open(&s1) == 0); + So(nng_pair_open(&s2) == 0); + Reset({ + nng_close(s2); + nng_close(s1); + }); + So(nng_listen(s1, "tcp://127.0.0.1:0", &l, 0) == 0); + sz = NNG_MAXADDRLEN; + So(nng_listener_getopt(l, NNG_OPT_URL, addr, &sz) == 0); + So(nng_dial(s2, addr, NULL, 0) == 0); + }); + Convey("Malformed TCP addresses do not panic", { nng_socket s1; diff --git a/tests/tls.c b/tests/tls.c index 31041fa5..f51fabef 100644 --- a/tests/tls.c +++ b/tests/tls.c @@ -9,7 +9,9 @@ // #include "convey.h" + #include "nng.h" + #include "protocol/pair1/pair.h" #include "supplemental/tls/tls.h" #include "transport/tls/tls.h" @@ -293,6 +295,26 @@ TestMain("TLS Transport", { So(nng_dial(s2, addr, NULL, 0) == 0); }); + Convey("We can bind to port zero", { + nng_socket s1; + nng_socket s2; + nng_listener l; + char addr[NNG_MAXADDRLEN]; + size_t sz; + + So(nng_tls_register() == 0); + So(nng_pair_open(&s1) == 0); + So(nng_pair_open(&s2) == 0); + Reset({ + nng_close(s2); + nng_close(s1); + }); + So(nng_listen(s1, "tls+tcp://127.0.0.1:0", &l, 0) == 0); + sz = NNG_MAXADDRLEN; + So(nng_listener_getopt(l, NNG_OPT_URL, addr, &sz) == 0); + So(nng_dial(s2, addr, NULL, 0) == 0); + }); + Convey("Malformed TLS addresses do not panic", { nng_socket s1; diff --git a/tests/zt.c b/tests/zt.c index c8b7563c..fa662857 100644 --- a/tests/zt.c +++ b/tests/zt.c @@ -285,6 +285,20 @@ TestMain("ZeroTier Transport", { nng_msleep(2000); // to give dialer time to start up }); - trantest_test_extended("zt://*." NWID ":%u", check_props); + // We need to determine our ephemeral ID: + + nng_socket s_test; + nng_listener l_test; + uint64_t node; + char fmt[128]; + + So(nng_pair_open(&s_test) == 0); + So(nng_listener_create(&l_test, s_test, "zt://*." NWID ":0") == 0); + So(nng_listener_start(l_test, 0) == 0); + So(nng_listener_getopt_uint64(l_test, NNG_OPT_ZT_NODE, &node) == 0); + snprintf(fmt, sizeof(fmt), "zt://%llx." NWID ":%%u", node); + nng_listener_close(l_test); + + trantest_test_extended(fmt, check_props); }) -- cgit v1.2.3-70-g09d2