quickjs-tart

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

lib661.c (5719B)


      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) 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.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  * SPDX-License-Identifier: curl
     22  *
     23  ***************************************************************************/
     24 #include "first.h"
     25 
     26 #include "memdebug.h"
     27 
     28 static CURLcode test_lib661(char *URL)
     29 {
     30    CURLcode res;
     31    CURL *curl = NULL;
     32    char *newURL = NULL;
     33    struct curl_slist *slist = NULL;
     34 
     35    if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
     36      curl_mfprintf(stderr, "curl_global_init() failed\n");
     37      return TEST_ERR_MAJOR_BAD;
     38    }
     39 
     40    curl = curl_easy_init();
     41    if(!curl) {
     42      curl_mfprintf(stderr, "curl_easy_init() failed\n");
     43      res = TEST_ERR_MAJOR_BAD;
     44      goto test_cleanup;
     45    }
     46 
     47    /* test: CURLFTPMETHOD_SINGLECWD with absolute path should
     48             skip CWD to entry path */
     49    newURL = curl_maprintf("%s/folderA/661", URL);
     50    test_setopt(curl, CURLOPT_URL, newURL);
     51    test_setopt(curl, CURLOPT_VERBOSE, 1L);
     52    test_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L);
     53    test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
     54    res = curl_easy_perform(curl);
     55    if(res != CURLE_REMOTE_FILE_NOT_FOUND)
     56      goto test_cleanup;
     57 
     58    curl_free(newURL);
     59    newURL = curl_maprintf("%s/folderB/661", URL);
     60    test_setopt(curl, CURLOPT_URL, newURL);
     61    res = curl_easy_perform(curl);
     62    if(res != CURLE_REMOTE_FILE_NOT_FOUND)
     63      goto test_cleanup;
     64 
     65    /* test: CURLFTPMETHOD_NOCWD with absolute path should
     66       never emit CWD (for both new and reused easy handle) */
     67    curl_easy_cleanup(curl);
     68    curl = curl_easy_init();
     69    if(!curl) {
     70      curl_mfprintf(stderr, "curl_easy_init() failed\n");
     71      res = TEST_ERR_MAJOR_BAD;
     72      goto test_cleanup;
     73    }
     74 
     75    curl_free(newURL);
     76    newURL = curl_maprintf("%s/folderA/661", URL);
     77    test_setopt(curl, CURLOPT_URL, newURL);
     78    test_setopt(curl, CURLOPT_VERBOSE, 1L);
     79    test_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L);
     80    test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
     81    res = curl_easy_perform(curl);
     82    if(res != CURLE_REMOTE_FILE_NOT_FOUND)
     83      goto test_cleanup;
     84 
     85    /* curve ball: CWD /folderB before reusing connection with _NOCWD */
     86    curl_free(newURL);
     87    newURL = curl_maprintf("%s/folderB/661", URL);
     88    test_setopt(curl, CURLOPT_URL, newURL);
     89    test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
     90    res = curl_easy_perform(curl);
     91    if(res != CURLE_REMOTE_FILE_NOT_FOUND)
     92      goto test_cleanup;
     93 
     94    curl_free(newURL);
     95    newURL = curl_maprintf("%s/folderA/661", URL);
     96    test_setopt(curl, CURLOPT_URL, newURL);
     97    test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
     98    res = curl_easy_perform(curl);
     99    if(res != CURLE_REMOTE_FILE_NOT_FOUND)
    100      goto test_cleanup;
    101 
    102    /* test: CURLFTPMETHOD_NOCWD with home-relative path should
    103       not emit CWD for first FTP access after login */
    104    curl_easy_cleanup(curl);
    105    curl = curl_easy_init();
    106    if(!curl) {
    107      curl_mfprintf(stderr, "curl_easy_init() failed\n");
    108      res = TEST_ERR_MAJOR_BAD;
    109      goto test_cleanup;
    110    }
    111 
    112    slist = curl_slist_append(NULL, "SYST");
    113    if(!slist) {
    114      curl_mfprintf(stderr, "curl_slist_append() failed\n");
    115      res = TEST_ERR_MAJOR_BAD;
    116      goto test_cleanup;
    117    }
    118 
    119    test_setopt(curl, CURLOPT_URL, URL);
    120    test_setopt(curl, CURLOPT_VERBOSE, 1L);
    121    test_setopt(curl, CURLOPT_NOBODY, 1L);
    122    test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
    123    test_setopt(curl, CURLOPT_QUOTE, slist);
    124    res = curl_easy_perform(curl);
    125    if(res)
    126      goto test_cleanup;
    127 
    128    /* test: CURLFTPMETHOD_SINGLECWD with home-relative path should
    129       not emit CWD for first FTP access after login */
    130    curl_easy_cleanup(curl);
    131    curl = curl_easy_init();
    132    if(!curl) {
    133      curl_mfprintf(stderr, "curl_easy_init() failed\n");
    134      res = TEST_ERR_MAJOR_BAD;
    135      goto test_cleanup;
    136    }
    137 
    138    test_setopt(curl, CURLOPT_URL, URL);
    139    test_setopt(curl, CURLOPT_VERBOSE, 1L);
    140    test_setopt(curl, CURLOPT_NOBODY, 1L);
    141    test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
    142    test_setopt(curl, CURLOPT_QUOTE, slist);
    143    res = curl_easy_perform(curl);
    144    if(res)
    145      goto test_cleanup;
    146 
    147    /* test: CURLFTPMETHOD_NOCWD with home-relative path should
    148       not emit CWD for second FTP access when not needed +
    149       bonus: see if path buffering survives curl_easy_reset() */
    150    curl_easy_reset(curl);
    151    test_setopt(curl, CURLOPT_URL, URL);
    152    test_setopt(curl, CURLOPT_VERBOSE, 1L);
    153    test_setopt(curl, CURLOPT_NOBODY, 1L);
    154    test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
    155    test_setopt(curl, CURLOPT_QUOTE, slist);
    156    res = curl_easy_perform(curl);
    157 
    158 test_cleanup:
    159 
    160    if(res)
    161      curl_mfprintf(stderr, "test encountered error %d\n", res);
    162    curl_slist_free_all(slist);
    163    curl_free(newURL);
    164    curl_easy_cleanup(curl);
    165    curl_global_cleanup();
    166 
    167    return res;
    168 }