unit1980.c (3527B)
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_unit1980(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 char *query_part; 36 const char *canonical_query; 37 }; 38 39 static const struct testcase testcases[] = { 40 { 41 "no-value", 42 "Param1=", 43 "Param1=" 44 }, 45 { 46 "test-439", 47 "name=me&noval&aim=b%aad&weirdo=*.//-", 48 "aim=b%AAd&name=me&noval=&weirdo=%2A.%2F%2F-" 49 }, 50 { 51 "blank-query-params", 52 "hello=a&b&c=&d", 53 "b=&c=&d=&hello=a" 54 }, 55 { 56 "get-vanilla-query-order-key-case", 57 "Param2=value2&Param1=value1", 58 "Param1=value1&Param2=value2" 59 }, 60 { 61 "get-vanilla-query-unreserved", 62 "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=" 63 "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 64 "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=" 65 "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 66 }, 67 { 68 "get-vanilla-empty-query-key", 69 "Param1=value1", 70 "Param1=value1" 71 }, 72 { 73 "get-vanilla-query-order-encoded", 74 "Param-3=Value3&Param=Value2&%E1%88%B4=Value1", 75 "%E1%88%B4=Value1&Param=Value2&Param-3=Value3" 76 }, 77 }; 78 79 size_t i; 80 81 for(i = 0; i < CURL_ARRAYSIZE(testcases); i++) { 82 struct dynbuf canonical_query; 83 84 char buffer[1024]; 85 char *canonical_query_ptr; 86 int result; 87 int msnprintf_result; 88 89 curlx_dyn_init(&canonical_query, CURL_MAX_HTTP_HEADER); 90 91 result = canon_query(testcases[i].query_part, &canonical_query); 92 canonical_query_ptr = curlx_dyn_ptr(&canonical_query); 93 msnprintf_result = curl_msnprintf(buffer, sizeof(buffer), 94 "%s: Received \"%s\" " 95 "and should be \"%s\"", 96 testcases[i].testname, 97 canonical_query_ptr, 98 testcases[i].canonical_query); 99 fail_unless(msnprintf_result >= 0, "curl_msnprintf fails"); 100 fail_unless(!result && canonical_query_ptr && 101 !strcmp(canonical_query_ptr, testcases[i].canonical_query), 102 buffer); 103 curlx_dyn_free(&canonical_query); 104 } 105 #endif /* !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS) */ 106 107 UNITTEST_END_SIMPLE 108 }