OLD | NEW |
---|---|
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" |
Bence
2017/02/23 23:33:04
In header_coalescer.h, HeaderCoalescer::OnHeader()
xunjieli
2017/02/24 16:33:32
base::StringPiece is used on line 70.
Bence
2017/02/24 16:51:30
header_coalescer.h also uses base::StringPiece, an
xunjieli
2017/02/24 17:36:55
Bence, I think this test file should include strin
Bence
2017/02/24 18:48:29
Good question. The style guide (https://google.gi
| |
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 Loading... | |
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 std::string 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 // where token is any visible US ASCII characters. | |
asanka
2017/02/23 23:18:54
|token| is defined in RFC 7230 Appendix B as:
tch
Bence
2017/02/23 23:33:04
Section 3.2.6 might be a more specific reference f
xunjieli
2017/02/24 16:33:32
Acknowledged.
xunjieli
2017/02/24 16:33:32
Done.
| |
89 TEST_F(HeaderCoalescerTest, HeaderNameValid) { | |
90 std::string header_name( | |
91 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&'*+-." | |
92 "^_`|~"); | |
93 header_coalescer_.OnHeader(header_name, "foo"); | |
94 EXPECT_FALSE(header_coalescer_.error_seen()); | |
95 SpdyHeaderBlock header_block = header_coalescer_.release_headers(); | |
96 EXPECT_THAT(header_block, ElementsAre(Pair(header_name, "foo"))); | |
97 } | |
98 | |
99 // RFC 7230 Section 3.2. Valid header value is defined as: | |
100 // field-value = *( field-content / obs-fold ) | |
101 // field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] | |
102 // field-vchar = VCHAR / obs-text | |
103 // | |
104 // obs-fold = CRLF 1*( SP / HTAB ) | |
105 // ; obsolete line folding | |
106 // ; see Section 3.2.4 | |
107 TEST_F(HeaderCoalescerTest, HeaderValueValid) { | |
108 // Add two header, one with an HTAB and one with a SP. | |
Bence
2017/02/23 23:33:04
s/header/headers/
xunjieli
2017/02/24 16:33:32
Done.
| |
109 std::string header_values[2]; | |
110 char prefixes[] = {'\t', ' '}; | |
111 for (int i = 0; i < 2; ++i) { | |
112 std::vector<char> value; | |
113 value.push_back(prefixes[i]); | |
114 // obs-text. From 0x80 to 0xff. | |
115 for (int j = 0x80; j <= 0xff; j++) { | |
116 value.push_back(j); | |
117 } | |
118 header_values[i] = std::string(value.data()); | |
119 header_values[i].append( | |
120 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&'*+" | |
121 "-.^_`|~"); | |
asanka
2017/02/23 23:18:54
This should be VCHAR, which is defined in RFC 5234
xunjieli
2017/02/24 16:33:32
Done.
| |
122 header_coalescer_.OnHeader(base::StringPrintf("%s_%d", "foo", i), | |
123 header_values[i]); | |
124 EXPECT_FALSE(header_coalescer_.error_seen()); | |
125 } | |
126 SpdyHeaderBlock header_block = header_coalescer_.release_headers(); | |
127 EXPECT_THAT(header_block, | |
128 ElementsAre(Pair("foo_0", header_values[0]), | |
129 Pair("foo_1", header_values[1]))); | |
130 } | |
131 | |
79 } // namespace test | 132 } // namespace test |
133 | |
80 } // namespace net | 134 } // namespace net |
OLD | NEW |