aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-01-21 20:25:42 -0800
committerGarrett D'Amore <garrett@damore.org>2018-01-21 22:29:31 -0800
commit5b1a3af7be4ae712868ae84b9a7d5a974d272b16 (patch)
tree960cf1b0843d1e5fbd879d1d0c1d31ab705e30c9 /tests
parent7dbc9ae4fef34c6fd836b939bd559e54b8008b72 (diff)
downloadnng-5b1a3af7be4ae712868ae84b9a7d5a974d272b16.tar.gz
nng-5b1a3af7be4ae712868ae84b9a7d5a974d272b16.tar.bz2
nng-5b1a3af7be4ae712868ae84b9a7d5a974d272b16.zip
fixes #217 URL canonicalization needs work
Diffstat (limited to 'tests')
-rw-r--r--tests/url.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/url.c b/tests/url.c
index 5348d470..dba0664b 100644
--- a/tests/url.c
+++ b/tests/url.c
@@ -265,4 +265,59 @@ TestMain("URLs", {
So(url == NULL);
});
+ Convey("Canonicalization works", {
+ url = NULL;
+ So(nni_url_parse(&url,
+ "hTTp://www.EXAMPLE.com/bogus/.%2e/%7egarrett") == 0);
+ So(url != NULL);
+ So(strcmp(url->u_scheme, "http") == 0);
+ So(strcmp(url->u_hostname, "www.example.com") == 0);
+ So(strcmp(url->u_port, "80") == 0);
+ So(strcmp(url->u_path, "/~garrett") == 0);
+ nni_url_free(url);
+ });
+
+ Convey("Path resolution works", {
+ url = NULL;
+ So(nni_url_parse(&url,
+ "http://www.x.com//abc/def/./x/..///./../y") == 0);
+ So(url != NULL);
+ So(strcmp(url->u_scheme, "http") == 0);
+ So(strcmp(url->u_hostname, "www.x.com") == 0);
+ So(strcmp(url->u_port, "80") == 0);
+ So(strcmp(url->u_path, "/abc/y") == 0);
+ nni_url_free(url);
+ });
+
+ Convey("Query info unmolested", {
+ url = NULL;
+ So(nni_url_parse(
+ &url, "http://www.x.com/?/abc/def/./x/.././../y") == 0);
+ So(url != NULL);
+ So(strcmp(url->u_scheme, "http") == 0);
+ So(strcmp(url->u_hostname, "www.x.com") == 0);
+ So(strcmp(url->u_port, "80") == 0);
+ So(strcmp(url->u_path, "/") == 0);
+ So(strcmp(url->u_query, "/abc/def/./x/.././../y") == 0);
+ nni_url_free(url);
+ });
+
+ Convey("Bad UTF-8 fails", {
+ url = NULL;
+ So(nni_url_parse(&url, "http://x.com/x%80x") == NNG_EINVAL);
+ So(nni_url_parse(&url, "http://x.com/x%c0%81") == NNG_EINVAL);
+ });
+
+ Convey("Valid UTF-8 works", {
+ url = NULL;
+ So(nni_url_parse(&url, "http://www.x.com/%c2%a2_centsign") ==
+ 0);
+ So(url != NULL);
+ So(strcmp(url->u_scheme, "http") == 0);
+ So(strcmp(url->u_hostname, "www.x.com") == 0);
+ So(strcmp(url->u_port, "80") == 0);
+ So(strcmp(url->u_path, "/\xc2\xa2_centsign") == 0);
+ nni_url_free(url);
+ });
+
})