xref: /aosp_15_r20/external/curl/tests/unit/unit1614.c (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker /***************************************************************************
2*6236dae4SAndroid Build Coastguard Worker  *                                  _   _ ____  _
3*6236dae4SAndroid Build Coastguard Worker  *  Project                     ___| | | |  _ \| |
4*6236dae4SAndroid Build Coastguard Worker  *                             / __| | | | |_) | |
5*6236dae4SAndroid Build Coastguard Worker  *                            | (__| |_| |  _ <| |___
6*6236dae4SAndroid Build Coastguard Worker  *                             \___|\___/|_| \_\_____|
7*6236dae4SAndroid Build Coastguard Worker  *
8*6236dae4SAndroid Build Coastguard Worker  * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9*6236dae4SAndroid Build Coastguard Worker  *
10*6236dae4SAndroid Build Coastguard Worker  * This software is licensed as described in the file COPYING, which
11*6236dae4SAndroid Build Coastguard Worker  * you should have received as part of this distribution. The terms
12*6236dae4SAndroid Build Coastguard Worker  * are also available at https://curl.se/docs/copyright.html.
13*6236dae4SAndroid Build Coastguard Worker  *
14*6236dae4SAndroid Build Coastguard Worker  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15*6236dae4SAndroid Build Coastguard Worker  * copies of the Software, and permit persons to whom the Software is
16*6236dae4SAndroid Build Coastguard Worker  * furnished to do so, under the terms of the COPYING file.
17*6236dae4SAndroid Build Coastguard Worker  *
18*6236dae4SAndroid Build Coastguard Worker  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19*6236dae4SAndroid Build Coastguard Worker  * KIND, either express or implied.
20*6236dae4SAndroid Build Coastguard Worker  *
21*6236dae4SAndroid Build Coastguard Worker  * SPDX-License-Identifier: curl
22*6236dae4SAndroid Build Coastguard Worker  *
23*6236dae4SAndroid Build Coastguard Worker  ***************************************************************************/
24*6236dae4SAndroid Build Coastguard Worker #include "curlcheck.h"
25*6236dae4SAndroid Build Coastguard Worker 
26*6236dae4SAndroid Build Coastguard Worker #include "noproxy.h"
27*6236dae4SAndroid Build Coastguard Worker 
unit_setup(void)28*6236dae4SAndroid Build Coastguard Worker static CURLcode unit_setup(void)
29*6236dae4SAndroid Build Coastguard Worker {
30*6236dae4SAndroid Build Coastguard Worker   return CURLE_OK;
31*6236dae4SAndroid Build Coastguard Worker }
32*6236dae4SAndroid Build Coastguard Worker 
unit_stop(void)33*6236dae4SAndroid Build Coastguard Worker static void unit_stop(void)
34*6236dae4SAndroid Build Coastguard Worker {
35*6236dae4SAndroid Build Coastguard Worker 
36*6236dae4SAndroid Build Coastguard Worker }
37*6236dae4SAndroid Build Coastguard Worker 
38*6236dae4SAndroid Build Coastguard Worker struct check {
39*6236dae4SAndroid Build Coastguard Worker   const char *a;
40*6236dae4SAndroid Build Coastguard Worker   const char *n;
41*6236dae4SAndroid Build Coastguard Worker   unsigned int bits;
42*6236dae4SAndroid Build Coastguard Worker   bool match;
43*6236dae4SAndroid Build Coastguard Worker };
44*6236dae4SAndroid Build Coastguard Worker 
45*6236dae4SAndroid Build Coastguard Worker struct noproxy {
46*6236dae4SAndroid Build Coastguard Worker   const char *a;
47*6236dae4SAndroid Build Coastguard Worker   const char *n;
48*6236dae4SAndroid Build Coastguard Worker   bool match;
49*6236dae4SAndroid Build Coastguard Worker };
50*6236dae4SAndroid Build Coastguard Worker 
51*6236dae4SAndroid Build Coastguard Worker UNITTEST_START
52*6236dae4SAndroid Build Coastguard Worker #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_PROXY)
53*6236dae4SAndroid Build Coastguard Worker {
54*6236dae4SAndroid Build Coastguard Worker   int i;
55*6236dae4SAndroid Build Coastguard Worker   int err = 0;
56*6236dae4SAndroid Build Coastguard Worker   struct check list4[]= {
57*6236dae4SAndroid Build Coastguard Worker     { "192.160.0.1", "192.160.0.1", 33, FALSE},
58*6236dae4SAndroid Build Coastguard Worker     { "192.160.0.1", "192.160.0.1", 32, TRUE},
59*6236dae4SAndroid Build Coastguard Worker     { "192.160.0.1", "192.160.0.1", 0, TRUE},
60*6236dae4SAndroid Build Coastguard Worker     { "192.160.0.1", "192.160.0.1", 24, TRUE},
61*6236dae4SAndroid Build Coastguard Worker     { "192.160.0.1", "192.160.0.1", 26, TRUE},
62*6236dae4SAndroid Build Coastguard Worker     { "192.160.0.1", "192.160.0.1", 20, TRUE},
63*6236dae4SAndroid Build Coastguard Worker     { "192.160.0.1", "192.160.0.1", 18, TRUE},
64*6236dae4SAndroid Build Coastguard Worker     { "192.160.0.1", "192.160.0.1", 12, TRUE},
65*6236dae4SAndroid Build Coastguard Worker     { "192.160.0.1", "192.160.0.1", 8, TRUE},
66*6236dae4SAndroid Build Coastguard Worker     { "192.160.0.1", "10.0.0.1", 8, FALSE},
67*6236dae4SAndroid Build Coastguard Worker     { "192.160.0.1", "10.0.0.1", 32, FALSE},
68*6236dae4SAndroid Build Coastguard Worker     { "192.160.0.1", "10.0.0.1", 0, FALSE},
69*6236dae4SAndroid Build Coastguard Worker     { NULL, NULL, 0, FALSE} /* end marker */
70*6236dae4SAndroid Build Coastguard Worker   };
71*6236dae4SAndroid Build Coastguard Worker #ifdef USE_IPV6
72*6236dae4SAndroid Build Coastguard Worker   struct check list6[]= {
73*6236dae4SAndroid Build Coastguard Worker     { "::1", "::1", 0, TRUE},
74*6236dae4SAndroid Build Coastguard Worker     { "::1", "::1", 128, TRUE},
75*6236dae4SAndroid Build Coastguard Worker     { "::1", "0:0::1", 128, TRUE},
76*6236dae4SAndroid Build Coastguard Worker     { "::1", "0:0::1", 129, FALSE},
77*6236dae4SAndroid Build Coastguard Worker     { "fe80::ab47:4396:55c9:8474", "fe80::ab47:4396:55c9:8474", 64, TRUE},
78*6236dae4SAndroid Build Coastguard Worker     { NULL, NULL, 0, FALSE} /* end marker */
79*6236dae4SAndroid Build Coastguard Worker   };
80*6236dae4SAndroid Build Coastguard Worker #endif
81*6236dae4SAndroid Build Coastguard Worker   struct noproxy list[]= {
82*6236dae4SAndroid Build Coastguard Worker     { "www.example.com", "localhost .example.com .example.de", FALSE},
83*6236dae4SAndroid Build Coastguard Worker     { "www.example.com", "localhost,.example.com,.example.de", TRUE},
84*6236dae4SAndroid Build Coastguard Worker     { "www.example.com.", "localhost,.example.com,.example.de", TRUE},
85*6236dae4SAndroid Build Coastguard Worker     { "example.com", "localhost,.example.com,.example.de", TRUE},
86*6236dae4SAndroid Build Coastguard Worker     { "example.com.", "localhost,.example.com,.example.de", TRUE},
87*6236dae4SAndroid Build Coastguard Worker     { "www.example.com", "localhost,.example.com.,.example.de", TRUE},
88*6236dae4SAndroid Build Coastguard Worker     { "www.example.com", "localhost,www.example.com.,.example.de", TRUE},
89*6236dae4SAndroid Build Coastguard Worker     { "example.com", "localhost,example.com,.example.de", TRUE},
90*6236dae4SAndroid Build Coastguard Worker     { "example.com.", "localhost,example.com,.example.de", TRUE},
91*6236dae4SAndroid Build Coastguard Worker     { "nexample.com", "localhost,example.com,.example.de", FALSE},
92*6236dae4SAndroid Build Coastguard Worker     { "www.example.com", "localhost,example.com,.example.de", TRUE},
93*6236dae4SAndroid Build Coastguard Worker     { "127.0.0.1", "127.0.0.1,localhost", TRUE},
94*6236dae4SAndroid Build Coastguard Worker     { "127.0.0.1", "127.0.0.1,localhost,", TRUE},
95*6236dae4SAndroid Build Coastguard Worker     { "127.0.0.1", "127.0.0.1/8,localhost,", TRUE},
96*6236dae4SAndroid Build Coastguard Worker     { "127.0.0.1", "127.0.0.1/28,localhost,", TRUE},
97*6236dae4SAndroid Build Coastguard Worker     { "127.0.0.1", "127.0.0.1/31,localhost,", TRUE},
98*6236dae4SAndroid Build Coastguard Worker     { "127.0.0.1", "localhost,127.0.0.1", TRUE},
99*6236dae4SAndroid Build Coastguard Worker     { "127.0.0.1", "localhost,127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1."
100*6236dae4SAndroid Build Coastguard Worker       "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."
101*6236dae4SAndroid Build Coastguard Worker       "0.0.1.127.0.0.1.127.0.0." /* 128 bytes "address" */, FALSE},
102*6236dae4SAndroid Build Coastguard Worker     { "127.0.0.1", "localhost,127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1."
103*6236dae4SAndroid Build Coastguard Worker       "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."
104*6236dae4SAndroid Build Coastguard Worker       "0.0.1.127.0.0.1.127.0.0" /* 127 bytes "address" */, FALSE},
105*6236dae4SAndroid Build Coastguard Worker     { "localhost", "localhost,127.0.0.1", TRUE},
106*6236dae4SAndroid Build Coastguard Worker     { "localhost", "127.0.0.1,localhost", TRUE},
107*6236dae4SAndroid Build Coastguard Worker     { "foobar", "barfoo", FALSE},
108*6236dae4SAndroid Build Coastguard Worker     { "foobar", "foobar", TRUE},
109*6236dae4SAndroid Build Coastguard Worker     { "192.168.0.1", "foobar", FALSE},
110*6236dae4SAndroid Build Coastguard Worker     { "192.168.0.1", "192.168.0.0/16", TRUE},
111*6236dae4SAndroid Build Coastguard Worker     { "192.168.0.1", "192.168.0.0/24", TRUE},
112*6236dae4SAndroid Build Coastguard Worker     { "192.168.0.1", "192.168.0.0/32", FALSE},
113*6236dae4SAndroid Build Coastguard Worker     { "192.168.0.1", "192.168.0.0", FALSE},
114*6236dae4SAndroid Build Coastguard Worker     { "192.168.1.1", "192.168.0.0/24", FALSE},
115*6236dae4SAndroid Build Coastguard Worker     { "192.168.1.1", "192.168.0.0/33", FALSE},
116*6236dae4SAndroid Build Coastguard Worker     { "192.168.1.1", "foo, bar, 192.168.0.0/24", FALSE},
117*6236dae4SAndroid Build Coastguard Worker     { "192.168.1.1", "foo, bar, 192.168.0.0/16", TRUE},
118*6236dae4SAndroid Build Coastguard Worker #ifdef USE_IPV6
119*6236dae4SAndroid Build Coastguard Worker     { "[::1]", "foo, bar, 192.168.0.0/16", FALSE},
120*6236dae4SAndroid Build Coastguard Worker     { "[::1]", "foo, bar, ::1/64", TRUE},
121*6236dae4SAndroid Build Coastguard Worker     { "[::1]", "::1/64", TRUE},
122*6236dae4SAndroid Build Coastguard Worker     { "[::1]", "::1/96", TRUE},
123*6236dae4SAndroid Build Coastguard Worker     { "[::1]", "::1/129", FALSE},
124*6236dae4SAndroid Build Coastguard Worker     { "bar", "foo, bar, ::1/64", TRUE},
125*6236dae4SAndroid Build Coastguard Worker     { "BAr", "foo, bar, ::1/64", TRUE},
126*6236dae4SAndroid Build Coastguard Worker     { "BAr", "foo,,,,,              bar, ::1/64", TRUE},
127*6236dae4SAndroid Build Coastguard Worker #endif
128*6236dae4SAndroid Build Coastguard Worker     { "www.example.com", "foo, .example.com", TRUE},
129*6236dae4SAndroid Build Coastguard Worker     { "www.example.com", "www2.example.com, .example.net", FALSE},
130*6236dae4SAndroid Build Coastguard Worker     { "example.com", ".example.com, .example.net", TRUE},
131*6236dae4SAndroid Build Coastguard Worker     { "nonexample.com", ".example.com, .example.net", FALSE},
132*6236dae4SAndroid Build Coastguard Worker     { NULL, NULL, FALSE}
133*6236dae4SAndroid Build Coastguard Worker   };
134*6236dae4SAndroid Build Coastguard Worker   for(i = 0; list4[i].a; i++) {
135*6236dae4SAndroid Build Coastguard Worker     bool match = Curl_cidr4_match(list4[i].a, list4[i].n, list4[i].bits);
136*6236dae4SAndroid Build Coastguard Worker     if(match != list4[i].match) {
137*6236dae4SAndroid Build Coastguard Worker       fprintf(stderr, "%s in %s/%u should %smatch\n",
138*6236dae4SAndroid Build Coastguard Worker               list4[i].a, list4[i].n, list4[i].bits,
139*6236dae4SAndroid Build Coastguard Worker               list4[i].match ? "": "not ");
140*6236dae4SAndroid Build Coastguard Worker       err++;
141*6236dae4SAndroid Build Coastguard Worker     }
142*6236dae4SAndroid Build Coastguard Worker   }
143*6236dae4SAndroid Build Coastguard Worker #ifdef USE_IPV6
144*6236dae4SAndroid Build Coastguard Worker   for(i = 0; list6[i].a; i++) {
145*6236dae4SAndroid Build Coastguard Worker     bool match = Curl_cidr6_match(list6[i].a, list6[i].n, list6[i].bits);
146*6236dae4SAndroid Build Coastguard Worker     if(match != list6[i].match) {
147*6236dae4SAndroid Build Coastguard Worker       fprintf(stderr, "%s in %s/%u should %smatch\n",
148*6236dae4SAndroid Build Coastguard Worker               list6[i].a, list6[i].n, list6[i].bits,
149*6236dae4SAndroid Build Coastguard Worker               list6[i].match ? "": "not ");
150*6236dae4SAndroid Build Coastguard Worker       err++;
151*6236dae4SAndroid Build Coastguard Worker     }
152*6236dae4SAndroid Build Coastguard Worker   }
153*6236dae4SAndroid Build Coastguard Worker #endif
154*6236dae4SAndroid Build Coastguard Worker   for(i = 0; list[i].a; i++) {
155*6236dae4SAndroid Build Coastguard Worker     bool match = Curl_check_noproxy(list[i].a, list[i].n);
156*6236dae4SAndroid Build Coastguard Worker     if(match != list[i].match) {
157*6236dae4SAndroid Build Coastguard Worker       fprintf(stderr, "%s in %s should %smatch\n",
158*6236dae4SAndroid Build Coastguard Worker               list[i].a, list[i].n,
159*6236dae4SAndroid Build Coastguard Worker               list[i].match ? "": "not ");
160*6236dae4SAndroid Build Coastguard Worker       err++;
161*6236dae4SAndroid Build Coastguard Worker     }
162*6236dae4SAndroid Build Coastguard Worker   }
163*6236dae4SAndroid Build Coastguard Worker   fail_if(err, "errors");
164*6236dae4SAndroid Build Coastguard Worker }
165*6236dae4SAndroid Build Coastguard Worker #endif
166*6236dae4SAndroid Build Coastguard Worker UNITTEST_STOP
167