unit1614.c (6121B)
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 "noproxy.h" 27 28 static CURLcode test_unit1614(char *arg) 29 { 30 UNITTEST_BEGIN_SIMPLE 31 32 #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_PROXY) 33 int i; 34 int err = 0; 35 36 struct check { 37 const char *a; 38 const char *n; 39 unsigned int bits; 40 bool match; 41 }; 42 struct check list4[]= { 43 { "192.160.0.1", "192.160.0.1", 33, FALSE}, 44 { "192.160.0.1", "192.160.0.1", 32, TRUE}, 45 { "192.160.0.1", "192.160.0.1", 0, TRUE}, 46 { "192.160.0.1", "192.160.0.1", 24, TRUE}, 47 { "192.160.0.1", "192.160.0.1", 26, TRUE}, 48 { "192.160.0.1", "192.160.0.1", 20, TRUE}, 49 { "192.160.0.1", "192.160.0.1", 18, TRUE}, 50 { "192.160.0.1", "192.160.0.1", 12, TRUE}, 51 { "192.160.0.1", "192.160.0.1", 8, TRUE}, 52 { "192.160.0.1", "10.0.0.1", 8, FALSE}, 53 { "192.160.0.1", "10.0.0.1", 32, FALSE}, 54 { "192.160.0.1", "10.0.0.1", 0, FALSE}, 55 { NULL, NULL, 0, FALSE} /* end marker */ 56 }; 57 #ifdef USE_IPV6 58 struct check list6[]= { 59 { "::1", "::1", 0, TRUE}, 60 { "::1", "::1", 128, TRUE}, 61 { "::1", "0:0::1", 128, TRUE}, 62 { "::1", "0:0::1", 129, FALSE}, 63 { "fe80::ab47:4396:55c9:8474", "fe80::ab47:4396:55c9:8474", 64, TRUE}, 64 { NULL, NULL, 0, FALSE} /* end marker */ 65 }; 66 #endif 67 struct noproxy { 68 const char *a; 69 const char *n; 70 bool match; 71 }; 72 struct noproxy list[]= { 73 { "www.example.com", "localhost .example.com .example.de", FALSE}, 74 { "www.example.com", "localhost,.example.com,.example.de", TRUE}, 75 { "www.example.com.", "localhost,.example.com,.example.de", TRUE}, 76 { "example.com", "localhost,.example.com,.example.de", TRUE}, 77 { "example.com.", "localhost,.example.com,.example.de", TRUE}, 78 { "www.example.com", "localhost,.example.com.,.example.de", TRUE}, 79 { "www.example.com", "localhost,www.example.com.,.example.de", TRUE}, 80 { "example.com", "localhost,example.com,.example.de", TRUE}, 81 { "example.com.", "localhost,example.com,.example.de", TRUE}, 82 { "nexample.com", "localhost,example.com,.example.de", FALSE}, 83 { "www.example.com", "localhost,example.com,.example.de", TRUE}, 84 { "127.0.0.1", "127.0.0.1,localhost", TRUE}, 85 { "127.0.0.1", "127.0.0.1,localhost,", TRUE}, 86 { "127.0.0.1", "127.0.0.1/8,localhost,", TRUE}, 87 { "127.0.0.1", "127.0.0.1/28,localhost,", TRUE}, 88 { "127.0.0.1", "127.0.0.1/31,localhost,", TRUE}, 89 { "127.0.0.1", "localhost,127.0.0.1", TRUE}, 90 { "127.0.0.1", "localhost,127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1." 91 "127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127." 92 "0.0.1.127.0.0.1.127.0.0." /* 128 bytes "address" */, FALSE}, 93 { "127.0.0.1", "localhost,127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1." 94 "127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127." 95 "0.0.1.127.0.0.1.127.0.0" /* 127 bytes "address" */, FALSE}, 96 { "localhost", "localhost,127.0.0.1", TRUE}, 97 { "localhost", "127.0.0.1,localhost", TRUE}, 98 { "foobar", "barfoo", FALSE}, 99 { "foobar", "foobar", TRUE}, 100 { "192.168.0.1", "foobar", FALSE}, 101 { "192.168.0.1", "192.168.0.0/16", TRUE}, 102 { "192.168.0.1", "192.168.0.0/24", TRUE}, 103 { "192.168.0.1", "192.168.0.0/32", FALSE}, 104 { "192.168.0.1", "192.168.0.0", FALSE}, 105 { "192.168.1.1", "192.168.0.0/24", FALSE}, 106 { "192.168.1.1", "192.168.0.0/33", FALSE}, 107 { "192.168.1.1", "foo, bar, 192.168.0.0/24", FALSE}, 108 { "192.168.1.1", "foo, bar, 192.168.0.0/16", TRUE}, 109 #ifdef USE_IPV6 110 { "[::1]", "foo, bar, 192.168.0.0/16", FALSE}, 111 { "[::1]", "foo, bar, ::1/64", TRUE}, 112 { "[::1]", "::1/64", TRUE}, 113 { "[::1]", "::1/96", TRUE}, 114 { "[::1]", "::1/129", FALSE}, 115 { "bar", "foo, bar, ::1/64", TRUE}, 116 { "BAr", "foo, bar, ::1/64", TRUE}, 117 { "BAr", "foo,,,,, bar, ::1/64", TRUE}, 118 #endif 119 { "www.example.com", "foo, .example.com", TRUE}, 120 { "www.example.com", "www2.example.com, .example.net", FALSE}, 121 { "example.com", ".example.com, .example.net", TRUE}, 122 { "nonexample.com", ".example.com, .example.net", FALSE}, 123 { NULL, NULL, FALSE} 124 }; 125 for(i = 0; list4[i].a; i++) { 126 bool match = Curl_cidr4_match(list4[i].a, list4[i].n, list4[i].bits); 127 if(match != list4[i].match) { 128 curl_mfprintf(stderr, "%s in %s/%u should %smatch\n", 129 list4[i].a, list4[i].n, list4[i].bits, 130 list4[i].match ? "": "not "); 131 err++; 132 } 133 } 134 #ifdef USE_IPV6 135 for(i = 0; list6[i].a; i++) { 136 bool match = Curl_cidr6_match(list6[i].a, list6[i].n, list6[i].bits); 137 if(match != list6[i].match) { 138 curl_mfprintf(stderr, "%s in %s/%u should %smatch\n", 139 list6[i].a, list6[i].n, list6[i].bits, 140 list6[i].match ? "": "not "); 141 err++; 142 } 143 } 144 #endif 145 for(i = 0; list[i].a; i++) { 146 bool match = Curl_check_noproxy(list[i].a, list[i].n); 147 if(match != list[i].match) { 148 curl_mfprintf(stderr, "%s in %s should %smatch\n", 149 list[i].a, list[i].n, 150 list[i].match ? "": "not "); 151 err++; 152 } 153 } 154 fail_if(err, "errors"); 155 #endif 156 157 UNITTEST_END_SIMPLE 158 }