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

Side by Side Diff: net/spdy/header_coalescer_test.cc

Issue 2710053002: HTTP/2 Check header names in HeaderCoalescer (Closed)
Patch Set: minor optimization Created 3 years, 9 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/spdy/header_coalescer.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 4
5 #include "header_coalescer.h" 5 #include "header_coalescer.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
10 #include "base/strings/stringprintf.h"
10 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 using ::testing::ElementsAre; 14 using ::testing::ElementsAre;
14 using ::testing::Pair; 15 using ::testing::Pair;
15 16
16 namespace net { 17 namespace net {
17 namespace test { 18 namespace test {
18 19
19 class HeaderCoalescerTest : public ::testing::Test { 20 class HeaderCoalescerTest : public ::testing::Test {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 ElementsAre(Pair("foo", base::StringPiece("bar\0quux", 8)), 70 ElementsAre(Pair("foo", base::StringPiece("bar\0quux", 8)),
70 Pair("cookie", "baz; qux"))); 71 Pair("cookie", "baz; qux")));
71 } 72 }
72 73
73 TEST_F(HeaderCoalescerTest, CRLFInHeaderValue) { 74 TEST_F(HeaderCoalescerTest, CRLFInHeaderValue) {
74 EXPECT_FALSE(header_coalescer_.error_seen()); 75 EXPECT_FALSE(header_coalescer_.error_seen());
75 header_coalescer_.OnHeader("foo", "bar\r\nbaz"); 76 header_coalescer_.OnHeader("foo", "bar\r\nbaz");
76 EXPECT_TRUE(header_coalescer_.error_seen()); 77 EXPECT_TRUE(header_coalescer_.error_seen());
77 } 78 }
78 79
80 TEST_F(HeaderCoalescerTest, HeaderNameNotValid) {
81 base::StringPiece header_name("\x01\x7F\x80\xff");
82 header_coalescer_.OnHeader(header_name, "foo");
83 EXPECT_TRUE(header_coalescer_.error_seen());
84 }
85
86 // RFC 7230 Section 3.2. Valid header name is defined as:
87 // field-name = token
88 // token = 1*tchar
89 // tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." /
90 // "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA
91 TEST_F(HeaderCoalescerTest, HeaderNameValid) {
92 base::StringPiece header_name(
93 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&'*+-."
94 "^_`|~");
95 header_coalescer_.OnHeader(header_name, "foo");
96 EXPECT_FALSE(header_coalescer_.error_seen());
97 SpdyHeaderBlock header_block = header_coalescer_.release_headers();
98 EXPECT_THAT(header_block, ElementsAre(Pair(header_name, "foo")));
99 }
100
101 // RFC 7230 Section 3.2. Valid header value is defined as:
102 // field-value = *( field-content / obs-fold )
103 // field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
104 // field-vchar = VCHAR / obs-text
105 //
106 // obs-fold = CRLF 1*( SP / HTAB )
107 // ; obsolete line folding
108 // ; see Section 3.2.4
109 TEST_F(HeaderCoalescerTest, HeaderValueValid) {
110 // Add two headers, one with an HTAB and one with a SP.
111 std::vector<char> header_values[2];
112 char prefixes[] = {'\t', ' '};
113 for (int i = 0; i < 2; ++i) {
114 header_values[i] = std::vector<char>();
115 header_values[i].push_back(prefixes[i]);
116 // obs-text. From 0x80 to 0xff.
117 for (int j = 0x80; j <= 0xff; ++j) {
118 header_values[i].push_back(j);
119 }
120 // vchar
121 for (int j = 0x21; j <= 0x7E; ++j) {
122 header_values[i].push_back(j);
123 }
124 header_coalescer_.OnHeader(
125 base::StringPrintf("%s_%d", "foo", i),
126 base::StringPiece(header_values[i].data(), header_values[i].size()));
127 EXPECT_FALSE(header_coalescer_.error_seen());
128 }
129 SpdyHeaderBlock header_block = header_coalescer_.release_headers();
130 EXPECT_THAT(header_block,
131 ElementsAre(Pair("foo_0",
132 base::StringPiece(header_values[0].data(),
133 header_values[0].size())),
134 Pair("foo_1",
135 base::StringPiece(header_values[1].data(),
136 header_values[1].size()))));
137 }
138
79 } // namespace test 139 } // namespace test
140
80 } // namespace net 141 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/header_coalescer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698