diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-09-26 20:29:32 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-09-26 20:29:32 +0000 |
| commit | 6eb7f22c4b23a1b8175222001435fa45d7b570b3 (patch) | |
| tree | a3cade1b39219fed5a5581043db1efca9297cb64 | |
| parent | 4f27c376e9e9aac413ad7b30b683ce08ba16fd1e (diff) | |
| download | luasocket-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.lua | 152 |
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) | |||
| 12 | assert(dofile "../lua/code.lua") | 12 | assert(dofile "../lua/code.lua") |
| 13 | assert(dofile "../lua/url.lua") | 13 | assert(dofile "../lua/url.lua") |
| 14 | 14 | ||
| 15 | local check_protect = function(parsed, path) | 15 | local 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 | ||
| 23 | end | ||
| 24 | |||
| 25 | local 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 | ||
| 319 | print("testing URL building") | ||
| 320 | check_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 | |||
| 333 | check_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 | |||
| 345 | check_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 | |||
| 356 | check_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 | |||
| 366 | check_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 | |||
| 375 | check_build_url { | ||
| 376 | url = "scheme://host/path#fragment", | ||
| 377 | scheme = "scheme", | ||
| 378 | host = "host", | ||
| 379 | path = "/path", | ||
| 380 | fragment = "fragment" | ||
| 381 | } | ||
| 382 | |||
| 383 | check_build_url { | ||
| 384 | url = "scheme://host/path", | ||
| 385 | scheme = "scheme", | ||
| 386 | host = "host", | ||
| 387 | path = "/path", | ||
| 388 | } | ||
| 389 | |||
| 390 | check_build_url { | ||
| 391 | url = "//host/path", | ||
| 392 | host = "host", | ||
| 393 | path = "/path", | ||
| 394 | } | ||
| 395 | |||
| 396 | check_build_url { | ||
| 397 | url = "/path", | ||
| 398 | path = "/path", | ||
| 399 | } | ||
| 400 | |||
| 401 | check_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 | |||
| 415 | check_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 | |||
| 430 | check_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 | |||
| 443 | check_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 |
| 310 | print("testing absolute resolution") | 454 | print("testing absolute resolution") |
| 311 | check_absolute_url("http://a/b/c/d;p?q#f", "g:h", "g:h") | 455 | 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") | |||
| 369 | check_protect({ "/eu>", "<diego?" }, "%2feu%3e/%3cdiego%3f") | 513 | check_protect({ "/eu>", "<diego?" }, "%2feu%3e/%3cdiego%3f") |
| 370 | check_protect({ "\\eu]", "[diego`" }, "%5ceu%5d/%5bdiego%60") | 514 | check_protect({ "\\eu]", "[diego`" }, "%5ceu%5d/%5bdiego%60") |
| 371 | check_protect({ "{eu}", "|diego\127" }, "%7beu%7d/%7cdiego%7f") | 515 | check_protect({ "{eu}", "|diego\127" }, "%7beu%7d/%7cdiego%7f") |
| 516 | check_protect({ "eu ", "~diego" }, "eu /~diego", 1) | ||
| 517 | check_protect({ "/eu>", "<diego?" }, "/eu>/<diego?", 1) | ||
| 518 | check_protect({ "\\eu]", "[diego`" }, "\\eu]/[diego`", 1) | ||
| 519 | check_protect({ "{eu}", "|diego\127" }, "{eu}/|diego\127", 1) | ||
| 372 | 520 | ||
| 373 | print("testing inversion") | 521 | print("testing inversion") |
| 374 | check_invert("http:") | 522 | check_invert("http:") |
