diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-02-09 13:51:53 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-02-09 13:51:53 +0100 |
commit | f6ee589dc9adca8fdb1838fa472a7ccc64bc293c (patch) | |
tree | 0a315ebc14ead188c447a620830fe6e0459ab464 | |
parent | d640ad8212caf6223ce164fa627864875da4eae1 (diff) | |
download | libmicrohttpd-f6ee589dc9adca8fdb1838fa472a7ccc64bc293c.tar.gz libmicrohttpd-f6ee589dc9adca8fdb1838fa472a7ccc64bc293c.zip |
add test for &-URI parsing and URI logging
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/testcurl/test_get.c | 94 |
2 files changed, 82 insertions, 16 deletions
@@ -1,3 +1,7 @@ | |||
1 | Sat 09 Feb 2019 01:51:02 PM CET | ||
2 | Extended test_get to test URI logging and query string parsing | ||
3 | to avoid regression fixed in previous patch in the future. -CG | ||
4 | |||
1 | Thu Feb 7 16:16:12 CET 2019 | 5 | Thu Feb 7 16:16:12 CET 2019 |
2 | Preliminary patch for the raw query string issue, to be tested. -CG | 6 | Preliminary patch for the raw query string issue, to be tested. -CG |
3 | 7 | ||
diff --git a/src/testcurl/test_get.c b/src/testcurl/test_get.c index cb81283f..7e4fd4c6 100644 --- a/src/testcurl/test_get.c +++ b/src/testcurl/test_get.c | |||
@@ -35,6 +35,8 @@ | |||
35 | #include "mhd_sockets.h" /* only macros used */ | 35 | #include "mhd_sockets.h" /* only macros used */ |
36 | 36 | ||
37 | 37 | ||
38 | #define EXPECTED_URI_PATH "/hello_world?a=%26&b=c" | ||
39 | |||
38 | #ifdef _WIN32 | 40 | #ifdef _WIN32 |
39 | #ifndef WIN32_LEAN_AND_MEAN | 41 | #ifndef WIN32_LEAN_AND_MEAN |
40 | #define WIN32_LEAN_AND_MEAN 1 | 42 | #define WIN32_LEAN_AND_MEAN 1 |
@@ -64,6 +66,7 @@ struct CBC | |||
64 | size_t size; | 66 | size_t size; |
65 | }; | 67 | }; |
66 | 68 | ||
69 | |||
67 | static size_t | 70 | static size_t |
68 | copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) | 71 | copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) |
69 | { | 72 | { |
@@ -76,6 +79,24 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) | |||
76 | return size * nmemb; | 79 | return size * nmemb; |
77 | } | 80 | } |
78 | 81 | ||
82 | |||
83 | static void * | ||
84 | log_cb (void *cls, | ||
85 | const char *uri, | ||
86 | struct MHD_Connection *con) | ||
87 | { | ||
88 | if (0 != strcmp (uri, | ||
89 | EXPECTED_URI_PATH)) | ||
90 | { | ||
91 | fprintf (stderr, | ||
92 | "Wrong URI: `%s'\n", | ||
93 | uri); | ||
94 | abort (); | ||
95 | } | ||
96 | return NULL; | ||
97 | } | ||
98 | |||
99 | |||
79 | static int | 100 | static int |
80 | ahc_echo (void *cls, | 101 | ahc_echo (void *cls, |
81 | struct MHD_Connection *connection, | 102 | struct MHD_Connection *connection, |
@@ -89,7 +110,10 @@ ahc_echo (void *cls, | |||
89 | const char *me = cls; | 110 | const char *me = cls; |
90 | struct MHD_Response *response; | 111 | struct MHD_Response *response; |
91 | int ret; | 112 | int ret; |
92 | (void)version;(void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ | 113 | const char *v; |
114 | (void) version; | ||
115 | (void) upload_data; | ||
116 | (void) upload_data_size; /* Unused. Silence compiler warning. */ | ||
93 | 117 | ||
94 | if (0 != strcasecmp (me, method)) | 118 | if (0 != strcasecmp (me, method)) |
95 | return MHD_NO; /* unexpected method */ | 119 | return MHD_NO; /* unexpected method */ |
@@ -99,10 +123,26 @@ ahc_echo (void *cls, | |||
99 | return MHD_YES; | 123 | return MHD_YES; |
100 | } | 124 | } |
101 | *unused = NULL; | 125 | *unused = NULL; |
126 | v = MHD_lookup_connection_value (connection, | ||
127 | MHD_GET_ARGUMENT_KIND, | ||
128 | "a"); | ||
129 | if ( (NULL == v) || | ||
130 | (0 != strcmp ("&", | ||
131 | v)) ) | ||
132 | abort (); | ||
133 | v = MHD_lookup_connection_value (connection, | ||
134 | MHD_GET_ARGUMENT_KIND, | ||
135 | "b"); | ||
136 | if ( (NULL == v) || | ||
137 | (0 != strcmp ("c", | ||
138 | v)) ) | ||
139 | abort (); | ||
102 | response = MHD_create_response_from_buffer (strlen (url), | 140 | response = MHD_create_response_from_buffer (strlen (url), |
103 | (void *) url, | 141 | (void *) url, |
104 | MHD_RESPMEM_MUST_COPY); | 142 | MHD_RESPMEM_MUST_COPY); |
105 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 143 | ret = MHD_queue_response (connection, |
144 | MHD_HTTP_OK, | ||
145 | response); | ||
106 | MHD_destroy_response (response); | 146 | MHD_destroy_response (response); |
107 | if (ret == MHD_NO) | 147 | if (ret == MHD_NO) |
108 | abort (); | 148 | abort (); |
@@ -131,7 +171,10 @@ testInternalGet (int poll_flag) | |||
131 | cbc.size = 2048; | 171 | cbc.size = 2048; |
132 | cbc.pos = 0; | 172 | cbc.pos = 0; |
133 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 173 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, |
134 | global_port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 174 | global_port, NULL, NULL, |
175 | &ahc_echo, "GET", | ||
176 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | ||
177 | MHD_OPTION_END); | ||
135 | if (d == NULL) | 178 | if (d == NULL) |
136 | return 1; | 179 | return 1; |
137 | if (0 == global_port) | 180 | if (0 == global_port) |
@@ -143,7 +186,7 @@ testInternalGet (int poll_flag) | |||
143 | global_port = (int)dinfo->port; | 186 | global_port = (int)dinfo->port; |
144 | } | 187 | } |
145 | c = curl_easy_init (); | 188 | c = curl_easy_init (); |
146 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 189 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); |
147 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); | 190 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); |
148 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 191 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
149 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 192 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
@@ -198,7 +241,10 @@ testMultithreadedGet (int poll_flag) | |||
198 | cbc.size = 2048; | 241 | cbc.size = 2048; |
199 | cbc.pos = 0; | 242 | cbc.pos = 0; |
200 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 243 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, |
201 | global_port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 244 | global_port, NULL, NULL, |
245 | &ahc_echo, "GET", | ||
246 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | ||
247 | MHD_OPTION_END); | ||
202 | if (d == NULL) | 248 | if (d == NULL) |
203 | return 16; | 249 | return 16; |
204 | if (0 == global_port) | 250 | if (0 == global_port) |
@@ -210,7 +256,7 @@ testMultithreadedGet (int poll_flag) | |||
210 | global_port = (int)dinfo->port; | 256 | global_port = (int)dinfo->port; |
211 | } | 257 | } |
212 | c = curl_easy_init (); | 258 | c = curl_easy_init (); |
213 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 259 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); |
214 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); | 260 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); |
215 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 261 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
216 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 262 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
@@ -265,8 +311,11 @@ testMultithreadedPoolGet (int poll_flag) | |||
265 | cbc.size = 2048; | 311 | cbc.size = 2048; |
266 | cbc.pos = 0; | 312 | cbc.pos = 0; |
267 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 313 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, |
268 | global_port, NULL, NULL, &ahc_echo, "GET", | 314 | global_port, NULL, NULL, |
269 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); | 315 | &ahc_echo, "GET", |
316 | MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, | ||
317 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | ||
318 | MHD_OPTION_END); | ||
270 | if (d == NULL) | 319 | if (d == NULL) |
271 | return 16; | 320 | return 16; |
272 | if (0 == global_port) | 321 | if (0 == global_port) |
@@ -278,7 +327,7 @@ testMultithreadedPoolGet (int poll_flag) | |||
278 | global_port = (int)dinfo->port; | 327 | global_port = (int)dinfo->port; |
279 | } | 328 | } |
280 | c = curl_easy_init (); | 329 | c = curl_easy_init (); |
281 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 330 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); |
282 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); | 331 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); |
283 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 332 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
284 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 333 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
@@ -348,7 +397,10 @@ testExternalGet () | |||
348 | cbc.size = 2048; | 397 | cbc.size = 2048; |
349 | cbc.pos = 0; | 398 | cbc.pos = 0; |
350 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, | 399 | d = MHD_start_daemon (MHD_USE_ERROR_LOG, |
351 | global_port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 400 | global_port, NULL, NULL, |
401 | &ahc_echo, "GET", | ||
402 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | ||
403 | MHD_OPTION_END); | ||
352 | if (d == NULL) | 404 | if (d == NULL) |
353 | return 256; | 405 | return 256; |
354 | if (0 == global_port) | 406 | if (0 == global_port) |
@@ -360,7 +412,7 @@ testExternalGet () | |||
360 | global_port = (int)dinfo->port; | 412 | global_port = (int)dinfo->port; |
361 | } | 413 | } |
362 | c = curl_easy_init (); | 414 | c = curl_easy_init (); |
363 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 415 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); |
364 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); | 416 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); |
365 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 417 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
366 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 418 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
@@ -494,6 +546,7 @@ testUnknownPortGet (int poll_flag) | |||
494 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 546 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, |
495 | 0, NULL, NULL, &ahc_echo, "GET", | 547 | 0, NULL, NULL, &ahc_echo, "GET", |
496 | MHD_OPTION_SOCK_ADDR, &addr, | 548 | MHD_OPTION_SOCK_ADDR, &addr, |
549 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | ||
497 | MHD_OPTION_END); | 550 | MHD_OPTION_END); |
498 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 551 | if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
499 | { | 552 | { |
@@ -517,8 +570,11 @@ testUnknownPortGet (int poll_flag) | |||
517 | port = (int)dinfo->port; | 570 | port = (int)dinfo->port; |
518 | } | 571 | } |
519 | 572 | ||
520 | snprintf(buf, sizeof(buf), "http://127.0.0.1:%d/hello_world", | 573 | snprintf(buf, |
521 | port); | 574 | sizeof(buf), |
575 | "http://127.0.0.1:%d%s", | ||
576 | port, | ||
577 | EXPECTED_URI_PATH); | ||
522 | 578 | ||
523 | c = curl_easy_init (); | 579 | c = curl_easy_init (); |
524 | curl_easy_setopt (c, CURLOPT_URL, buf); | 580 | curl_easy_setopt (c, CURLOPT_URL, buf); |
@@ -570,7 +626,10 @@ testStopRace (int poll_flag) | |||
570 | } | 626 | } |
571 | 627 | ||
572 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 628 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, |
573 | global_port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 629 | global_port, NULL, NULL, |
630 | &ahc_echo, "GET", | ||
631 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | ||
632 | MHD_OPTION_END); | ||
574 | if (d == NULL) | 633 | if (d == NULL) |
575 | return 16; | 634 | return 16; |
576 | if (0 == global_port) | 635 | if (0 == global_port) |
@@ -686,7 +745,10 @@ testEmptyGet (int poll_flag) | |||
686 | cbc.size = 2048; | 745 | cbc.size = 2048; |
687 | cbc.pos = 0; | 746 | cbc.pos = 0; |
688 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, | 747 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag, |
689 | global_port, NULL, NULL, &ahc_empty, NULL, MHD_OPTION_END); | 748 | global_port, NULL, NULL, |
749 | &ahc_empty, NULL, | ||
750 | MHD_OPTION_URI_LOG_CALLBACK, &log_cb, NULL, | ||
751 | MHD_OPTION_END); | ||
690 | if (d == NULL) | 752 | if (d == NULL) |
691 | return 4194304; | 753 | return 4194304; |
692 | if (0 == global_port) | 754 | if (0 == global_port) |
@@ -698,7 +760,7 @@ testEmptyGet (int poll_flag) | |||
698 | global_port = (int)dinfo->port; | 760 | global_port = (int)dinfo->port; |
699 | } | 761 | } |
700 | c = curl_easy_init (); | 762 | c = curl_easy_init (); |
701 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 763 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1" EXPECTED_URI_PATH); |
702 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); | 764 | curl_easy_setopt (c, CURLOPT_PORT, (long)global_port); |
703 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 765 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
704 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 766 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |