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

Unified Diff: net/spdy/header_coalescer_test.cc

Issue 2184253002: Reset HTTP/2 stream on line-folded response headers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re: #7. Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/spdy/header_coalescer.cc ('k') | net/spdy/spdy_network_transaction_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/header_coalescer_test.cc
diff --git a/net/spdy/header_coalescer_test.cc b/net/spdy/header_coalescer_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..986e775321076f8d89cce04affe463970df0a604
--- /dev/null
+++ b/net/spdy/header_coalescer_test.cc
@@ -0,0 +1,80 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "header_coalescer.h"
+
+#include <string>
+
+#include "base/strings/string_piece.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::ElementsAre;
+using ::testing::Pair;
+
+namespace net {
+namespace test {
+
+class HeaderCoalescerTest : public ::testing::Test {
+ public:
+ protected:
+ HeaderCoalescer header_coalescer_;
+};
+
+TEST_F(HeaderCoalescerTest, CorrectHeaders) {
+ header_coalescer_.OnHeader(":foo", "bar");
+ header_coalescer_.OnHeader("baz", "qux");
+ EXPECT_FALSE(header_coalescer_.error_seen());
+
+ SpdyHeaderBlock header_block = header_coalescer_.release_headers();
+ EXPECT_THAT(header_block,
+ ElementsAre(Pair(":foo", "bar"), Pair("baz", "qux")));
+}
+
+TEST_F(HeaderCoalescerTest, EmptyHeaderKey) {
+ EXPECT_FALSE(header_coalescer_.error_seen());
+ header_coalescer_.OnHeader("", "foo");
+ EXPECT_TRUE(header_coalescer_.error_seen());
+}
+
+TEST_F(HeaderCoalescerTest, HeaderBlockTooLarge) {
+ // 3 byte key, 256 * 1024 - 40 byte value, 32 byte overhead:
+ // less than 256 * 1024 bytes in total.
+ std::string data(256 * 1024 - 40, 'a');
+ header_coalescer_.OnHeader("foo", data);
+ EXPECT_FALSE(header_coalescer_.error_seen());
+
+ // Another 3 + 3 + 32 bytes: too large.
+ header_coalescer_.OnHeader("bar", "baz");
+ EXPECT_TRUE(header_coalescer_.error_seen());
+}
+
+TEST_F(HeaderCoalescerTest, PseudoHeadersMustNotFollowRegularHeaders) {
+ header_coalescer_.OnHeader("foo", "bar");
+ EXPECT_FALSE(header_coalescer_.error_seen());
+ header_coalescer_.OnHeader(":baz", "qux");
+ EXPECT_TRUE(header_coalescer_.error_seen());
+}
+
+TEST_F(HeaderCoalescerTest, Append) {
+ header_coalescer_.OnHeader("foo", "bar");
+ header_coalescer_.OnHeader("cookie", "baz");
+ header_coalescer_.OnHeader("foo", "quux");
+ header_coalescer_.OnHeader("cookie", "qux");
+ EXPECT_FALSE(header_coalescer_.error_seen());
+
+ SpdyHeaderBlock header_block = header_coalescer_.release_headers();
+ EXPECT_THAT(header_block,
+ ElementsAre(Pair("foo", base::StringPiece("bar\0quux", 8)),
+ Pair("cookie", "baz; qux")));
+}
+
+TEST_F(HeaderCoalescerTest, CRLFInHeaderValue) {
+ EXPECT_FALSE(header_coalescer_.error_seen());
+ header_coalescer_.OnHeader("foo", "bar\r\nbaz");
+ EXPECT_TRUE(header_coalescer_.error_seen());
+}
+
+} // namespace test
+} // namespace net
« no previous file with comments | « net/spdy/header_coalescer.cc ('k') | net/spdy/spdy_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698