unit1653.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "curlcheck.h"
  23. #include "urldata.h"
  24. #include "curl/urlapi.h"
  25. #include "urlapi-int.h"
  26. static CURLU *u;
  27. static CURLcode
  28. unit_setup(void)
  29. {
  30. return CURLE_OK;
  31. }
  32. static void
  33. unit_stop(void)
  34. {
  35. curl_global_cleanup();
  36. }
  37. #define free_and_clear(x) free(x); x = NULL
  38. UNITTEST_START
  39. {
  40. CURLUcode ret;
  41. char *ipv6port = NULL;
  42. char *portnum;
  43. /* Valid IPv6 */
  44. u = curl_url();
  45. if(!u)
  46. goto fail;
  47. ipv6port = strdup("[fe80::250:56ff:fea7:da15]");
  48. if(!ipv6port)
  49. goto fail;
  50. ret = Curl_parse_port(u, ipv6port);
  51. fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
  52. ret = curl_url_get(u, CURLUPART_PORT, &portnum, CURLU_NO_DEFAULT_PORT);
  53. fail_unless(ret != CURLUE_OK, "curl_url_get portnum returned something");
  54. free_and_clear(ipv6port);
  55. curl_url_cleanup(u);
  56. /* Invalid IPv6 */
  57. u = curl_url();
  58. if(!u)
  59. goto fail;
  60. ipv6port = strdup("[fe80::250:56ff:fea7:da15|");
  61. if(!ipv6port)
  62. goto fail;
  63. ret = Curl_parse_port(u, ipv6port);
  64. fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
  65. free_and_clear(ipv6port);
  66. curl_url_cleanup(u);
  67. u = curl_url();
  68. if(!u)
  69. goto fail;
  70. ipv6port = strdup("[fe80::250:56ff;fea7:da15]:80");
  71. if(!ipv6port)
  72. goto fail;
  73. ret = Curl_parse_port(u, ipv6port);
  74. fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
  75. free_and_clear(ipv6port);
  76. curl_url_cleanup(u);
  77. /* Valid IPv6 with zone index and port number */
  78. u = curl_url();
  79. if(!u)
  80. goto fail;
  81. ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]:80");
  82. if(!ipv6port)
  83. goto fail;
  84. ret = Curl_parse_port(u, ipv6port);
  85. fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
  86. ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
  87. fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
  88. fail_unless(portnum && !strcmp(portnum, "80"), "Check portnumber");
  89. curl_free(portnum);
  90. free_and_clear(ipv6port);
  91. curl_url_cleanup(u);
  92. /* Valid IPv6 with zone index without port number */
  93. u = curl_url();
  94. if(!u)
  95. goto fail;
  96. ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]");
  97. if(!ipv6port)
  98. goto fail;
  99. ret = Curl_parse_port(u, ipv6port);
  100. fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
  101. free_and_clear(ipv6port);
  102. curl_url_cleanup(u);
  103. /* Valid IPv6 with port number */
  104. u = curl_url();
  105. if(!u)
  106. goto fail;
  107. ipv6port = strdup("[fe80::250:56ff:fea7:da15]:81");
  108. if(!ipv6port)
  109. goto fail;
  110. ret = Curl_parse_port(u, ipv6port);
  111. fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
  112. ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
  113. fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
  114. fail_unless(portnum && !strcmp(portnum, "81"), "Check portnumber");
  115. curl_free(portnum);
  116. free_and_clear(ipv6port);
  117. curl_url_cleanup(u);
  118. /* Valid IPv6 with syntax error in the port number */
  119. u = curl_url();
  120. if(!u)
  121. goto fail;
  122. ipv6port = strdup("[fe80::250:56ff:fea7:da15];81");
  123. if(!ipv6port)
  124. goto fail;
  125. ret = Curl_parse_port(u, ipv6port);
  126. fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
  127. free_and_clear(ipv6port);
  128. curl_url_cleanup(u);
  129. u = curl_url();
  130. if(!u)
  131. goto fail;
  132. ipv6port = strdup("[fe80::250:56ff:fea7:da15]80");
  133. if(!ipv6port)
  134. goto fail;
  135. ret = Curl_parse_port(u, ipv6port);
  136. fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
  137. free_and_clear(ipv6port);
  138. curl_url_cleanup(u);
  139. /* Valid IPv6 with no port after the colon, should use default */
  140. u = curl_url();
  141. if(!u)
  142. goto fail;
  143. ipv6port = strdup("[fe80::250:56ff:fea7:da15]:");
  144. if(!ipv6port)
  145. goto fail;
  146. ret = Curl_parse_port(u, ipv6port);
  147. fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
  148. free_and_clear(ipv6port);
  149. curl_url_cleanup(u);
  150. /* Incorrect zone index syntax */
  151. u = curl_url();
  152. if(!u)
  153. goto fail;
  154. ipv6port = strdup("[fe80::250:56ff:fea7:da15!25eth3]:80");
  155. if(!ipv6port)
  156. goto fail;
  157. ret = Curl_parse_port(u, ipv6port);
  158. fail_unless(ret != CURLUE_OK, "Curl_parse_port returned non-error");
  159. free_and_clear(ipv6port);
  160. curl_url_cleanup(u);
  161. /* Non percent-encoded zone index */
  162. u = curl_url();
  163. if(!u)
  164. goto fail;
  165. ipv6port = strdup("[fe80::250:56ff:fea7:da15%eth3]:80");
  166. if(!ipv6port)
  167. goto fail;
  168. ret = Curl_parse_port(u, ipv6port);
  169. fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
  170. fail:
  171. free(ipv6port);
  172. curl_url_cleanup(u);
  173. }
  174. UNITTEST_STOP