xref: /aosp_15_r20/external/grpc-grpc/test/core/uri/uri_parser_test.cc (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 //
2 // Copyright 2015 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include "src/core/lib/uri/uri_parser.h"
18 
19 #include <utility>
20 
21 #include "absl/status/status.h"
22 #include "gmock/gmock.h"
23 #include "gtest/gtest.h"
24 
25 #include <grpc/grpc.h>
26 
27 #include "test/core/util/test_config.h"
28 
29 using ::testing::ContainerEq;
30 using ::testing::Contains;
31 using ::testing::ElementsAre;
32 using ::testing::Pair;
33 
34 namespace grpc_core {
35 
36 class URIParserTest : public testing::Test {
37  protected:
TestSucceeds(absl::string_view uri_text,absl::string_view scheme,absl::string_view authority,absl::string_view path,const std::map<absl::string_view,absl::string_view> & query_param_map,const std::vector<URI::QueryParam> & query_param_pairs,absl::string_view fragment)38   static void TestSucceeds(
39       absl::string_view uri_text, absl::string_view scheme,
40       absl::string_view authority, absl::string_view path,
41       const std::map<absl::string_view, absl::string_view>& query_param_map,
42       const std::vector<URI::QueryParam>& query_param_pairs,
43       absl::string_view fragment) {
44     absl::StatusOr<URI> uri = URI::Parse(uri_text);
45     ASSERT_TRUE(uri.ok()) << uri.status().ToString();
46     EXPECT_EQ(scheme, uri->scheme());
47     EXPECT_EQ(authority, uri->authority());
48     EXPECT_EQ(path, uri->path());
49     EXPECT_THAT(uri->query_parameter_map(), ContainerEq(query_param_map));
50     EXPECT_THAT(uri->query_parameter_pairs(), ContainerEq(query_param_pairs));
51     EXPECT_EQ(fragment, uri->fragment());
52   }
53 
TestFails(absl::string_view uri_text)54   static void TestFails(absl::string_view uri_text) {
55     absl::StatusOr<URI> uri = URI::Parse(uri_text);
56     ASSERT_FALSE(uri.ok());
57   }
58 };
59 
TEST_F(URIParserTest,BasicExamplesAreParsedCorrectly)60 TEST_F(URIParserTest, BasicExamplesAreParsedCorrectly) {
61   TestSucceeds("http://www.google.com", "http", "www.google.com", "", {}, {},
62                "");
63   TestSucceeds("dns:///foo", "dns", "", "/foo", {}, {}, "");
64   TestSucceeds("http://www.google.com:90", "http", "www.google.com:90", "", {},
65                {}, "");
66   TestSucceeds("a192.4-df:foo.coom", "a192.4-df", "", "foo.coom", {}, {}, "");
67   TestSucceeds("a+b:foo.coom", "a+b", "", "foo.coom", {}, {}, "");
68   TestSucceeds("zookeeper://127.0.0.1:2181/foo/bar", "zookeeper",
69                "127.0.0.1:2181", "/foo/bar", {}, {}, "");
70   TestSucceeds("dns:foo.com#fragment-all-the-things", "dns", "", "foo.com", {},
71                {}, "fragment-all-the-things");
72   TestSucceeds("http://localhost:8080/whatzit?mi_casa=su_casa", "http",
73                "localhost:8080", "/whatzit", {{"mi_casa", "su_casa"}},
74                {{"mi_casa", "su_casa"}}, "");
75   TestSucceeds("http://localhost:8080/whatzit?1=2#buckle/my/shoe", "http",
76                "localhost:8080", "/whatzit", {{"1", "2"}}, {{"1", "2"}},
77                "buckle/my/shoe");
78 }
79 
TEST_F(URIParserTest,UncommonValidExamplesAreParsedCorrectly)80 TEST_F(URIParserTest, UncommonValidExamplesAreParsedCorrectly) {
81   TestSucceeds("scheme:path//is/ok", "scheme", "", "path//is/ok", {}, {}, "");
82   TestSucceeds("http:?legit", "http", "", "", {{"legit", ""}}, {{"legit", ""}},
83                "");
84   TestSucceeds("unix:#this-is-ok-too", "unix", "", "", {}, {},
85                "this-is-ok-too");
86   TestSucceeds("http:?legit#twice", "http", "", "", {{"legit", ""}},
87                {{"legit", ""}}, "twice");
88   TestSucceeds("fake:///", "fake", "", "/", {}, {}, "");
89   TestSucceeds("http://local%25host:8080/whatz%25it?1%25=2%25#fragment", "http",
90                "local%host:8080", "/whatz%it", {{"1%", "2%"}}, {{"1%", "2%"}},
91                "fragment");
92 }
93 
TEST_F(URIParserTest,VariousKeyValueAndNonKVQueryParamsAreParsedCorrectly)94 TEST_F(URIParserTest, VariousKeyValueAndNonKVQueryParamsAreParsedCorrectly) {
95   TestSucceeds("http://foo/path?a&b=B&c=&#frag", "http", "foo", "/path",
96                {{"c", ""}, {"a", ""}, {"b", "B"}},
97                {{"a", ""}, {"b", "B"}, {"c", ""}}, "frag");
98 }
99 
TEST_F(URIParserTest,ParserTreatsFirstEqualSignAsKVDelimiterInQueryString)100 TEST_F(URIParserTest, ParserTreatsFirstEqualSignAsKVDelimiterInQueryString) {
101   TestSucceeds(
102       "http://localhost:8080/?too=many=equals&are=present=here#fragged", "http",
103       "localhost:8080", "/", {{"are", "present=here"}, {"too", "many=equals"}},
104       {{"too", "many=equals"}, {"are", "present=here"}}, "fragged");
105   TestSucceeds("http://auth/path?foo=bar=baz&foobar===", "http", "auth",
106                "/path", {{"foo", "bar=baz"}, {"foobar", "=="}},
107                {{"foo", "bar=baz"}, {"foobar", "=="}}, "");
108 }
109 
TEST_F(URIParserTest,RepeatedQueryParamsAreSupportedInOrderedPairsButDeduplicatedInTheMap)110 TEST_F(URIParserTest,
111        RepeatedQueryParamsAreSupportedInOrderedPairsButDeduplicatedInTheMap) {
112   absl::StatusOr<URI> uri = URI::Parse("http://foo/path?a=2&a=1&a=3");
113   ASSERT_TRUE(uri.ok()) << uri.status().ToString();
114   // The map stores the last found value.
115   ASSERT_THAT(uri->query_parameter_map(), ElementsAre(Pair("a", "3")));
116   // Order matters for query parameter pairs
117   ASSERT_THAT(uri->query_parameter_pairs(),
118               ElementsAre(URI::QueryParam{"a", "2"}, URI::QueryParam{"a", "1"},
119                           URI::QueryParam{"a", "3"}));
120 }
121 
TEST_F(URIParserTest,QueryParamMapRemainsValiditAfterMovingTheURI)122 TEST_F(URIParserTest, QueryParamMapRemainsValiditAfterMovingTheURI) {
123   URI uri_copy;
124   {
125     absl::StatusOr<URI> uri = URI::Parse("http://foo/path?a=2&b=1&c=3");
126     ASSERT_TRUE(uri.ok()) << uri.status().ToString();
127     uri_copy = std::move(*uri);
128   }
129   // ASSERT_EQ(uri_copy.query_parameter_map().find("a")->second, "2");
130   ASSERT_THAT(uri_copy.query_parameter_map(), Contains(Pair("a", "2")));
131 }
132 
TEST_F(URIParserTest,QueryParamMapRemainsValidAfterCopyingTheURI)133 TEST_F(URIParserTest, QueryParamMapRemainsValidAfterCopyingTheURI) {
134   // Since the query parameter map points to objects stored in the param pair
135   // vector, this test checks that the param map pointers remain valid after
136   // a copy. Ideally {a,m}san will catch this if there's a problem.
137   // testing copy operator=:
138   URI uri_copy;
139   {
140     absl::StatusOr<URI> del_uri = URI::Parse("http://foo/path?a=2&b=1&c=3");
141     ASSERT_TRUE(del_uri.ok()) << del_uri.status().ToString();
142     uri_copy = *del_uri;
143   }
144   ASSERT_THAT(uri_copy.query_parameter_map(), Contains(Pair("a", "2")));
145   URI* del_uri2 = new URI(uri_copy);
146   URI uri_copy2(*del_uri2);
147   delete del_uri2;
148   ASSERT_THAT(uri_copy2.query_parameter_map(), Contains(Pair("a", "2")));
149 }
150 
TEST_F(URIParserTest,AWSExternalAccountRegressionTest)151 TEST_F(URIParserTest, AWSExternalAccountRegressionTest) {
152   TestSucceeds(
153       "https://foo.com:5555/v1/"
154       "token-exchange?subject_token=eyJhbGciO&subject_token_type=urn:ietf:"
155       "params:oauth:token-type:id_token",
156       "https", "foo.com:5555", "/v1/token-exchange",
157       {{"subject_token", "eyJhbGciO"},
158        {"subject_token_type", "urn:ietf:params:oauth:token-type:id_token"}},
159       {{"subject_token", "eyJhbGciO"},
160        {"subject_token_type", "urn:ietf:params:oauth:token-type:id_token"}},
161       "");
162 }
163 
TEST_F(URIParserTest,NonKeyValueQueryStringsWork)164 TEST_F(URIParserTest, NonKeyValueQueryStringsWork) {
165   TestSucceeds("http://www.google.com?yay-i'm-using-queries", "http",
166                "www.google.com", "", {{"yay-i'm-using-queries", ""}},
167                {{"yay-i'm-using-queries", ""}}, "");
168 }
169 
TEST_F(URIParserTest,IPV6StringsAreParsedCorrectly)170 TEST_F(URIParserTest, IPV6StringsAreParsedCorrectly) {
171   TestSucceeds("ipv6:[2001:db8::1%252]:12345", "ipv6", "",
172                "[2001:db8::1%2]:12345", {}, {}, "");
173   TestSucceeds("ipv6:[fe80::90%eth1.sky1]:6010", "ipv6", "",
174                "[fe80::90%eth1.sky1]:6010", {}, {}, "");
175 }
176 
TEST_F(URIParserTest,PreviouslyReservedCharactersInUnrelatedURIPartsAreIgnored)177 TEST_F(URIParserTest,
178        PreviouslyReservedCharactersInUnrelatedURIPartsAreIgnored) {
179   // The '?' and '/' characters are not reserved delimiter characters in the
180   // fragment. See http://go/rfc/3986#section-3.5
181   TestSucceeds("http://foo?bar#lol?", "http", "foo", "", {{"bar", ""}},
182                {{"bar", ""}}, "lol?");
183   TestSucceeds("http://foo?bar#lol?/", "http", "foo", "", {{"bar", ""}},
184                {{"bar", ""}}, "lol?/");
185 }
186 
TEST_F(URIParserTest,EncodedCharactersInQueryStringAreParsedCorrectly)187 TEST_F(URIParserTest, EncodedCharactersInQueryStringAreParsedCorrectly) {
188   TestSucceeds("https://www.google.com/?a=1%26b%3D2&c=3", "https",
189                "www.google.com", "/", {{"c", "3"}, {"a", "1&b=2"}},
190                {{"a", "1&b=2"}, {"c", "3"}}, "");
191 }
192 
TEST_F(URIParserTest,InvalidPercentEncodingsArePassedThrough)193 TEST_F(URIParserTest, InvalidPercentEncodingsArePassedThrough) {
194   TestSucceeds("x:y?%xx", "x", "", "y", {{"%xx", ""}}, {{"%xx", ""}}, "");
195   TestSucceeds("http:?dangling-pct-%0", "http", "", "",
196                {{"dangling-pct-%0", ""}}, {{"dangling-pct-%0", ""}}, "");
197 }
198 
TEST_F(URIParserTest,NullCharactersInURIStringAreSupported)199 TEST_F(URIParserTest, NullCharactersInURIStringAreSupported) {
200   // Artificial examples to show that embedded nulls are supported.
201   TestSucceeds(std::string("unix-abstract:\0should-be-ok", 27), "unix-abstract",
202                "", std::string("\0should-be-ok", 13), {}, {}, "");
203 }
204 
TEST_F(URIParserTest,EncodedNullsInURIStringAreSupported)205 TEST_F(URIParserTest, EncodedNullsInURIStringAreSupported) {
206   TestSucceeds("unix-abstract:%00x", "unix-abstract", "", std::string("\0x", 2),
207                {}, {}, "");
208 }
209 
TEST_F(URIParserTest,InvalidURIsResultInFailureStatuses)210 TEST_F(URIParserTest, InvalidURIsResultInFailureStatuses) {
211   TestFails("xyz");
212   TestFails("http://foo?[bar]");
213   TestFails("http://foo?x[bar]");
214   TestFails("http://foo?bar#lol#");
215   TestFails("");
216   TestFails(":no_scheme");
217   TestFails("0invalid_scheme:must_start/with?alpha");
218 }
219 
TEST(URITest,PercentEncodePath)220 TEST(URITest, PercentEncodePath) {
221   EXPECT_EQ(URI::PercentEncodePath(
222                 // These chars are allowed.
223                 "abcdefghijklmnopqrstuvwxyz"
224                 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
225                 "0123456789"
226                 "/:@-._~!$&'()*+,;="
227                 // These chars will be escaped.
228                 "\\?%#[]^"),
229             "abcdefghijklmnopqrstuvwxyz"
230             "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
231             "0123456789"
232             "/:@-._~!$&'()*+,;="
233             "%5C%3F%25%23%5B%5D%5E");
234 }
235 
TEST(URITest,Basic)236 TEST(URITest, Basic) {
237   auto uri =
238       URI::Create("http", "server.example.com", "/path/to/file.html", {}, "");
239   ASSERT_TRUE(uri.ok()) << uri.status().ToString();
240   EXPECT_EQ(uri->scheme(), "http");
241   EXPECT_EQ(uri->authority(), "server.example.com");
242   EXPECT_EQ(uri->path(), "/path/to/file.html");
243   EXPECT_THAT(uri->query_parameter_pairs(), testing::ElementsAre());
244   EXPECT_THAT(uri->query_parameter_map(), testing::ElementsAre());
245   EXPECT_EQ(uri->fragment(), "");
246   EXPECT_EQ("http://server.example.com/path/to/file.html", uri->ToString());
247 }
248 
TEST(URITest,NoAuthority)249 TEST(URITest, NoAuthority) {
250   auto uri = URI::Create("http", "", "/path/to/file.html", {}, "");
251   ASSERT_TRUE(uri.ok()) << uri.status().ToString();
252   EXPECT_EQ(uri->scheme(), "http");
253   EXPECT_EQ(uri->authority(), "");
254   EXPECT_EQ(uri->path(), "/path/to/file.html");
255   EXPECT_THAT(uri->query_parameter_pairs(), testing::ElementsAre());
256   EXPECT_THAT(uri->query_parameter_map(), testing::ElementsAre());
257   EXPECT_EQ(uri->fragment(), "");
258   EXPECT_EQ("http:/path/to/file.html", uri->ToString());
259 }
260 
TEST(URITest,NoAuthorityRelativePath)261 TEST(URITest, NoAuthorityRelativePath) {
262   auto uri = URI::Create("http", "", "path/to/file.html", {}, "");
263   ASSERT_TRUE(uri.ok()) << uri.status().ToString();
264   EXPECT_EQ(uri->scheme(), "http");
265   EXPECT_EQ(uri->authority(), "");
266   EXPECT_EQ(uri->path(), "path/to/file.html");
267   EXPECT_THAT(uri->query_parameter_pairs(), testing::ElementsAre());
268   EXPECT_THAT(uri->query_parameter_map(), testing::ElementsAre());
269   EXPECT_EQ(uri->fragment(), "");
270   EXPECT_EQ("http:path/to/file.html", uri->ToString());
271 }
272 
TEST(URITest,AuthorityRelativePath)273 TEST(URITest, AuthorityRelativePath) {
274   auto uri =
275       URI::Create("http", "server.example.com", "path/to/file.html", {}, "");
276   ASSERT_FALSE(uri.ok());
277   EXPECT_EQ(uri.status().code(), absl::StatusCode::kInvalidArgument);
278   EXPECT_EQ(uri.status().message(),
279             "if authority is present, path must start with a '/'");
280 }
281 
TEST(URITest,QueryParams)282 TEST(URITest, QueryParams) {
283   auto uri = URI::Create("http", "server.example.com", "/path/to/file.html",
284                          {{"key", "value"}, {"key2", "value2"}}, "");
285   ASSERT_TRUE(uri.ok()) << uri.status().ToString();
286   EXPECT_EQ(uri->scheme(), "http");
287   EXPECT_EQ(uri->authority(), "server.example.com");
288   EXPECT_EQ(uri->path(), "/path/to/file.html");
289   EXPECT_THAT(
290       uri->query_parameter_pairs(),
291       testing::ElementsAre(
292           testing::AllOf(testing::Field(&URI::QueryParam::key, "key"),
293                          testing::Field(&URI::QueryParam::value, "value")),
294           testing::AllOf(testing::Field(&URI::QueryParam::key, "key2"),
295                          testing::Field(&URI::QueryParam::value, "value2"))));
296   EXPECT_THAT(uri->query_parameter_map(),
297               testing::ElementsAre(testing::Pair("key", "value"),
298                                    testing::Pair("key2", "value2")));
299   EXPECT_EQ(uri->fragment(), "");
300   EXPECT_EQ("http://server.example.com/path/to/file.html?key=value&key2=value2",
301             uri->ToString());
302 }
303 
TEST(URITest,DuplicateQueryParams)304 TEST(URITest, DuplicateQueryParams) {
305   auto uri = URI::Create(
306       "http", "server.example.com", "/path/to/file.html",
307       {{"key", "value"}, {"key2", "value2"}, {"key", "other_value"}}, "");
308   ASSERT_TRUE(uri.ok()) << uri.status().ToString();
309   EXPECT_EQ(uri->scheme(), "http");
310   EXPECT_EQ(uri->authority(), "server.example.com");
311   EXPECT_EQ(uri->path(), "/path/to/file.html");
312   EXPECT_THAT(
313       uri->query_parameter_pairs(),
314       testing::ElementsAre(
315           testing::AllOf(testing::Field(&URI::QueryParam::key, "key"),
316                          testing::Field(&URI::QueryParam::value, "value")),
317           testing::AllOf(testing::Field(&URI::QueryParam::key, "key2"),
318                          testing::Field(&URI::QueryParam::value, "value2")),
319           testing::AllOf(
320               testing::Field(&URI::QueryParam::key, "key"),
321               testing::Field(&URI::QueryParam::value, "other_value"))));
322   EXPECT_THAT(uri->query_parameter_map(),
323               testing::ElementsAre(testing::Pair("key", "other_value"),
324                                    testing::Pair("key2", "value2")));
325   EXPECT_EQ(uri->fragment(), "");
326   EXPECT_EQ(
327       "http://server.example.com/path/to/file.html"
328       "?key=value&key2=value2&key=other_value",
329       uri->ToString());
330 }
331 
TEST(URITest,Fragment)332 TEST(URITest, Fragment) {
333   auto uri = URI::Create("http", "server.example.com", "/path/to/file.html", {},
334                          "fragment");
335   ASSERT_TRUE(uri.ok()) << uri.status().ToString();
336   EXPECT_EQ(uri->scheme(), "http");
337   EXPECT_EQ(uri->authority(), "server.example.com");
338   EXPECT_EQ(uri->path(), "/path/to/file.html");
339   EXPECT_THAT(uri->query_parameter_pairs(), testing::ElementsAre());
340   EXPECT_THAT(uri->query_parameter_map(), testing::ElementsAre());
341   EXPECT_EQ(uri->fragment(), "fragment");
342   EXPECT_EQ("http://server.example.com/path/to/file.html#fragment",
343             uri->ToString());
344 }
345 
TEST(URITest,QueryParamsAndFragment)346 TEST(URITest, QueryParamsAndFragment) {
347   auto uri = URI::Create("http", "server.example.com", "/path/to/file.html",
348                          {{"key", "value"}, {"key2", "value2"}}, "fragment");
349   ASSERT_TRUE(uri.ok()) << uri.status().ToString();
350   EXPECT_EQ(uri->scheme(), "http");
351   EXPECT_EQ(uri->authority(), "server.example.com");
352   EXPECT_EQ(uri->path(), "/path/to/file.html");
353   EXPECT_THAT(
354       uri->query_parameter_pairs(),
355       testing::ElementsAre(
356           testing::AllOf(testing::Field(&URI::QueryParam::key, "key"),
357                          testing::Field(&URI::QueryParam::value, "value")),
358           testing::AllOf(testing::Field(&URI::QueryParam::key, "key2"),
359                          testing::Field(&URI::QueryParam::value, "value2"))));
360   EXPECT_THAT(uri->query_parameter_map(),
361               testing::ElementsAre(testing::Pair("key", "value"),
362                                    testing::Pair("key2", "value2")));
363   EXPECT_EQ(uri->fragment(), "fragment");
364   EXPECT_EQ(
365       "http://server.example.com/path/to/"
366       "file.html?key=value&key2=value2#fragment",
367       uri->ToString());
368 }
369 
TEST(URITest,ToStringPercentEncoding)370 TEST(URITest, ToStringPercentEncoding) {
371   auto uri = URI::Create(
372       // Scheme allowed chars.
373       "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-."
374       // Scheme escaped chars.
375       "%:/?#[]@!$&'()*,;=",
376       // Authority allowed chars.
377       "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
378       "-.+~!$&'()*+,;=:[]@"
379       // Authority escaped chars.
380       "%/?#",
381       // Path allowed chars.
382       "/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
383       "-._~!$&'()*+,;=:@"
384       // Path escaped chars.
385       "%?#[]",
386       {{// Query allowed chars.
387         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
388         "-._~!$'()*+,;:@/?"
389         // Query escaped chars.
390         "%=&#[]",
391         // Query allowed chars.
392         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
393         "-._~!$'()*+,;:@/?"
394         // Query escaped chars.
395         "%=&#[]"}},
396       // Fragment allowed chars.
397       "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
398       "-._~!$'()*+,;:@/?=&"
399       // Fragment escaped chars.
400       "%#[]");
401   ASSERT_TRUE(uri.ok()) << uri.status().ToString();
402   EXPECT_EQ(uri->scheme(),
403             "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-."
404             "%:/?#[]@!$&'()*,;=");
405   EXPECT_EQ(uri->authority(),
406             "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
407             "-.+~!$&'()*+,;=:[]@"
408             "%/?#");
409   EXPECT_EQ(uri->path(),
410             "/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
411             "-._~!$&'()*+,;=:@"
412             "%?#[]");
413   EXPECT_THAT(
414       uri->query_parameter_pairs(),
415       testing::ElementsAre(testing::AllOf(
416           testing::Field(
417               &URI::QueryParam::key,
418               "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
419               "-._~!$'()*+,;:@/?"
420               "%=&#[]"),
421           testing::Field(
422               &URI::QueryParam::value,
423               "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
424               "-._~!$'()*+,;:@/?"
425               "%=&#[]"))));
426   EXPECT_THAT(
427       uri->query_parameter_map(),
428       testing::ElementsAre(testing::Pair(
429           "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
430           "-._~!$'()*+,;:@/?"
431           "%=&#[]",
432           "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
433           "-._~!$'()*+,;:@/?"
434           "%=&#[]")));
435   EXPECT_EQ(uri->fragment(),
436             "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
437             "-._~!$'()*+,;:@/?=&"
438             "%#[]");
439   EXPECT_EQ(
440       // Scheme
441       "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-."
442       "%25%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2C%3B%3D"
443       // Authority
444       "://abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
445       "-.+~!$&'()*+,;=:[]@"
446       "%25%2F%3F%23"
447       // Path
448       "/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
449       "-._~!$&'()*+,;=:@"
450       "%25%3F%23%5B%5D"
451       // Query
452       "?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
453       "-._~!$'()*+,;:@/?"
454       "%25%3D%26%23%5B%5D"
455       "=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
456       "-._~!$'()*+,;:@/?"
457       "%25%3D%26%23%5B%5D"
458       // Fragment
459       "#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
460       "-._~!$'()*+,;:@/?=&"
461       "%25%23%5B%5D",
462       uri->ToString());
463 }
464 
465 }  // namespace grpc_core
466 
main(int argc,char ** argv)467 int main(int argc, char** argv) {
468   testing::InitGoogleTest(&argc, argv);
469   grpc::testing::TestEnvironment env(&argc, argv);
470   grpc_init();
471   auto result = RUN_ALL_TESTS();
472   grpc_shutdown();
473   return result;
474 }
475