aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2001-09-26 20:29:32 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2001-09-26 20:29:32 +0000
commit6eb7f22c4b23a1b8175222001435fa45d7b570b3 (patch)
treea3cade1b39219fed5a5581043db1efca9297cb64
parent4f27c376e9e9aac413ad7b30b683ce08ba16fd1e (diff)
downloadluasocket-6eb7f22c4b23a1b8175222001435fa45d7b570b3.tar.gz
luasocket-6eb7f22c4b23a1b8175222001435fa45d7b570b3.tar.bz2
luasocket-6eb7f22c4b23a1b8175222001435fa45d7b570b3.zip
added unsafe path composition test
added new build_url tests
-rw-r--r--test/urltest.lua152
1 files 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)
12assert(dofile "../lua/code.lua") 12assert(dofile "../lua/code.lua")
13assert(dofile "../lua/url.lua") 13assert(dofile "../lua/url.lua")
14 14
15local check_protect = function(parsed, path) 15local check_build_url = function(parsed)
16 local built = URL.build_path(parsed) 16 local built = URL.build_url(parsed)
17 if built ~= parsed.url then
18 print("built is different from expected")
19 print(built)
20 print(expected)
21 exit()
22 end
23end
24
25local check_protect = function(parsed, path, unsafe)
26 local built = URL.build_path(parsed, unsafe)
17 if built ~= path then 27 if built ~= path then
18 print(built, path) 28 print(built, path)
19 print("path composition failed.") 29 print("path composition failed.")
@@ -306,6 +316,140 @@ check_parse_url{
306 path = "path", 316 path = "path",
307} 317}
308 318
319print("testing URL building")
320check_build_url {
321 url = "scheme://user:password@host:port/path;params?query#fragment",
322 scheme = "scheme",
323 host = "host",
324 port = "port",
325 user = "user",
326 password = "password",
327 path = "/path",
328 params = "params",
329 query = "query",
330 fragment = "fragment"
331}
332
333check_build_url {
334 url = "scheme://user:password@host/path;params?query#fragment",
335 scheme = "scheme",
336 host = "host",
337 user = "user",
338 password = "password",
339 path = "/path",
340 params = "params",
341 query = "query",
342 fragment = "fragment"
343}
344
345check_build_url {
346 url = "scheme://user@host/path;params?query#fragment",
347 scheme = "scheme",
348 host = "host",
349 user = "user",
350 path = "/path",
351 params = "params",
352 query = "query",
353 fragment = "fragment"
354}
355
356check_build_url {
357 url = "scheme://host/path;params?query#fragment",
358 scheme = "scheme",
359 host = "host",
360 path = "/path",
361 params = "params",
362 query = "query",
363 fragment = "fragment"
364}
365
366check_build_url {
367 url = "scheme://host/path;params#fragment",
368 scheme = "scheme",
369 host = "host",
370 path = "/path",
371 params = "params",
372 fragment = "fragment"
373}
374
375check_build_url {
376 url = "scheme://host/path#fragment",
377 scheme = "scheme",
378 host = "host",
379 path = "/path",
380 fragment = "fragment"
381}
382
383check_build_url {
384 url = "scheme://host/path",
385 scheme = "scheme",
386 host = "host",
387 path = "/path",
388}
389
390check_build_url {
391 url = "//host/path",
392 host = "host",
393 path = "/path",
394}
395
396check_build_url {
397 url = "/path",
398 path = "/path",
399}
400
401check_build_url {
402 url = "scheme://user:password@host:port/path;params?query#fragment",
403 scheme = "scheme",
404 host = "host",
405 port = "port",
406 user = "user",
407 userinfo = "not used",
408 password = "password",
409 path = "/path",
410 params = "params",
411 query = "query",
412 fragment = "fragment"
413}
414
415check_build_url {
416 url = "scheme://user:password@host:port/path;params?query#fragment",
417 scheme = "scheme",
418 host = "host",
419 port = "port",
420 user = "user",
421 userinfo = "not used",
422 authority = "not used",
423 password = "password",
424 path = "/path",
425 params = "params",
426 query = "query",
427 fragment = "fragment"
428}
429
430check_build_url {
431 url = "scheme://user:password@host:port/path;params?query#fragment",
432 scheme = "scheme",
433 host = "host",
434 port = "port",
435 userinfo = "user:password",
436 authority = "not used",
437 path = "/path",
438 params = "params",
439 query = "query",
440 fragment = "fragment"
441}
442
443check_build_url {
444 url = "scheme://user:password@host:port/path;params?query#fragment",
445 scheme = "scheme",
446 authority = "user:password@host:port",
447 path = "/path",
448 params = "params",
449 query = "query",
450 fragment = "fragment"
451}
452
309-- standard RFC tests 453-- standard RFC tests
310print("testing absolute resolution") 454print("testing absolute resolution")
311check_absolute_url("http://a/b/c/d;p?q#f", "g:h", "g:h") 455check_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")
369check_protect({ "/eu>", "<diego?" }, "%2feu%3e/%3cdiego%3f") 513check_protect({ "/eu>", "<diego?" }, "%2feu%3e/%3cdiego%3f")
370check_protect({ "\\eu]", "[diego`" }, "%5ceu%5d/%5bdiego%60") 514check_protect({ "\\eu]", "[diego`" }, "%5ceu%5d/%5bdiego%60")
371check_protect({ "{eu}", "|diego\127" }, "%7beu%7d/%7cdiego%7f") 515check_protect({ "{eu}", "|diego\127" }, "%7beu%7d/%7cdiego%7f")
516check_protect({ "eu ", "~diego" }, "eu /~diego", 1)
517check_protect({ "/eu>", "<diego?" }, "/eu>/<diego?", 1)
518check_protect({ "\\eu]", "[diego`" }, "\\eu]/[diego`", 1)
519check_protect({ "{eu}", "|diego\127" }, "{eu}/|diego\127", 1)
372 520
373print("testing inversion") 521print("testing inversion")
374check_invert("http:") 522check_invert("http:")