diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-09-25 21:35:17 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-09-25 21:35:17 +0000 |
| commit | 6dd115015c6f2514a2f180aaf474a66364939c31 (patch) | |
| tree | 70440522e4aa720c2813258b6923afd6a25e41b0 | |
| parent | d36460a249261680a4a920f05767b7f7cf2868ba (diff) | |
| download | luasocket-6dd115015c6f2514a2f180aaf474a66364939c31.tar.gz luasocket-6dd115015c6f2514a2f180aaf474a66364939c31.tar.bz2 luasocket-6dd115015c6f2514a2f180aaf474a66364939c31.zip | |
Initial revision
| -rw-r--r-- | test/smtptest.lua | 306 | ||||
| -rw-r--r-- | test/urltest.lua | 388 |
2 files changed, 694 insertions, 0 deletions
diff --git a/test/smtptest.lua b/test/smtptest.lua new file mode 100644 index 0000000..fcd238b --- /dev/null +++ b/test/smtptest.lua | |||
| @@ -0,0 +1,306 @@ | |||
| 1 | local sent = {} | ||
| 2 | |||
| 3 | local from = "luasock@tecgraf.puc-rio.br" | ||
| 4 | local server = "mail.tecgraf.puc-rio.br" | ||
| 5 | local rcpt = "luasock@tecgraf.puc-rio.br" | ||
| 6 | |||
| 7 | local parse = {} | ||
| 8 | |||
| 9 | local name = "/var/spool/mail/luasock" | ||
| 10 | |||
| 11 | local t = _time() | ||
| 12 | local err | ||
| 13 | |||
| 14 | function mysetglobal (varname, oldvalue, newvalue) | ||
| 15 | print("changing " .. varname) | ||
| 16 | %rawset(%globals(), varname, newvalue) | ||
| 17 | end | ||
| 18 | function mygetglobal (varname, newvalue) | ||
| 19 | print("checking " .. varname) | ||
| 20 | return %rawget(%globals(), varname) | ||
| 21 | end | ||
| 22 | settagmethod(tag(nil), "setglobal", mysetglobal) | ||
| 23 | settagmethod(tag(nil), "getglobal", mygetglobal) | ||
| 24 | |||
| 25 | assert(dofile("../lua/smtp.lua")) | ||
| 26 | assert(dofile("../lua/cl-compat.lua")) | ||
| 27 | |||
| 28 | local total = function() | ||
| 29 | local t = 0 | ||
| 30 | for i = 1, getn(%sent) do | ||
| 31 | t = t + %sent[i].count | ||
| 32 | end | ||
| 33 | return t | ||
| 34 | end | ||
| 35 | |||
| 36 | local similar = function(s1, s2) | ||
| 37 | return strlower(gsub(s1, "%s", "")) == strlower(gsub(s2, "%s", "")) | ||
| 38 | end | ||
| 39 | |||
| 40 | function parse.headers(headers_s) | ||
| 41 | local headers = {} | ||
| 42 | headers_s = "\n" .. headers_s .. "$$$:\n" | ||
| 43 | local i, j = 1, 1 | ||
| 44 | local name, value, _ | ||
| 45 | while 1 do | ||
| 46 | j = strfind(headers_s, "\n%S-:", i+1) | ||
| 47 | if not j then break end | ||
| 48 | _, _, name, value = strfind(strsub(headers_s, i+1, j-1), "(%S-): (.*)") | ||
| 49 | value = gsub(value, "\r\n", "\n") | ||
| 50 | value = gsub(value, "\n%s*", " ") | ||
| 51 | name = strlower(name) | ||
| 52 | if headers[name] then headers[name] = headers[name] .. ", " .. value | ||
| 53 | else headers[name] = value end | ||
| 54 | i, j = j, i | ||
| 55 | end | ||
| 56 | headers["$$$"] = nil | ||
| 57 | return headers | ||
| 58 | end | ||
| 59 | |||
| 60 | function parse.message(message_s) | ||
| 61 | message_s = gsub(message_s, "^.-\n", "") | ||
| 62 | local _, headers_s, body | ||
| 63 | _, _, headers_s, body = strfind(message_s, "^(.-\n)\n(.*)") | ||
| 64 | headers_s = headers_s or "" | ||
| 65 | body = body or "" | ||
| 66 | return { headers = %parse.headers(headers_s), body = body } | ||
| 67 | end | ||
| 68 | |||
| 69 | function parse.mbox(mbox_s) | ||
| 70 | local mbox = {} | ||
| 71 | mbox_s = "\n" .. mbox_s .. "\nFrom " | ||
| 72 | local i, j = 1, 1 | ||
| 73 | while 1 do | ||
| 74 | j = strfind(mbox_s, "\nFrom ", i + 1) | ||
| 75 | if not j then break end | ||
| 76 | tinsert(mbox, %parse.message(strsub(mbox_s, i + 1, j - 1))) | ||
| 77 | i, j = j, i | ||
| 78 | end | ||
| 79 | return mbox | ||
| 80 | end | ||
| 81 | |||
| 82 | local readfile = function(name) | ||
| 83 | local f = readfrom(name) | ||
| 84 | if not f then return nil end | ||
| 85 | local s = read("*a") | ||
| 86 | readfrom() | ||
| 87 | return s | ||
| 88 | end | ||
| 89 | |||
| 90 | local capture = function(cmd) | ||
| 91 | readfrom("| " .. cmd) | ||
| 92 | local s = read("*a") | ||
| 93 | readfrom() | ||
| 94 | return s | ||
| 95 | end | ||
| 96 | |||
| 97 | local fail = function(s) | ||
| 98 | s = s or "failed!" | ||
| 99 | print(s) | ||
| 100 | exit() | ||
| 101 | end | ||
| 102 | |||
| 103 | local empty = function() | ||
| 104 | local f = openfile(%name, "w") | ||
| 105 | closefile(f) | ||
| 106 | end | ||
| 107 | |||
| 108 | local get = function() | ||
| 109 | return %readfile(%name) | ||
| 110 | end | ||
| 111 | |||
| 112 | local list = function() | ||
| 113 | return %capture("ls -l " .. %name) | ||
| 114 | end | ||
| 115 | |||
| 116 | local check_headers = function(sent, got) | ||
| 117 | sent = sent or {} | ||
| 118 | got = got or {} | ||
| 119 | for i,v in sent do | ||
| 120 | if not %similar(v, got[i]) then %fail("header " .. v .. "failed!") end | ||
| 121 | end | ||
| 122 | end | ||
| 123 | |||
| 124 | local check_body = function(sent, got) | ||
| 125 | sent = sent or "" | ||
| 126 | got = got or "" | ||
| 127 | if not %similar(sent, got) then %fail("bodies differ!") end | ||
| 128 | end | ||
| 129 | |||
| 130 | local check = function(sent, m) | ||
| 131 | write("checking ", m.headers.title, ": ") | ||
| 132 | for i = 1, getn(sent) do | ||
| 133 | local s = sent[i] | ||
| 134 | if s.title == m.headers.title and s.count > 0 then | ||
| 135 | %check_headers(s.headers, m.headers) | ||
| 136 | %check_body(s.body, m.body) | ||
| 137 | s.count = s.count - 1 | ||
| 138 | print("ok") | ||
| 139 | return | ||
| 140 | end | ||
| 141 | end | ||
| 142 | %fail("not found") | ||
| 143 | end | ||
| 144 | |||
| 145 | local insert = function(sent, message) | ||
| 146 | if type(message.rcpt) == "table" then | ||
| 147 | message.count = getn(message.rcpt) | ||
| 148 | else message.count = 1 end | ||
| 149 | message.headers = message.headers or {} | ||
| 150 | message.headers.title = message.title | ||
| 151 | tinsert(sent, message) | ||
| 152 | end | ||
| 153 | |||
| 154 | local mark = function() | ||
| 155 | local time = _time() | ||
| 156 | return { time = time } | ||
| 157 | end | ||
| 158 | |||
| 159 | local wait = function(sentinel, n) | ||
| 160 | local to | ||
| 161 | write("waiting for ", n, " messages: ") | ||
| 162 | while 1 do | ||
| 163 | local mbox = %parse.mbox(%get()) | ||
| 164 | if n == getn(mbox) then break end | ||
| 165 | if _time() - sentinel.time > 50 then | ||
| 166 | to = 1 | ||
| 167 | break | ||
| 168 | end | ||
| 169 | _sleep(1) | ||
| 170 | write(".") | ||
| 171 | flush(_STDOUT) | ||
| 172 | end | ||
| 173 | if to then %fail("timeout") | ||
| 174 | else print("ok") end | ||
| 175 | end | ||
| 176 | |||
| 177 | local stuffed_body = [[ | ||
| 178 | This message body needs to be | ||
| 179 | stuffed because it has a dot | ||
| 180 | . | ||
| 181 | by itself on a line. | ||
| 182 | Otherwise the mailer would | ||
| 183 | think that the dot | ||
| 184 | . | ||
| 185 | is the end of the message | ||
| 186 | and the remaining will cause | ||
| 187 | a lot of trouble. | ||
| 188 | ]] | ||
| 189 | |||
| 190 | insert(sent, { | ||
| 191 | from = from, | ||
| 192 | rcpt = { | ||
| 193 | "luasock2@tecgraf.puc-rio.br", | ||
| 194 | "luasock", | ||
| 195 | "luasock1" | ||
| 196 | }, | ||
| 197 | body = "multiple rcpt body", | ||
| 198 | title = "multiple rcpt", | ||
| 199 | }) | ||
| 200 | |||
| 201 | insert(sent, { | ||
| 202 | from = from, | ||
| 203 | rcpt = { | ||
| 204 | "luasock2@tecgraf.puc-rio.br", | ||
| 205 | "luasock", | ||
| 206 | "luasock1" | ||
| 207 | }, | ||
| 208 | headers = { | ||
| 209 | header1 = "header 1", | ||
| 210 | header2 = "header 2", | ||
| 211 | header3 = "header 3", | ||
| 212 | header4 = "header 4", | ||
| 213 | header5 = "header 5", | ||
| 214 | header6 = "header 6", | ||
| 215 | }, | ||
| 216 | body = stuffed_body, | ||
| 217 | title = "complex message", | ||
| 218 | }) | ||
| 219 | |||
| 220 | insert(sent, { | ||
| 221 | from = from, | ||
| 222 | rcpt = rcpt, | ||
| 223 | server = server, | ||
| 224 | body = "simple message body", | ||
| 225 | title = "simple message" | ||
| 226 | }) | ||
| 227 | |||
| 228 | insert(sent, { | ||
| 229 | from = from, | ||
| 230 | rcpt = rcpt, | ||
| 231 | server = server, | ||
| 232 | body = stuffed_body, | ||
| 233 | title = "stuffed message body" | ||
| 234 | }) | ||
| 235 | |||
| 236 | insert(sent, { | ||
| 237 | from = from, | ||
| 238 | rcpt = rcpt, | ||
| 239 | headers = { | ||
| 240 | header1 = "header 1", | ||
| 241 | header2 = "header 2", | ||
| 242 | header3 = "header 3", | ||
| 243 | header4 = "header 4", | ||
| 244 | header5 = "header 5", | ||
| 245 | header6 = "header 6", | ||
| 246 | }, | ||
| 247 | title = "multiple headers" | ||
| 248 | }) | ||
| 249 | |||
| 250 | insert(sent, { | ||
| 251 | from = from, | ||
| 252 | rcpt = rcpt, | ||
| 253 | title = "minimum message" | ||
| 254 | }) | ||
| 255 | |||
| 256 | write("testing host not found: ") | ||
| 257 | local c, e = connect("wrong.host", 25) | ||
| 258 | local err = SMTP.mail{ | ||
| 259 | from = from, | ||
| 260 | rcpt = rcpt, | ||
| 261 | server = "wrong.host" | ||
| 262 | } | ||
| 263 | if e ~= err then fail("wrong error message") | ||
| 264 | else print("ok") end | ||
| 265 | |||
| 266 | write("testing invalid from: ") | ||
| 267 | local err = SMTP.mail{ | ||
| 268 | from = ' " " (( _ * ', | ||
| 269 | rcpt = rcpt, | ||
| 270 | } | ||
| 271 | if not err then fail("wrong error message") | ||
| 272 | else print(err) end | ||
| 273 | |||
| 274 | write("testing no rcpt: ") | ||
| 275 | local err = SMTP.mail{ | ||
| 276 | from = from, | ||
| 277 | } | ||
| 278 | if not err then fail("wrong error message") | ||
| 279 | else print(err) end | ||
| 280 | |||
| 281 | write("clearing mailbox: ") | ||
| 282 | empty() | ||
| 283 | print("ok") | ||
| 284 | |||
| 285 | write("sending messages: ") | ||
| 286 | for i = 1, getn(sent) do | ||
| 287 | err = SMTP.mail(sent[i]) | ||
| 288 | if err then fail(err) end | ||
| 289 | write("+") | ||
| 290 | flush(_STDOUT) | ||
| 291 | end | ||
| 292 | print("ok") | ||
| 293 | |||
| 294 | wait(mark(), total()) | ||
| 295 | |||
| 296 | write("parsing mailbox: ") | ||
| 297 | local mbox = parse.mbox(get()) | ||
| 298 | print(getn(mbox) .. " messages found!") | ||
| 299 | |||
| 300 | for i = 1, getn(mbox) do | ||
| 301 | check(sent, mbox[i]) | ||
| 302 | end | ||
| 303 | |||
| 304 | |||
| 305 | print("passed all tests") | ||
| 306 | print(format("done in %.2fs", _time() - t)) | ||
diff --git a/test/urltest.lua b/test/urltest.lua new file mode 100644 index 0000000..20a4f7d --- /dev/null +++ b/test/urltest.lua | |||
| @@ -0,0 +1,388 @@ | |||
| 1 | function mysetglobal (varname, oldvalue, newvalue) | ||
| 2 | print("changing " .. varname) | ||
| 3 | %rawset(%globals(), varname, newvalue) | ||
| 4 | end | ||
| 5 | function mygetglobal (varname, newvalue) | ||
| 6 | print("checking " .. varname) | ||
| 7 | return %rawget(%globals(), varname) | ||
| 8 | end | ||
| 9 | settagmethod(tag(nil), "setglobal", mysetglobal) | ||
| 10 | settagmethod(tag(nil), "getglobal", mygetglobal) | ||
| 11 | |||
| 12 | assert(dofile "../lua/code.lua") | ||
| 13 | assert(dofile "../lua/url.lua") | ||
| 14 | |||
| 15 | local check_protect = function(parsed, path) | ||
| 16 | local built = URL.build_path(parsed) | ||
| 17 | if built ~= path then | ||
| 18 | print(built, path) | ||
| 19 | print("path composition failed.") | ||
| 20 | exit() | ||
| 21 | end | ||
| 22 | end | ||
| 23 | |||
| 24 | local check_invert = function(url) | ||
| 25 | local parsed = URL.parse_url(url) | ||
| 26 | parsed.path = URL.build_path(URL.parse_path(parsed.path)) | ||
| 27 | local rebuilt = URL.build_url(parsed) | ||
| 28 | if rebuilt ~= url then | ||
| 29 | print(url, rebuilt) | ||
| 30 | print("original and rebuilt are different") | ||
| 31 | exit() | ||
| 32 | end | ||
| 33 | end | ||
| 34 | |||
| 35 | local check_parse_path = function(path, expect) | ||
| 36 | local parsed = URL.parse_path(path) | ||
| 37 | for i = 1, max(getn(parsed), getn(expect)) do | ||
| 38 | if parsed[i] ~= expect[i] then | ||
| 39 | print(path) | ||
| 40 | write("segment: ", i, " = '", Code.hexa(tostring(parsed[i])), | ||
| 41 | "' but expected '", Code.hexa(tostring(expect[i])), "'\n") | ||
| 42 | exit() | ||
| 43 | end | ||
| 44 | end | ||
| 45 | if expect.is_directory ~= parsed.is_directory then | ||
| 46 | print(path) | ||
| 47 | print("is_directory mismatch") | ||
| 48 | exit() | ||
| 49 | end | ||
| 50 | if expect.is_absolute ~= parsed.is_absolute then | ||
| 51 | print(path) | ||
| 52 | print("is_absolute mismatch") | ||
| 53 | exit() | ||
| 54 | end | ||
| 55 | local built = URL.build_path(expect) | ||
| 56 | if built ~= path then | ||
| 57 | print(built, path) | ||
| 58 | print("path composition failed.") | ||
| 59 | exit() | ||
| 60 | end | ||
| 61 | end | ||
| 62 | |||
| 63 | local check_absolute_url = function(base, relative, absolute) | ||
| 64 | local res = URL.absolute_url(base, relative) | ||
| 65 | if res ~= absolute then | ||
| 66 | write("absolute: In test for '", relative, "' expected '", | ||
| 67 | absolute, "' but got '", res, "'\n") | ||
| 68 | exit() | ||
| 69 | end | ||
| 70 | end | ||
| 71 | |||
| 72 | local check_parse_url = function(gaba) | ||
| 73 | local url = gaba.url | ||
| 74 | gaba.url = nil | ||
| 75 | local parsed = URL.parse_url(url) | ||
| 76 | for i, v in gaba do | ||
| 77 | if v ~= parsed[i] then | ||
| 78 | write("parse: In test for '", url, "' expected ", i, " = '", | ||
| 79 | v, "' but got '", tostring(parsed[i]), "'\n") | ||
| 80 | for i,v in parsed do print(i,v) end | ||
| 81 | exit() | ||
| 82 | end | ||
| 83 | end | ||
| 84 | for i, v in parsed do | ||
| 85 | if v ~= gaba[i] then | ||
| 86 | write("parse: In test for '", url, "' expected ", i, " = '", | ||
| 87 | tostring(gaba[i]), "' but got '", v, "'\n") | ||
| 88 | for i,v in parsed do print(i,v) end | ||
| 89 | exit() | ||
| 90 | end | ||
| 91 | end | ||
| 92 | end | ||
| 93 | |||
| 94 | print("testing URL parsing") | ||
| 95 | check_parse_url{ | ||
| 96 | url = "scheme://userinfo@host:port/path;params?query#fragment", | ||
| 97 | scheme = "scheme", | ||
| 98 | authority = "userinfo@host:port", | ||
| 99 | host = "host", | ||
| 100 | port = "port", | ||
| 101 | userinfo = "userinfo", | ||
| 102 | user = "userinfo", | ||
| 103 | path = "/path", | ||
| 104 | params = "params", | ||
| 105 | query = "query", | ||
| 106 | fragment = "fragment" | ||
| 107 | } | ||
| 108 | |||
| 109 | check_parse_url{ | ||
| 110 | url = "scheme://user:password@host:port/path;params?query#fragment", | ||
| 111 | scheme = "scheme", | ||
| 112 | authority = "user:password@host:port", | ||
| 113 | host = "host", | ||
| 114 | port = "port", | ||
| 115 | userinfo = "user:password", | ||
| 116 | user = "user", | ||
| 117 | password = "password", | ||
| 118 | path = "/path", | ||
| 119 | params = "params", | ||
| 120 | query = "query", | ||
| 121 | fragment = "fragment", | ||
| 122 | } | ||
| 123 | |||
| 124 | check_parse_url{ | ||
| 125 | url = "scheme://userinfo@host:port/path;params?query#", | ||
| 126 | scheme = "scheme", | ||
| 127 | authority = "userinfo@host:port", | ||
| 128 | host = "host", | ||
| 129 | port = "port", | ||
| 130 | userinfo = "userinfo", | ||
| 131 | user = "userinfo", | ||
| 132 | path = "/path", | ||
| 133 | params = "params", | ||
| 134 | query = "query", | ||
| 135 | fragment = "" | ||
| 136 | } | ||
| 137 | |||
| 138 | check_parse_url{ | ||
| 139 | url = "scheme://userinfo@host:port/path;params?#fragment", | ||
| 140 | scheme = "scheme", | ||
| 141 | authority = "userinfo@host:port", | ||
| 142 | host = "host", | ||
| 143 | port = "port", | ||
| 144 | userinfo = "userinfo", | ||
| 145 | user = "userinfo", | ||
| 146 | path = "/path", | ||
| 147 | params = "params", | ||
| 148 | query = "", | ||
| 149 | fragment = "fragment" | ||
| 150 | } | ||
| 151 | |||
| 152 | check_parse_url{ | ||
| 153 | url = "scheme://userinfo@host:port/path;params#fragment", | ||
| 154 | scheme = "scheme", | ||
| 155 | authority = "userinfo@host:port", | ||
| 156 | host = "host", | ||
| 157 | port = "port", | ||
| 158 | userinfo = "userinfo", | ||
| 159 | user = "userinfo", | ||
| 160 | path = "/path", | ||
| 161 | params = "params", | ||
| 162 | fragment = "fragment" | ||
| 163 | } | ||
| 164 | |||
| 165 | check_parse_url{ | ||
| 166 | url = "scheme://userinfo@host:port/path;?query#fragment", | ||
| 167 | scheme = "scheme", | ||
| 168 | authority = "userinfo@host:port", | ||
| 169 | host = "host", | ||
| 170 | port = "port", | ||
| 171 | userinfo = "userinfo", | ||
| 172 | user = "userinfo", | ||
| 173 | path = "/path", | ||
| 174 | params = "", | ||
| 175 | query = "query", | ||
| 176 | fragment = "fragment" | ||
| 177 | } | ||
| 178 | |||
| 179 | check_parse_url{ | ||
| 180 | url = "scheme://userinfo@host:port/path?query#fragment", | ||
| 181 | scheme = "scheme", | ||
| 182 | authority = "userinfo@host:port", | ||
| 183 | host = "host", | ||
| 184 | port = "port", | ||
| 185 | userinfo = "userinfo", | ||
| 186 | user = "userinfo", | ||
| 187 | path = "/path", | ||
| 188 | query = "query", | ||
| 189 | fragment = "fragment" | ||
| 190 | } | ||
| 191 | |||
| 192 | check_parse_url{ | ||
| 193 | url = "scheme://userinfo@host:port/;params?query#fragment", | ||
| 194 | scheme = "scheme", | ||
| 195 | authority = "userinfo@host:port", | ||
| 196 | host = "host", | ||
| 197 | port = "port", | ||
| 198 | userinfo = "userinfo", | ||
| 199 | user = "userinfo", | ||
| 200 | path = "/", | ||
| 201 | params = "params", | ||
| 202 | query = "query", | ||
| 203 | fragment = "fragment" | ||
| 204 | } | ||
| 205 | |||
| 206 | check_parse_url{ | ||
| 207 | url = "scheme://userinfo@host:port", | ||
| 208 | scheme = "scheme", | ||
| 209 | authority = "userinfo@host:port", | ||
| 210 | host = "host", | ||
| 211 | port = "port", | ||
| 212 | userinfo = "userinfo", | ||
| 213 | user = "userinfo", | ||
| 214 | } | ||
| 215 | |||
| 216 | check_parse_url{ | ||
| 217 | url = "//userinfo@host:port/path;params?query#fragment", | ||
| 218 | authority = "userinfo@host:port", | ||
| 219 | host = "host", | ||
| 220 | port = "port", | ||
| 221 | userinfo = "userinfo", | ||
| 222 | user = "userinfo", | ||
| 223 | path = "/path", | ||
| 224 | params = "params", | ||
| 225 | query = "query", | ||
| 226 | fragment = "fragment" | ||
| 227 | } | ||
| 228 | |||
| 229 | check_parse_url{ | ||
| 230 | url = "//userinfo@host:port/path", | ||
| 231 | authority = "userinfo@host:port", | ||
| 232 | host = "host", | ||
| 233 | port = "port", | ||
| 234 | userinfo = "userinfo", | ||
| 235 | user = "userinfo", | ||
| 236 | path = "/path", | ||
| 237 | } | ||
| 238 | |||
| 239 | check_parse_url{ | ||
| 240 | url = "//userinfo@host/path", | ||
| 241 | authority = "userinfo@host", | ||
| 242 | host = "host", | ||
| 243 | userinfo = "userinfo", | ||
| 244 | user = "userinfo", | ||
| 245 | path = "/path", | ||
| 246 | } | ||
| 247 | |||
| 248 | check_parse_url{ | ||
| 249 | url = "//user:password@host/path", | ||
| 250 | authority = "user:password@host", | ||
| 251 | host = "host", | ||
| 252 | userinfo = "user:password", | ||
| 253 | password = "password", | ||
| 254 | user = "user", | ||
| 255 | path = "/path", | ||
| 256 | } | ||
| 257 | |||
| 258 | check_parse_url{ | ||
| 259 | url = "//user:@host/path", | ||
| 260 | authority = "user:@host", | ||
| 261 | host = "host", | ||
| 262 | userinfo = "user:", | ||
| 263 | password = "", | ||
| 264 | user = "user", | ||
| 265 | path = "/path", | ||
| 266 | } | ||
| 267 | |||
| 268 | check_parse_url{ | ||
| 269 | url = "//user@host:port/path", | ||
| 270 | authority = "user@host:port", | ||
| 271 | host = "host", | ||
| 272 | userinfo = "user", | ||
| 273 | user = "user", | ||
| 274 | port = "port", | ||
| 275 | path = "/path", | ||
| 276 | } | ||
| 277 | |||
| 278 | check_parse_url{ | ||
| 279 | url = "//host:port/path", | ||
| 280 | authority = "host:port", | ||
| 281 | port = "port", | ||
| 282 | host = "host", | ||
| 283 | path = "/path", | ||
| 284 | } | ||
| 285 | |||
| 286 | check_parse_url{ | ||
| 287 | url = "//host/path", | ||
| 288 | authority = "host", | ||
| 289 | host = "host", | ||
| 290 | path = "/path", | ||
| 291 | } | ||
| 292 | |||
| 293 | check_parse_url{ | ||
| 294 | url = "//host", | ||
| 295 | authority = "host", | ||
| 296 | host = "host", | ||
| 297 | } | ||
| 298 | |||
| 299 | check_parse_url{ | ||
| 300 | url = "/path", | ||
| 301 | path = "/path", | ||
| 302 | } | ||
| 303 | |||
| 304 | check_parse_url{ | ||
| 305 | url = "path", | ||
| 306 | path = "path", | ||
| 307 | } | ||
| 308 | |||
| 309 | -- standard RFC tests | ||
| 310 | print("testing absolute resolution") | ||
| 311 | check_absolute_url("http://a/b/c/d;p?q#f", "g:h", "g:h") | ||
| 312 | check_absolute_url("http://a/b/c/d;p?q#f", "g", "http://a/b/c/g") | ||
| 313 | check_absolute_url("http://a/b/c/d;p?q#f", "./g", "http://a/b/c/g") | ||
| 314 | check_absolute_url("http://a/b/c/d;p?q#f", "g/", "http://a/b/c/g/") | ||
| 315 | check_absolute_url("http://a/b/c/d;p?q#f", "/g", "http://a/g") | ||
| 316 | check_absolute_url("http://a/b/c/d;p?q#f", "//g", "http://g") | ||
| 317 | check_absolute_url("http://a/b/c/d;p?q#f", "?y", "http://a/b/c/d;p?y") | ||
| 318 | check_absolute_url("http://a/b/c/d;p?q#f", "g?y", "http://a/b/c/g?y") | ||
| 319 | check_absolute_url("http://a/b/c/d;p?q#f", "g?y/./x", "http://a/b/c/g?y/./x") | ||
| 320 | check_absolute_url("http://a/b/c/d;p?q#f", "#s", "http://a/b/c/d;p?q#s") | ||
| 321 | check_absolute_url("http://a/b/c/d;p?q#f", "g#s", "http://a/b/c/g#s") | ||
| 322 | check_absolute_url("http://a/b/c/d;p?q#f", "g#s/./x", "http://a/b/c/g#s/./x") | ||
| 323 | check_absolute_url("http://a/b/c/d;p?q#f", "g?y#s", "http://a/b/c/g?y#s") | ||
| 324 | check_absolute_url("http://a/b/c/d;p?q#f", ";x", "http://a/b/c/d;x") | ||
| 325 | check_absolute_url("http://a/b/c/d;p?q#f", "g;x", "http://a/b/c/g;x") | ||
| 326 | check_absolute_url("http://a/b/c/d;p?q#f", "g;x?y#s", "http://a/b/c/g;x?y#s") | ||
| 327 | check_absolute_url("http://a/b/c/d;p?q#f", ".", "http://a/b/c/") | ||
| 328 | check_absolute_url("http://a/b/c/d;p?q#f", "./", "http://a/b/c/") | ||
| 329 | check_absolute_url("http://a/b/c/d;p?q#f", "..", "http://a/b/") | ||
| 330 | check_absolute_url("http://a/b/c/d;p?q#f", "../", "http://a/b/") | ||
| 331 | check_absolute_url("http://a/b/c/d;p?q#f", "../g", "http://a/b/g") | ||
| 332 | check_absolute_url("http://a/b/c/d;p?q#f", "../..", "http://a/") | ||
| 333 | check_absolute_url("http://a/b/c/d;p?q#f", "../../", "http://a/") | ||
| 334 | check_absolute_url("http://a/b/c/d;p?q#f", "../../g", "http://a/g") | ||
| 335 | check_absolute_url("http://a/b/c/d;p?q#f", "", "http://a/b/c/d;p?q#f") | ||
| 336 | check_absolute_url("http://a/b/c/d;p?q#f", "/./g", "http://a/./g") | ||
| 337 | check_absolute_url("http://a/b/c/d;p?q#f", "/../g", "http://a/../g") | ||
| 338 | check_absolute_url("http://a/b/c/d;p?q#f", "g.", "http://a/b/c/g.") | ||
| 339 | check_absolute_url("http://a/b/c/d;p?q#f", ".g", "http://a/b/c/.g") | ||
| 340 | check_absolute_url("http://a/b/c/d;p?q#f", "g..", "http://a/b/c/g..") | ||
| 341 | check_absolute_url("http://a/b/c/d;p?q#f", "..g", "http://a/b/c/..g") | ||
| 342 | check_absolute_url("http://a/b/c/d;p?q#f", "./../g", "http://a/b/g") | ||
| 343 | check_absolute_url("http://a/b/c/d;p?q#f", "./g/.", "http://a/b/c/g/") | ||
| 344 | check_absolute_url("http://a/b/c/d;p?q#f", "g/./h", "http://a/b/c/g/h") | ||
| 345 | check_absolute_url("http://a/b/c/d;p?q#f", "g/../h", "http://a/b/c/h") | ||
| 346 | |||
| 347 | -- extra tests | ||
| 348 | check_absolute_url("//a/b/c/d;p?q#f", "d/e/f", "//a/b/c/d/e/f") | ||
| 349 | check_absolute_url("/a/b/c/d;p?q#f", "d/e/f", "/a/b/c/d/e/f") | ||
| 350 | check_absolute_url("a/b/c/d", "d/e/f", "a/b/c/d/e/f") | ||
| 351 | check_absolute_url("a/b/c/d/../", "d/e/f", "a/b/c/d/e/f") | ||
| 352 | check_absolute_url("http://velox.telemar.com.br", "/dashboard/index.html", | ||
| 353 | "http://velox.telemar.com.br/dashboard/index.html") | ||
| 354 | |||
| 355 | print("testing path parsing and composition") | ||
| 356 | check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 }) | ||
| 357 | check_parse_path("/eu/", { "eu"; is_absolute = 1, is_directory = 1 }) | ||
| 358 | check_parse_path("eu/tu/ele/nos/vos/eles/", | ||
| 359 | { "eu", "tu", "ele", "nos", "vos", "eles"; is_directory = 1}) | ||
| 360 | check_parse_path("/", { is_absolute = 1, is_directory = 1}) | ||
| 361 | check_parse_path("", { }) | ||
| 362 | check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/", | ||
| 363 | { "eu\1", "\2tu", "e\3l\4e", "nos", "vos\5", "e\18les"; is_directory = 1}) | ||
| 364 | check_parse_path("eu/tu", { "eu", "tu" }) | ||
| 365 | |||
| 366 | print("testing path protection") | ||
| 367 | check_protect({ "eu", "-_.!~*'():@&=+$,", "tu" }, "eu/-_.!~*'():@&=+$,/tu") | ||
| 368 | check_protect({ "eu ", "~diego" }, "eu%20/~diego") | ||
| 369 | check_protect({ "/eu>", "<diego?" }, "%2feu%3e/%3cdiego%3f") | ||
| 370 | check_protect({ "\\eu]", "[diego`" }, "%5ceu%5d/%5bdiego%60") | ||
| 371 | check_protect({ "{eu}", "|diego\127" }, "%7beu%7d/%7cdiego%7f") | ||
| 372 | |||
| 373 | print("testing inversion") | ||
| 374 | check_invert("http:") | ||
| 375 | check_invert("a/b/c/d.html") | ||
| 376 | check_invert("//net_loc") | ||
| 377 | check_invert("http:a/b/d/c.html") | ||
| 378 | check_invert("//net_loc/a/b/d/c.html") | ||
| 379 | check_invert("http://net_loc/a/b/d/c.html") | ||
| 380 | check_invert("//who:isit@net_loc") | ||
| 381 | check_invert("http://he:man@boo.bar/a/b/c/i.html;type=moo?this=that#mark") | ||
| 382 | check_invert("/b/c/d#fragment") | ||
| 383 | check_invert("/b/c/d;param#fragment") | ||
| 384 | check_invert("/b/c/d;param?query#fragment") | ||
| 385 | check_invert("/b/c/d?query") | ||
| 386 | check_invert("/b/c/d;param?query") | ||
| 387 | |||
| 388 | print("the library passed all tests") | ||
