From d00483eadbee48b820a8a79163c5296953b6f5cb Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 22 Dec 2018 19:18:05 -0800 Subject: Add some wild card validation tests for URLs. These tests are intended to demonstrate that we are not affected by the bug described in #821. --- tests/url.c | 14 ++++++++++++++ tests/ws.c | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/url.c b/tests/url.c index 15eb5d78..9b44dda4 100644 --- a/tests/url.c +++ b/tests/url.c @@ -223,6 +223,20 @@ TestMain("URLs", { nng_url_free(url); }); + Convey("ws://*:12345/foobar", { + So(nng_url_parse(&url, "ws://*:12345/foobar") == 0); + So(url != NULL); + So(strcmp(url->u_scheme, "ws") == 0); + So(strcmp(url->u_host, ":12345") == 0); + So(strcmp(url->u_hostname, "") == 0); + So(strcmp(url->u_path, "/foobar") == 0); + So(strcmp(url->u_port, "12345") == 0); + So(url->u_query == NULL); + So(url->u_fragment == NULL); + So(url->u_userinfo == NULL); + nng_url_free(url); + }); + Convey("ssh://user@host.example.com", { So(nng_url_parse(&url, "ssh://user@host.example.com") == 0); So(url != NULL); diff --git a/tests/ws.c b/tests/ws.c index 0add1a07..e126cb39 100644 --- a/tests/ws.c +++ b/tests/ws.c @@ -103,6 +103,25 @@ TestMain("WebSocket Transport", { So(nng_dial(s2, addr, NULL, 0) == 0); }); + Convey("Wild card hostname works", { + nng_socket s1; + nng_socket s2; + char addr[NNG_MAXADDRLEN]; + + So(nng_pair_open(&s1) == 0); + So(nng_pair_open(&s2) == 0); + Reset({ + nng_close(s2); + nng_close(s1); + }); + trantest_next_address(addr, "ws://*:%u/test"); + So(nng_listen(s1, addr, NULL, 0) == 0); + nng_msleep(100); + // reset port back one + trantest_prev_address(addr, "ws://127.0.0.1:%u/test"); + So(nng_dial(s2, addr, NULL, 0) == 0); + }); + Convey("Incorrect URL paths do not work", { nng_socket s1; nng_socket s2; -- cgit v1.2.3-70-g09d2