test1404 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <testcase>
  2. # Based on test 1315
  3. <info>
  4. <keywords>
  5. HTTP
  6. HTTP FORMPOST
  7. HTTP file upload
  8. --libcurl
  9. </keywords>
  10. </info>
  11. # Server-side
  12. <reply>
  13. <data>
  14. HTTP/1.1 200 OK
  15. Date: Thu, 29 Jul 2008 14:49:00 GMT
  16. Server: test-server/fake
  17. Content-Length: 0
  18. Connection: close
  19. </data>
  20. </reply>
  21. # Client-side
  22. <client>
  23. <features>
  24. Mime
  25. </features>
  26. <server>
  27. http
  28. </server>
  29. <name>
  30. --libcurl for HTTP RFC1867-type formposting - -F with 3 files, one with explicit type & encoder
  31. </name>
  32. <setenv>
  33. SSL_CERT_FILE=
  34. </setenv>
  35. <command>
  36. http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER -F name=value -F 'file=@%LOGDIR/test%TESTNUMBER.txt,%LOGDIR/test%TESTNUMBER.txt;type=magic/content;encoder=8bit,%LOGDIR/test%TESTNUMBER.txt;headers=X-testheader-1: header 1;headers=X-testheader-2: header 2' --libcurl %LOGDIR/test%TESTNUMBER.c
  37. </command>
  38. # We create this file before the command is invoked!
  39. <file name="%LOGDIR/test%TESTNUMBER.txt">
  40. dummy data
  41. </file>
  42. </client>
  43. # Verify data after the test has been "shot"
  44. <verify>
  45. <strip>
  46. -----+\w+
  47. </strip>
  48. <protocol>
  49. POST /we/want/%TESTNUMBER HTTP/1.1
  50. Host: %HOSTIP:%HTTPPORT
  51. User-Agent: curl/%VERSION
  52. Accept: */*
  53. Content-Length: 930
  54. Content-Type: multipart/form-data; boundary=----------------------------9ef8d6205763
  55. ------------------------------9ef8d6205763
  56. Content-Disposition: form-data; name="name"
  57. value
  58. ------------------------------9ef8d6205763
  59. Content-Disposition: form-data; name="file"
  60. Content-Type: multipart/mixed; boundary=----------------------------aaaaaaaaaaaa
  61. Content-Disposition: attachment; filename="test%TESTNUMBER.txt"
  62. Content-Type: text/plain
  63. dummy data
  64. ------------------------------9ef8d6205763
  65. Content-Disposition: attachment; filename="test%TESTNUMBER.txt"
  66. Content-Type: magic/content
  67. Content-Transfer-Encoding: 8bit
  68. dummy data
  69. ------------------------------9ef8d6205763
  70. Content-Disposition: attachment; filename="test%TESTNUMBER.txt"
  71. Content-Type: text/plain
  72. X-testheader-1: header 1
  73. X-testheader-2: header 2
  74. dummy data
  75. ------------------------------aaaaaaaaaaaa--
  76. ------------------------------9ef8d6205763--
  77. </protocol>
  78. <stripfile>
  79. # curl's default user-agent varies with version, libraries etc.
  80. s/(USERAGENT, \")[^\"]+/${1}stripped/
  81. # CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
  82. # configurations - just ignore them
  83. $_ = '' if /CURLOPT_SSL_VERIFYPEER/
  84. $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
  85. $_ = '' if /CURLOPT_HTTP_VERSION/
  86. $_ = '' if /CURLOPT_INTERLEAVEDATA/
  87. # CURL_DOES_CONVERSION generates an extra comment.
  88. $_ = '' if /\/\* "value" \*\//
  89. </stripfile>
  90. <file name="%LOGDIR/test%TESTNUMBER.c" mode="text">
  91. /********* Sample code generated by the curl command line tool **********
  92. * All curl_easy_setopt() options are documented at:
  93. * https://curl.se/libcurl/c/curl_easy_setopt.html
  94. ************************************************************************/
  95. #include <curl/curl.h>
  96. int main(int argc, char *argv[])
  97. {
  98. CURLcode ret;
  99. CURL *hnd;
  100. curl_mime *mime1;
  101. curl_mimepart *part1;
  102. curl_mime *mime2;
  103. curl_mimepart *part2;
  104. struct curl_slist *slist1;
  105. mime1 = NULL;
  106. mime2 = NULL;
  107. slist1 = NULL;
  108. slist1 = curl_slist_append(slist1, "X-testheader-1: header 1");
  109. slist1 = curl_slist_append(slist1, "X-testheader-2: header 2");
  110. hnd = curl_easy_init();
  111. curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
  112. curl_easy_setopt(hnd, CURLOPT_URL, "http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER");
  113. mime1 = curl_mime_init(hnd);
  114. part1 = curl_mime_addpart(mime1);
  115. curl_mime_data(part1, "value", CURL_ZERO_TERMINATED);
  116. curl_mime_name(part1, "name");
  117. part1 = curl_mime_addpart(mime1);
  118. mime2 = curl_mime_init(hnd);
  119. part2 = curl_mime_addpart(mime2);
  120. curl_mime_filedata(part2, "%LOGDIR/test%TESTNUMBER.txt");
  121. part2 = curl_mime_addpart(mime2);
  122. curl_mime_filedata(part2, "%LOGDIR/test%TESTNUMBER.txt");
  123. curl_mime_encoder(part2, "8bit");
  124. curl_mime_type(part2, "magic/content");
  125. part2 = curl_mime_addpart(mime2);
  126. curl_mime_filedata(part2, "%LOGDIR/test%TESTNUMBER.txt");
  127. curl_mime_headers(part2, slist1, 1);
  128. slist1 = NULL;
  129. curl_mime_subparts(part1, mime2);
  130. mime2 = NULL;
  131. curl_mime_name(part1, "file");
  132. curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime1);
  133. curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped");
  134. curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
  135. curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
  136. %if ftp
  137. curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L);
  138. %endif
  139. curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
  140. /* Here is a list of options the curl code used that cannot get generated
  141. as source easily. You may choose to either not use them or implement
  142. them yourself.
  143. CURLOPT_WRITEDATA was set to an object pointer
  144. CURLOPT_WRITEFUNCTION was set to a function pointer
  145. CURLOPT_READDATA was set to an object pointer
  146. CURLOPT_READFUNCTION was set to a function pointer
  147. CURLOPT_SEEKDATA was set to an object pointer
  148. CURLOPT_SEEKFUNCTION was set to a function pointer
  149. CURLOPT_ERRORBUFFER was set to an object pointer
  150. CURLOPT_STDERR was set to an object pointer
  151. CURLOPT_DEBUGFUNCTION was set to a function pointer
  152. CURLOPT_DEBUGDATA was set to an object pointer
  153. CURLOPT_HEADERFUNCTION was set to a function pointer
  154. CURLOPT_HEADERDATA was set to an object pointer
  155. */
  156. ret = curl_easy_perform(hnd);
  157. curl_easy_cleanup(hnd);
  158. hnd = NULL;
  159. curl_mime_free(mime1);
  160. mime1 = NULL;
  161. curl_mime_free(mime2);
  162. mime2 = NULL;
  163. curl_slist_free_all(slist1);
  164. slist1 = NULL;
  165. return (int)ret;
  166. }
  167. /**** End of sample code ****/
  168. </file>
  169. </verify>
  170. </testcase>