Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: net/quic/core/spdy_utils_test.cc

Issue 2963863002: Allow trailing headers with duplicate keys. Protected by FLAGS_quic_reloadable_flag_quic_allow_dupl… (Closed)
Patch Set: Rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/spdy_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "net/quic/core/spdy_utils.h" 4 #include "net/quic/core/spdy_utils.h"
5 5
6 #include <memory> 6 #include <memory>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "net/quic/platform/api/quic_flag_utils.h"
10 #include "net/quic/platform/api/quic_flags.h"
9 #include "net/quic/platform/api/quic_string_piece.h" 11 #include "net/quic/platform/api/quic_string_piece.h"
10 #include "net/quic/platform/api/quic_text_utils.h" 12 #include "net/quic/platform/api/quic_text_utils.h"
11 #include "net/test/gtest_util.h" 13 #include "net/test/gtest_util.h"
12 14
13 using std::string; 15 using std::string;
14 using testing::UnorderedElementsAre; 16 using testing::UnorderedElementsAre;
15 using testing::Pair; 17 using testing::Pair;
16 18
17 namespace net { 19 namespace net {
18 namespace test { 20 namespace test {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // Pseudo headers are illegal in trailers. 241 // Pseudo headers are illegal in trailers.
240 auto trailers = 242 auto trailers =
241 FromList({{":pseudo_key", "value"}, {kFinalOffsetHeaderKey, "1234"}}); 243 FromList({{":pseudo_key", "value"}, {kFinalOffsetHeaderKey, "1234"}});
242 size_t final_byte_offset = 0; 244 size_t final_byte_offset = 0;
243 SpdyHeaderBlock block; 245 SpdyHeaderBlock block;
244 EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset, 246 EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
245 &block)); 247 &block));
246 } 248 }
247 249
248 TEST(CopyAndValidateTrailers, DuplicateTrailers) { 250 TEST(CopyAndValidateTrailers, DuplicateTrailers) {
249 // Duplicate trailers are not allowed. 251 // Duplicate trailers are allowed, and their values are concatenated into a
252 // single string delimted with '\0'. Some of the duplicate headers
253 // deliberately have an empty value.
254 FLAGS_quic_reloadable_flag_quic_handle_duplicate_trailers = true;
250 auto trailers = FromList({{"key", "value0"}, 255 auto trailers = FromList({{"key", "value0"},
251 {"key", "value1"}, 256 {"key", "value1"},
252 {"key", ""}, 257 {"key", ""},
253 {"key", ""}, 258 {"key", ""},
254 {"key", "value2"}, 259 {"key", "value2"},
255 {"key", ""}, 260 {"key", ""},
256 {kFinalOffsetHeaderKey, "1234"}, 261 {kFinalOffsetHeaderKey, "1234"},
257 {"other_key", "value"}, 262 {"other_key", "value"},
258 {"key", "non_contiguous_duplicate"}}); 263 {"key", "non_contiguous_duplicate"}});
259 size_t final_byte_offset = 0; 264 size_t final_byte_offset = 0;
260 SpdyHeaderBlock block; 265 SpdyHeaderBlock block;
261 EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset, 266 EXPECT_TRUE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
262 &block)); 267 &block));
268 EXPECT_THAT(
269 block,
270 UnorderedElementsAre(
271 Pair("key",
272 QuicStringPiece(
273 "value0\0value1\0\0\0value2\0\0non_contiguous_duplicate",
274 48)),
275 Pair("other_key", "value")));
276 }
277
278 TEST(CopyAndValidateTrailers, DuplicateCookies) {
279 // Duplicate cookie headers in trailers should be concatenated into a single
280 // "; " delimted string.
281 FLAGS_quic_reloadable_flag_quic_handle_duplicate_trailers = true;
282 auto headers = FromList({{"cookie", " part 1"},
283 {"cookie", "part 2 "},
284 {"cookie", "part3"},
285 {"key", "value"},
286 {kFinalOffsetHeaderKey, "1234"},
287 {"cookie", " non_contiguous_cookie!"}});
288
289 size_t final_byte_offset = 0;
290 SpdyHeaderBlock block;
291 EXPECT_TRUE(
292 SpdyUtils::CopyAndValidateTrailers(*headers, &final_byte_offset, &block));
293 EXPECT_THAT(
294 block,
295 UnorderedElementsAre(
296 Pair("cookie", " part 1; part 2 ; part3; non_contiguous_cookie!"),
297 Pair("key", "value")));
263 } 298 }
264 299
265 TEST(GetUrlFromHeaderBlock, Basic) { 300 TEST(GetUrlFromHeaderBlock, Basic) {
266 SpdyHeaderBlock headers; 301 SpdyHeaderBlock headers;
267 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 302 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
268 headers[":scheme"] = "https"; 303 headers[":scheme"] = "https";
269 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 304 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
270 headers[":authority"] = "www.google.com"; 305 headers[":authority"] = "www.google.com";
271 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 306 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
272 headers[":path"] = "/index.html"; 307 headers[":path"] = "/index.html";
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 TEST(PopulateHeaderBlockFromUrl, Failure) { 354 TEST(PopulateHeaderBlockFromUrl, Failure) {
320 SpdyHeaderBlock headers; 355 SpdyHeaderBlock headers;
321 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/", &headers)); 356 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/", &headers));
322 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/index.html", &headers)); 357 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/index.html", &headers));
323 EXPECT_FALSE( 358 EXPECT_FALSE(
324 SpdyUtils::PopulateHeaderBlockFromUrl("www.google.com/", &headers)); 359 SpdyUtils::PopulateHeaderBlockFromUrl("www.google.com/", &headers));
325 } 360 }
326 361
327 } // namespace test 362 } // namespace test
328 } // namespace net 363 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/spdy_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698