Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

135 lignes
5.5 KiB

il y a 13 ans
il y a 13 ans
il y a 13 ans
il y a 13 ans
  1. %%% File : ibrowse_lib.erl
  2. %%% Authors : Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>,
  3. %%% Filipe David Manana <fdmanana@apache.org>
  4. %%% Description : Tests for the module ibrowse_lib.erl
  5. %%% Created : 12 April 2011 by Filipe David Manana <fdmanana@apache.org>
  6. -module(ibrowse_lib_tests).
  7. -include_lib("eunit/include/eunit.hrl").
  8. -include("../include/ibrowse.hrl").
  9. parse_urls_test_() ->
  10. {timeout, 60, [fun parse_urls/0]}.
  11. parse_urls() ->
  12. ?assertMatch(#url{
  13. abspath = "http://localhost",
  14. host = "localhost",
  15. host_type = hostname,
  16. port = 80,
  17. path = "/",
  18. username = undefined,
  19. password = undefined,
  20. protocol = http
  21. },
  22. ibrowse_lib:parse_url("http://localhost")),
  23. ?assertMatch(#url{
  24. abspath = "http://localhost:80/",
  25. host = "localhost",
  26. host_type = hostname,
  27. port = 80,
  28. path = "/",
  29. username = undefined,
  30. password = undefined,
  31. protocol = http
  32. },
  33. ibrowse_lib:parse_url("http://localhost:80/")),
  34. ?assertMatch(#url{
  35. abspath = "http://127.0.0.1:8000/",
  36. host = "127.0.0.1",
  37. host_type = ipv4_address,
  38. port = 8000,
  39. path = "/",
  40. username = undefined,
  41. password = undefined,
  42. protocol = http
  43. },
  44. ibrowse_lib:parse_url("http://127.0.0.1:8000/")),
  45. ?assertMatch(#url{
  46. abspath = "https://foo:bar@127.0.0.1:8000/test",
  47. host = "127.0.0.1",
  48. host_type = ipv4_address,
  49. port = 8000,
  50. path = "/test",
  51. username = "foo",
  52. password = "bar",
  53. protocol = https
  54. },
  55. ibrowse_lib:parse_url("https://foo:bar@127.0.0.1:8000/test")),
  56. ?assertMatch(#url{
  57. abspath = "https://[::1]",
  58. host = "::1",
  59. host_type = ipv6_address,
  60. port = 443,
  61. path = "/",
  62. username = undefined,
  63. password = undefined,
  64. protocol = https
  65. },
  66. ibrowse_lib:parse_url("https://[::1]")),
  67. ?assertMatch(#url{
  68. abspath = "http://[::1]:8080",
  69. host = "::1",
  70. host_type = ipv6_address,
  71. port = 8080,
  72. path = "/",
  73. username = undefined,
  74. password = undefined,
  75. protocol = http
  76. },
  77. ibrowse_lib:parse_url("http://[::1]:8080")),
  78. ?assertMatch(#url{
  79. abspath = "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8081/index.html",
  80. host = "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210",
  81. host_type = ipv6_address,
  82. port = 8081,
  83. path = "/index.html",
  84. username = undefined,
  85. password = undefined,
  86. protocol = http
  87. },
  88. ibrowse_lib:parse_url("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8081/index.html")),
  89. ?assertMatch(#url{
  90. abspath = "http://[1080:0:0:0:8:800:200C:417A]/foo/bar",
  91. host = "1080:0:0:0:8:800:200C:417A",
  92. host_type = ipv6_address,
  93. port = 80,
  94. path = "/foo/bar",
  95. username = undefined,
  96. password = undefined,
  97. protocol = http
  98. },
  99. ibrowse_lib:parse_url("http://[1080:0:0:0:8:800:200C:417A]/foo/bar")),
  100. ?assertMatch(#url{
  101. abspath = "http://[1080:0:0:0:8:800:200C:417A]:8080/foo/bar",
  102. host = "1080:0:0:0:8:800:200C:417A",
  103. host_type = ipv6_address,
  104. port = 8080,
  105. path = "/foo/bar",
  106. username = undefined,
  107. password = undefined,
  108. protocol = http
  109. },
  110. ibrowse_lib:parse_url("http://[1080:0:0:0:8:800:200C:417A]:8080/foo/bar")),
  111. ?assertMatch(#url{
  112. abspath = "http://[::192.9.5.5]:6000/foo?q=bar",
  113. host = "::192.9.5.5",
  114. host_type = ipv6_address,
  115. port = 6000,
  116. path = "/foo?q=bar",
  117. username = undefined,
  118. password = undefined,
  119. protocol = http
  120. },
  121. ibrowse_lib:parse_url("http://[::192.9.5.5]:6000/foo?q=bar")),
  122. ?assertMatch({error, invalid_uri},
  123. ibrowse_lib:parse_url("http://[:1080:0:0:0:8:800:200C:417A:]:6000/foo?q=bar")),
  124. ?assertMatch({error, invalid_uri},
  125. ibrowse_lib:parse_url("http://[12::z]")),
  126. ?assertMatch({error, invalid_uri},
  127. ibrowse_lib:parse_url("http://foo[1080:0:0:0:8:800:200C:417A]:6000")),
  128. ?assertMatch({error, invalid_uri},
  129. ibrowse_lib:parse_url("http://foo:[1080:0:0:0:8:800:200C:417A]:6000")),
  130. ok.