master
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#include "urldata.h"
26#include "connect.h"
27#include "curl_addrinfo.h"
29static CURLcode t3271_setup(void)
30{
31 CURLcode result = CURLE_OK;
32 global_init(CURL_GLOBAL_ALL);
33 return result;
34}
36/* CURLOPT_RESOLVE address parsing test - to test the following defect fix:
38 1. if there is already existing host:port pair in the DNS cache and
39 we call CURLOPT_RESOLVE, it should also replace addresses.
40 for example, if there is "test.com:80" with address "1.1.1.1"
41 and we called CURLOPT_RESOLVE with address "2.2.2.2", then DNS entry
42 needs to reflect that.
44 2. when cached address is already there and close to expire, then by the
45 time request is made, it can get expired. This happens because, when
46 we set address using CURLOPT_RESOLVE,
47 it usually marks as permanent (by setting timestamp to zero). However,
48 if address already exists in the cache, then it does not mark it, but
49 leaves it as it is.
50 We are fixing this by setting timestamp to zero if address already
51 exists too.
53 Test:
55 - insert new entry
56 - verify that timestamp is not zero
57 - call set options with CURLOPT_RESOLVE
58 - then, call Curl_loadhostpairs
60 expected result: cached address has zero timestamp.
62 - call set options with CURLOPT_RESOLVE with same host:port pair,
63 different address.
64 - then, call Curl_loadhostpairs
66 expected result: cached address has zero timestamp and new address
67 */
69static CURLcode test_unit3271(const char *arg)
70{
71 UNITTEST_BEGIN(t3271_setup())
73 struct testcase {
74 /* host:port:address[,address]... */
75 const char *optval;
77 /* lowercase host and port to retrieve the addresses from hostcache */
78 const char *host;
79 uint16_t port;
81 /* 0 to 9 addresses expected from hostcache */
82 const char *address[10];
83 };
85 static const struct testcase tests[] = {
86 /* spaces are not allowed */
87 { "test.com:80:127.0.0.1",
88 "test.com", 80, { "127.0.0.1", }
89 },
90 { "test.com:80:127.0.0.2",
91 "test.com", 80, { "127.0.0.2", }
92 },
93 };
95 size_t i;
96 struct Curl_multi *multi = NULL;
97 struct Curl_easy *easy = NULL;
98 struct curl_slist *list = NULL;
99 char hostname[258];
100 struct dnsc_id long_id;
101 struct Curl_dns_entry *long_dns;
103 /* Check full hostname matching when the DNS cache key is truncated. */
104 memset(hostname, 'a', sizeof(hostname) - 1);
105 hostname[sizeof(hostname) - 1] = 0;
106 long_dns = curlx_calloc(1, sizeof(*long_dns) + sizeof(hostname));
107 abort_unless(long_dns, "could not allocate cache entry");
108 hostname[255] = 0;
109 memcpy(long_dns->hostname, hostname, 256);
110 hostname[255] = 'a';
111 long_dns->hostlen = 255;
112 long_dns->port = 80;
113 long_id.port = 80;
114 curlx_str_assign(&long_id.name, hostname, strlen(hostname));
115 fail_unless(!dnsc_id_matches_entry(&long_id, long_dns),
116 "long query must not match shorter cached hostname");
117 memcpy(long_dns->hostname, hostname, sizeof(hostname));
118 long_dns->hostlen = (uint16_t)strlen(hostname);
119 fail_unless(dnsc_id_matches_entry(&long_id, long_dns),
120 "identical long hostname must match");
121 hostname[0] = 'A';
122 fail_unless(dnsc_id_matches_entry(&long_id, long_dns),
123 "long hostname lookup must remain case insensitive");
124 hostname[255] = 0;
125 curlx_str_assign(&long_id.name, hostname, strlen(hostname));
126 fail_unless(!dnsc_id_matches_entry(&long_id, long_dns),
127 "short query must not match longer cached hostname");
128 curlx_free(long_dns);
130 /* important: we setup cache outside of the loop and also clean cache after
131 the loop. In contrast, for example, test 1607 sets up and cleans cache on
132 each iteration. */
134 for(i = 0; i < CURL_ARRAYSIZE(tests); ++i) {
135 size_t j;
136 size_t addressnum = CURL_ARRAYSIZE(tests[i].address);
137 struct Curl_addrinfo *addr;
138 struct Curl_dns_entry *dns;
139 struct dnsc_id id;
140 struct dnsc_key key;
141 const char type = CURL_DNST_ADDR;
142 bool problem = FALSE;
143 struct Curl_peer *peer = NULL;
144 easy = curl_easy_init();
145 if(!easy) {
146 curl_global_cleanup();
147 return CURLE_OUT_OF_MEMORY;
148 }
149 /* create a multi handle and add the easy handle to it so that the
150 hostcache is setup */
151 multi = curl_multi_init();
152 if(!multi)
153 goto error;
154 curl_multi_add_handle(multi, easy);
156 list = curl_slist_append(NULL, tests[i].optval);
157 if(!list)
158 goto error;
160 curl_easy_setopt(easy, CURLOPT_RESOLVE, list);
162 if(Curl_loadhostpairs(easy))
163 goto error;
165 if(Curl_peer_create(easy, &Curl_scheme_http,
166 tests[i].host, tests[i].port, &peer))
167 goto error;
169 dnsc_peer2id(&id, type, peer);
170 dnsc_id2key(&key, &id);
171 dns = Curl_hash_pick(&multi->dnscache.entries, key.data, key.len);
173 addr = dns ? dns->addr : NULL;
175 for(j = 0; j < addressnum; ++j) {
176 uint16_t port = 0;
177 char ipaddress[MAX_IPADR_LEN] = { 0 };
179 if(!addr && !tests[i].address[j])
180 break;
182 if(addr && sockaddr2string(addr->ai_addr, addr->ai_addrlen,
183 ipaddress, &port)) {
184 curl_mfprintf(stderr,
185 "%s:%d tests[%zu] failed. Curl_addr2string failed.\n",
186 __FILE__, __LINE__, i);
187 problem = TRUE;
188 break;
189 }
191 if(addr && !tests[i].address[j]) {
192 curl_mfprintf(stderr, "%s:%d tests[%zu] failed. the retrieved addr "
193 "is %s but tests[%zu].address[%zu] is NULL.\n",
194 __FILE__, __LINE__, i, ipaddress, i, j);
195 problem = TRUE;
196 break;
197 }
199 if(!addr && tests[i].address[j]) {
200 curl_mfprintf(stderr, "%s:%d tests[%zu] failed. the retrieved addr "
201 "is NULL but tests[%zu].address[%zu] is %s.\n",
202 __FILE__, __LINE__, i, i, j, tests[i].address[j]);
203 problem = TRUE;
204 break;
205 }
207 if(!curl_strequal(ipaddress, tests[i].address[j])) {
208 curl_mfprintf(stderr, "%s:%d tests[%zu] failed. the retrieved addr "
209 "%s is not equal to tests[%zu].address[%zu] %s.\n",
210 __FILE__, __LINE__, i, ipaddress, i, j,
211 tests[i].address[j]);
212 problem = TRUE;
213 break;
214 }
216 if(port != tests[i].port) {
217 curl_mfprintf(stderr, "%s:%d tests[%zu] failed. the retrieved port "
218 "for tests[%zu].address[%zu] is %d "
219 "but tests[%zu].port is %d.\n",
220 __FILE__, __LINE__, i, i, j, port, i, tests[i].port);
221 problem = TRUE;
222 break;
223 }
225 if(!addr)
226 break;
228 addr = addr->ai_next;
229 }
230 Curl_peer_unlink(&peer);
232 curl_easy_cleanup(easy);
233 easy = NULL;
234 curl_multi_cleanup(multi);
235 multi = NULL;
236 curl_slist_free_all(list);
237 list = NULL;
239 if(problem) {
240 unitfail++;
241 continue;
242 }
243 }
244 goto unit_test_abort;
245error:
246 curl_easy_cleanup(easy);
247 curl_multi_cleanup(multi);
248 curl_slist_free_all(list);
250 UNITTEST_END(curl_global_cleanup())
251}
Diagnostics4 git calls · 38 ms
CallStatusSizeTime038 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2002.8 KiB · hit32 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=32 git.response.bytes=2909 git.response.cache=HIT git.response.duration_ms=32 git.fetch.wants=abab4cc700f3cc429a6f13399b945242e0fa6962 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2909 git.pkt.payload.max=2888 git.sideband.band1.bytes=2887 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e1fb4af800a9c0
- Request
- 53fabc0d…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format