quickjs-tart

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

unit1979.c (4008B)


      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 "unitcheck.h"
     25 
     26 #include "http_aws_sigv4.h"
     27 
     28 static CURLcode test_unit1979(char *arg)
     29 {
     30   UNITTEST_BEGIN_SIMPLE
     31 
     32 #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS)
     33   struct testcase {
     34     const char *testname;
     35     const bool normalize;
     36     const char *url_part;
     37     const char *canonical_url;
     38   };
     39 
     40   static const struct testcase testcases[] = {
     41     {
     42       "test-equals-encode",
     43       true,
     44       "/a=b",
     45       "/a%3Db"
     46     },
     47     {
     48       "test-equals-noencode",
     49       false,
     50       "/a=b",
     51       "/a=b"
     52     },
     53     {
     54       "test-s3-tables",
     55       true,
     56       "/tables/arn%3Aaws%3As3tables%3Aus-east-1%3A022954301426%3Abucket%2Fja"
     57       "soehartablebucket/jasoeharnamespace/jasoehartable/encryption",
     58       "/tables/arn%253Aaws%253As3tables%253Aus-east-1%253A022954301426%253Ab"
     59       "ucket%252Fjasoehartablebucket/jasoeharnamespace/jasoehartable/encrypt"
     60       "ion"
     61     },
     62     {
     63       "get-vanilla",
     64       true,
     65       "/",
     66       "/"
     67     },
     68     {
     69       "get-unreserved",
     70       true,
     71       "/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
     72       "/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
     73     },
     74     {
     75       "get-slashes-unnormalized",
     76       false,
     77       "//example//",
     78       "//example//"
     79     },
     80     {
     81       "get-space-normalized",
     82       true,
     83       "/example space/",
     84       "/example%20space/"
     85     },
     86     {
     87       "get-slash-dot-slash-unnormalized",
     88       false,
     89       "/./",
     90       "/./"
     91     },
     92     {
     93       "get-slash-unnormalized",
     94       false,
     95       "//",
     96       "//"
     97     },
     98     {
     99       "get-relative-relative-unnormalized",
    100       false,
    101       "/example1/example2/../..",
    102       "/example1/example2/../.."
    103     }
    104   };
    105 
    106   size_t i;
    107 
    108   for(i = 0; i < CURL_ARRAYSIZE(testcases); i++) {
    109     struct dynbuf canonical_path;
    110 
    111     char buffer[1024];
    112     char *canonical_path_string;
    113     int result;
    114     int msnprintf_result;
    115 
    116     curlx_dyn_init(&canonical_path, CURL_MAX_HTTP_HEADER);
    117 
    118     result = canon_path(testcases[i].url_part, strlen(testcases[i].url_part),
    119                         &canonical_path, testcases[i].normalize);
    120     canonical_path_string = curlx_dyn_ptr(&canonical_path);
    121     msnprintf_result = curl_msnprintf(buffer, sizeof(buffer),
    122                                       "%s: Received \"%s\" "
    123                                       "and should be \"%s\", normalize (%d)",
    124                                       testcases[i].testname,
    125                                       curlx_dyn_ptr(&canonical_path),
    126                                       testcases[i].canonical_url,
    127                                       testcases[i].normalize);
    128     fail_unless(msnprintf_result >= 0, "curl_msnprintf fails");
    129     fail_unless(!result && canonical_path_string &&
    130                 !strcmp(canonical_path_string, testcases[i].canonical_url),
    131                 buffer);
    132     curlx_dyn_free(&canonical_path);
    133   }
    134 #endif /* !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS) */
    135 
    136   UNITTEST_END_SIMPLE
    137 }