xref: /aosp_15_r20/external/cronet/net/http/http_cookie_indices_fuzztest.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2024 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/http/http_cookie_indices.h"
6 #include "net/http/http_response_headers.h"
7 #include "third_party/fuzztest/src/fuzztest/fuzztest.h"
8 
9 namespace net {
10 namespace {
11 
FuzzParseFromHeader(std::string_view header_value)12 void FuzzParseFromHeader(std::string_view header_value) {
13   auto headers = HttpResponseHeaders::Builder(HttpVersion(1, 1), "200 OK")
14                      .AddHeader("cookie-indices", header_value)
15                      .Build();
16   ParseCookieIndices(*headers);
17 }
18 
19 // While the range of well-formed values is in fact narrower (see field-value
20 // from RFC 9110), we might process HttpResponseHeaders which has filtered out
21 // only '\0', '\r' and '\n'.
HttpFieldValue()22 auto HttpFieldValue() {
23   return fuzztest::StringOf(fuzztest::Filter(
24       [](char c) { return c != '\0' && c != '\n' && c != '\r'; },
25       fuzztest::Arbitrary<char>()));
26 }
27 
28 FUZZ_TEST(CookieIndicesFuzzTest, FuzzParseFromHeader)
29     .WithDomains(HttpFieldValue());
30 
31 }  // namespace
32 }  // namespace net
33