quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

test1404 (5456B)


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