2
0

testuri.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include "testutil.h"
  19. #include "apr_general.h"
  20. #include "apr_strings.h"
  21. #include "apr_uri.h"
  22. struct aup_test {
  23. const char *uri;
  24. apr_status_t rv;
  25. const char *scheme;
  26. const char *hostinfo;
  27. const char *user;
  28. const char *password;
  29. const char *hostname;
  30. const char *port_str;
  31. const char *path;
  32. const char *query;
  33. const char *fragment;
  34. apr_port_t port;
  35. };
  36. struct aup_test aup_tests[] =
  37. {
  38. { "http://[/::1]/index.html", APR_EGENERAL },
  39. { "http://[", APR_EGENERAL },
  40. { "http://[?::1]/index.html", APR_EGENERAL },
  41. {
  42. "http://127.0.0.1:9999/asdf.html",
  43. 0, "http", "127.0.0.1:9999", NULL, NULL, "127.0.0.1", "9999", "/asdf.html", NULL, NULL, 9999
  44. },
  45. {
  46. "http://127.0.0.1:9999a/asdf.html",
  47. APR_EGENERAL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0
  48. },
  49. {
  50. "http://[::127.0.0.1]:9999/asdf.html",
  51. 0, "http", "[::127.0.0.1]:9999", NULL, NULL, "::127.0.0.1", "9999", "/asdf.html", NULL, NULL, 9999
  52. },
  53. {
  54. "http://[::127.0.0.1]:9999a/asdf.html",
  55. APR_EGENERAL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0
  56. },
  57. {
  58. "/error/include/top.html",
  59. 0, NULL, NULL, NULL, NULL, NULL, NULL, "/error/include/top.html", NULL, NULL, 0
  60. },
  61. {
  62. "/error/include/../contact.html.var",
  63. 0, NULL, NULL, NULL, NULL, NULL, NULL, "/error/include/../contact.html.var", NULL, NULL, 0
  64. },
  65. {
  66. "/",
  67. 0, NULL, NULL, NULL, NULL, NULL, NULL, "/", NULL, NULL, 0
  68. },
  69. {
  70. "/manual/",
  71. 0, NULL, NULL, NULL, NULL, NULL, NULL, "/manual/", NULL, NULL, 0
  72. },
  73. {
  74. "/cocoon/developing/graphics/Using%20Databases-label_over.jpg",
  75. 0, NULL, NULL, NULL, NULL, NULL, NULL, "/cocoon/developing/graphics/Using%20Databases-label_over.jpg", NULL, NULL, 0
  76. },
  77. {
  78. "http://sonyamt:garbage@127.0.0.1/filespace/",
  79. 0, "http", "sonyamt:garbage@127.0.0.1", "sonyamt", "garbage", "127.0.0.1", NULL, "/filespace/", NULL, NULL, 0
  80. },
  81. {
  82. "http://sonyamt:garbage@[fe80::1]/filespace/",
  83. 0, "http", "sonyamt:garbage@[fe80::1]", "sonyamt", "garbage", "fe80::1", NULL, "/filespace/", NULL, NULL, 0
  84. },
  85. {
  86. "http://sonyamt@[fe80::1]/filespace/?arg1=store",
  87. 0, "http", "sonyamt@[fe80::1]", "sonyamt", NULL, "fe80::1", NULL, "/filespace/", "arg1=store", NULL, 0
  88. },
  89. {
  90. "//www.apache.org/",
  91. 0, NULL, "www.apache.org", NULL, NULL, "www.apache.org", NULL, "/", NULL, NULL, 0
  92. },
  93. };
  94. struct uph_test {
  95. const char *hostinfo;
  96. apr_status_t rv;
  97. const char *hostname;
  98. const char *port_str;
  99. apr_port_t port;
  100. };
  101. struct uph_test uph_tests[] =
  102. {
  103. {
  104. "www.ibm.com:443",
  105. 0, "www.ibm.com", "443", 443
  106. },
  107. {
  108. "[fe80::1]:443",
  109. 0, "fe80::1", "443", 443
  110. },
  111. {
  112. "127.0.0.1:443",
  113. 0, "127.0.0.1", "443", 443
  114. },
  115. {
  116. "127.0.0.1",
  117. APR_EGENERAL, NULL, NULL, 0
  118. },
  119. {
  120. "[fe80:80",
  121. APR_EGENERAL, NULL, NULL, 0
  122. },
  123. {
  124. "fe80::80]:443",
  125. APR_EGENERAL, NULL, NULL, 0
  126. }
  127. };
  128. #if 0
  129. static void show_info(apr_status_t rv, apr_status_t expected, const apr_uri_t *info)
  130. {
  131. if (rv != expected) {
  132. fprintf(stderr, " actual rv: %d expected rv: %d\n", rv, expected);
  133. }
  134. else {
  135. fprintf(stderr,
  136. " scheme: %s\n"
  137. " hostinfo: %s\n"
  138. " user: %s\n"
  139. " password: %s\n"
  140. " hostname: %s\n"
  141. " port_str: %s\n"
  142. " path: %s\n"
  143. " query: %s\n"
  144. " fragment: %s\n"
  145. " hostent: %p\n"
  146. " port: %u\n"
  147. " is_initialized: %u\n"
  148. " dns_looked_up: %u\n"
  149. " dns_resolved: %u\n",
  150. info->scheme, info->hostinfo, info->user, info->password,
  151. info->hostname, info->port_str, info->path, info->query,
  152. info->fragment, info->hostent, info->port, info->is_initialized,
  153. info->dns_looked_up, info->dns_resolved);
  154. }
  155. }
  156. #endif
  157. static void test_aup(abts_case *tc, void *data)
  158. {
  159. int i;
  160. apr_status_t rv;
  161. apr_uri_t info;
  162. struct aup_test *t;
  163. const char *s = NULL;
  164. for (i = 0; i < sizeof(aup_tests) / sizeof(aup_tests[0]); i++) {
  165. char msg[256];
  166. memset(&info, 0, sizeof(info));
  167. t = &aup_tests[i];
  168. rv = apr_uri_parse(p, t->uri, &info);
  169. apr_snprintf(msg, sizeof msg, "uri '%s': rv=%d not %d", t->uri,
  170. rv, t->rv);
  171. ABTS_ASSERT(tc, msg, rv == t->rv);
  172. if (t->rv == APR_SUCCESS) {
  173. ABTS_STR_EQUAL(tc, info.scheme, t->scheme);
  174. ABTS_STR_EQUAL(tc, info.hostinfo, t->hostinfo);
  175. ABTS_STR_EQUAL(tc, info.user, t->user);
  176. ABTS_STR_EQUAL(tc, info.password, t->password);
  177. ABTS_STR_EQUAL(tc, info.hostname, t->hostname);
  178. ABTS_STR_EQUAL(tc, info.port_str, t->port_str);
  179. ABTS_STR_EQUAL(tc, info.path, t->path);
  180. ABTS_STR_EQUAL(tc, info.query, t->query);
  181. ABTS_STR_EQUAL(tc, info.user, t->user);
  182. ABTS_INT_EQUAL(tc, info.port, t->port);
  183. s = apr_uri_unparse(p, &info, APR_URI_UNP_REVEALPASSWORD);
  184. ABTS_STR_EQUAL(tc, s, t->uri);
  185. }
  186. }
  187. }
  188. static void test_uph(abts_case *tc, void *data)
  189. {
  190. int i;
  191. apr_status_t rv;
  192. apr_uri_t info;
  193. struct uph_test *t;
  194. for (i = 0; i < sizeof(uph_tests) / sizeof(uph_tests[0]); i++) {
  195. memset(&info, 0, sizeof(info));
  196. t = &uph_tests[i];
  197. rv = apr_uri_parse_hostinfo(p, t->hostinfo, &info);
  198. ABTS_INT_EQUAL(tc, rv, t->rv);
  199. if (t->rv == APR_SUCCESS) {
  200. ABTS_STR_EQUAL(tc, info.hostname, t->hostname);
  201. ABTS_STR_EQUAL(tc, info.port_str, t->port_str);
  202. ABTS_INT_EQUAL(tc, info.port, t->port);
  203. }
  204. }
  205. }
  206. abts_suite *testuri(abts_suite *suite)
  207. {
  208. suite = ADD_SUITE(suite);
  209. abts_run_test(suite, test_aup, NULL);
  210. abts_run_test(suite, test_uph, NULL);
  211. return suite;
  212. }