From 6eb7f22c4b23a1b8175222001435fa45d7b570b3 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Wed, 26 Sep 2001 20:29:32 +0000 Subject: [PATCH] added unsafe path composition test added new build_url tests --- test/urltest.lua | 152 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 150 insertions(+), 2 deletions(-) diff --git a/test/urltest.lua b/test/urltest.lua index 20a4f7d..b078d03 100644 --- a/test/urltest.lua +++ b/test/urltest.lua @@ -12,8 +12,18 @@ settagmethod(tag(nil), "getglobal", mygetglobal) assert(dofile "../lua/code.lua") assert(dofile "../lua/url.lua") -local check_protect = function(parsed, path) - local built = URL.build_path(parsed) +local check_build_url = function(parsed) + local built = URL.build_url(parsed) + if built ~= parsed.url then + print("built is different from expected") + print(built) + print(expected) + exit() + end +end + +local check_protect = function(parsed, path, unsafe) + local built = URL.build_path(parsed, unsafe) if built ~= path then print(built, path) print("path composition failed.") @@ -306,6 +316,140 @@ check_parse_url{ path = "path", } +print("testing URL building") +check_build_url { + url = "scheme://user:password@host:port/path;params?query#fragment", + scheme = "scheme", + host = "host", + port = "port", + user = "user", + password = "password", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} + +check_build_url { + url = "scheme://user:password@host/path;params?query#fragment", + scheme = "scheme", + host = "host", + user = "user", + password = "password", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} + +check_build_url { + url = "scheme://user@host/path;params?query#fragment", + scheme = "scheme", + host = "host", + user = "user", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} + +check_build_url { + url = "scheme://host/path;params?query#fragment", + scheme = "scheme", + host = "host", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} + +check_build_url { + url = "scheme://host/path;params#fragment", + scheme = "scheme", + host = "host", + path = "/path", + params = "params", + fragment = "fragment" +} + +check_build_url { + url = "scheme://host/path#fragment", + scheme = "scheme", + host = "host", + path = "/path", + fragment = "fragment" +} + +check_build_url { + url = "scheme://host/path", + scheme = "scheme", + host = "host", + path = "/path", +} + +check_build_url { + url = "//host/path", + host = "host", + path = "/path", +} + +check_build_url { + url = "/path", + path = "/path", +} + +check_build_url { + url = "scheme://user:password@host:port/path;params?query#fragment", + scheme = "scheme", + host = "host", + port = "port", + user = "user", + userinfo = "not used", + password = "password", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} + +check_build_url { + url = "scheme://user:password@host:port/path;params?query#fragment", + scheme = "scheme", + host = "host", + port = "port", + user = "user", + userinfo = "not used", + authority = "not used", + password = "password", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} + +check_build_url { + url = "scheme://user:password@host:port/path;params?query#fragment", + scheme = "scheme", + host = "host", + port = "port", + userinfo = "user:password", + authority = "not used", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} + +check_build_url { + url = "scheme://user:password@host:port/path;params?query#fragment", + scheme = "scheme", + authority = "user:password@host:port", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} + -- standard RFC tests print("testing absolute resolution") check_absolute_url("http://a/b/c/d;p?q#f", "g:h", "g:h") @@ -369,6 +513,10 @@ check_protect({ "eu ", "~diego" }, "eu%20/~diego") check_protect({ "/eu>", "", "/