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"
26#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_HSTS)
27#include "urldata.h"
28#include "hsts.h"
30static void showsts(struct stsentry *e, const char *chost)
31{
32 if(!e)
33 curl_mprintf("'%s' is not HSTS\n", chost);
34 else {
35 curl_mprintf("%s [%s]: %" CURL_FORMAT_CURL_OFF_T "%s\n",
36 chost, e->host, e->expires,
37 e->includeSubDomains ? " includeSubDomains" : "");
38 }
39}
41static CURLcode test_unit1660(const char *arg)
42{
43 UNITTEST_BEGIN_SIMPLE
45 struct testit {
46 const char *host;
47 const char *chost; /* if non-NULL, use to lookup with */
48 const char *hdr; /* if NULL, do the lookup */
49 const CURLcode result; /* parse result */
50 };
52 static const struct testit headers[] = {
53 /* two entries read from disk cache, verify first */
54 { "-", "readfrom.example", NULL, CURLE_OK },
55 { "-", "old.example", NULL, CURLE_OK },
56 /* delete the remaining one read from disk */
57 { "readfrom.example", NULL, "max-age=\"0\"", CURLE_OK },
59 { "example.com", NULL, "max-age=\"31536000\"\r\n", CURLE_OK },
60 { "example.com", NULL, "max-age=\"21536000\"\r\n", CURLE_OK },
61 { "example.com", NULL, "max-age=\"21536000\"; \r\n", CURLE_OK },
62 { "example.com", NULL, "max-age=\"21536000\"; includeSubDomains\r\n",
63 CURLE_OK },
64 { "example.org", NULL, "max-age=\"31536000\"\r\n", CURLE_OK },
65 { "this.example", NULL, "max=\"31536\";", CURLE_BAD_FUNCTION_ARGUMENT },
66 { "this.example", NULL, "max-age=\"31536", CURLE_BAD_FUNCTION_ARGUMENT },
67 { "this.example", NULL, "max-age=31536\"", CURLE_OK },
68 /* max-age=0 removes the entry */
69 { "this.example", NULL, "max-age=0", CURLE_OK },
70 { "another.example", NULL, "includeSubDomains; ",
71 CURLE_BAD_FUNCTION_ARGUMENT },
73 /* Two max-age is illegal */
74 { "example.com", NULL,
75 "max-age=\"21536000\"; includeSubDomains; max-age=\"3\";",
76 CURLE_BAD_FUNCTION_ARGUMENT },
77 /* Two includeSubDomains is illegal */
78 { "2.example.com", NULL,
79 "max-age=\"21536000\"; includeSubDomains; includeSubDomains;",
80 CURLE_BAD_FUNCTION_ARGUMENT },
81 /* use an unknown directive "include" that should be ignored */
82 { "3.example.com", NULL,
83 "max-age=\"21536000\"; include; includeSubDomains;", CURLE_OK },
84 /* remove the "3.example.com" one, should still match the example.com */
85 { "3.example.com", NULL, "max-age=\"0\"; includeSubDomains;", CURLE_OK },
86 { "-", "foo.example.com", NULL, CURLE_OK },
87 { "-", "foo.xample.com", NULL, CURLE_OK },
89 /* should not match */
90 { "example.net", "forexample.net", "max-age=\"31536000\"\r\n", CURLE_OK },
92 /* should not match either, since forexample.net is not in the example.net
93 domain */
94 { "example.net", "forexample.net",
95 "max-age=\"31536000\"; includeSubDomains\r\n", CURLE_OK },
96 /* remove example.net again */
97 { "example.net", NULL, "max-age=\"0\"; includeSubDomains\r\n", CURLE_OK },
99 /* make this live for 7 seconds */
100 { "expire.example", NULL, "max-age=\"7\"\r\n", CURLE_OK },
101 { NULL, NULL, NULL, CURLE_OK }
102 };
104 CURLcode result;
105 struct stsentry *e;
106 struct hsts *h = Curl_hsts_init();
107 int i;
108 const char *chost;
109 CURL *easy;
110 char savename[256];
112 abort_unless(h, "Curl_hsts_init()");
114 curl_global_init(CURL_GLOBAL_ALL);
115 easy = curl_easy_init();
116 if(!easy) {
117 Curl_hsts_cleanup(&h);
118 curl_global_cleanup();
119 abort_unless(easy, "curl_easy_init()");
120 }
122 Curl_hsts_loadfile(easy, h, arg);
124 for(i = 0; headers[i].host; i++) {
125 if(headers[i].hdr) {
126 result = Curl_hsts_parse(h, headers[i].host, headers[i].hdr);
128 if(result != headers[i].result) {
129 curl_mfprintf(stderr, "Curl_hsts_parse(%s) failed: %d\n",
130 headers[i].hdr, (int)result);
131 unitfail++;
132 continue;
133 }
134 else if(result) {
135 curl_mprintf("Input %d: error %d\n", i, (int)result);
136 continue;
137 }
138 }
140 chost = headers[i].chost ? headers[i].chost : headers[i].host;
141 e = hsts_check(h, chost, strlen(chost), TRUE);
142 showsts(e, chost);
143 }
145 result = Curl_hsts_parse(h, "prefix.example",
146 "max-age=60; includeSubDomainsExtra");
147 fail_if(result, "failed to parse unknown HSTS directive");
148 e = hsts_check(h, "child.prefix.example",
149 strlen("child.prefix.example"), TRUE);
150 fail_if(e, "unknown directive enabled subdomain matching");
151 result = Curl_hsts_parse(h, "prefix.example", "max-age=0");
152 fail_if(result, "failed to remove HSTS test entry");
154 result = Curl_hsts_parse(h, "unknown.example",
155 "max-age-extra=1; max-age=60");
156 fail_if(result, "failed to ignore unknown HSTS directive");
157 e = hsts_check(h, "unknown.example", strlen("unknown.example"), FALSE);
158 fail_if(!e, "recognized directive after unknown directive was ignored");
159 result = Curl_hsts_parse(h, "unknown.example", "max-age=0");
160 fail_if(result, "failed to remove HSTS test entry");
162 curl_mprintf("Number of entries: %zu\n", Curl_llist_count(&h->list));
164 /* verify that it is exists for 7 seconds */
165 chost = "expire.example";
166 for(i = 100; i < 110; i++) {
167 e = hsts_check(h, chost, strlen(chost), TRUE);
168 showsts(e, chost);
169 deltatime++; /* another second passed */
170 }
172 curl_msnprintf(savename, sizeof(savename), "%s.save", arg);
173 (void)Curl_hsts_save(easy, h, savename);
174 Curl_hsts_cleanup(&h);
175 curl_easy_cleanup(easy);
176 curl_global_cleanup();
178 UNITTEST_END(curl_global_cleanup())
179}
180#else
181static CURLcode test_unit1660(const char *arg)
182{
183 UNITTEST_BEGIN_SIMPLE
184 puts("nothing to do when HTTP or HSTS are disabled");
185 UNITTEST_END_SIMPLE
186}
187#endif
Diagnostics4 git calls · 26 ms
CallStatusSizeTime026 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=2 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.2 KiB · hit20 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=20 git.response.bytes=2289 git.response.cache=HIT git.response.duration_ms=20 git.fetch.wants=2e62b313a83695d89eb3becfb144f537132e755f 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=2289 git.pkt.payload.max=2268 git.sideband.band1.bytes=2267 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
- a5e2e7f3a959ecfa
- Request
- 563977fe…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format