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

Side by Side Diff: net/http/http_util_unittest.cc

Issue 2101963002: Skip header lines with invalid header name (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
« net/http/http_util.cc ('K') | « net/http/http_util.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "net/http/http_util.h" 8 #include "net/http/http_util.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 EXPECT_EQ(std::string("foo"), it.name()); 171 EXPECT_EQ(std::string("foo"), it.name());
172 EXPECT_EQ(std::string("1"), it.values()); 172 EXPECT_EQ(std::string("1"), it.values());
173 173
174 ASSERT_TRUE(it.GetNext()); 174 ASSERT_TRUE(it.GetNext());
175 EXPECT_EQ(std::string("bar"), it.name()); 175 EXPECT_EQ(std::string("bar"), it.name());
176 EXPECT_EQ(std::string("4"), it.values()); 176 EXPECT_EQ(std::string("4"), it.values());
177 177
178 EXPECT_FALSE(it.GetNext()); 178 EXPECT_FALSE(it.GetNext());
179 } 179 }
180 180
181 TEST(HttpUtilTest, HeadersIterator_MalformedName) {
182 {
183 std::string headers = "[ignore me] /: 3\r\n";
184
185 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n");
186
187 EXPECT_FALSE(it.GetNext());
188 }
189 {
190 std::string headers = "[ignore me] /: 3\r\nbar: 4\n";
191
192 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n");
193
194 ASSERT_TRUE(it.GetNext());
195 EXPECT_EQ(std::string("bar"), it.name());
196 EXPECT_EQ(std::string("4"), it.values());
197
198 EXPECT_FALSE(it.GetNext());
199 }
mmenke 2016/06/28 14:54:01 Could you split this into two tests? Not too conc
robwu 2016/06/28 15:24:42 Done.
200 }
201
181 TEST(HttpUtilTest, HeadersIterator_AdvanceTo) { 202 TEST(HttpUtilTest, HeadersIterator_AdvanceTo) {
182 std::string headers = "foo: 1\r\n: 2\r\n3\r\nbar: 4"; 203 std::string headers = "foo: 1\r\n: 2\r\n3\r\nbar: 4";
183 204
184 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); 205 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n");
185 EXPECT_TRUE(it.AdvanceTo("foo")); 206 EXPECT_TRUE(it.AdvanceTo("foo"));
186 EXPECT_EQ("foo", it.name()); 207 EXPECT_EQ("foo", it.name());
187 EXPECT_TRUE(it.AdvanceTo("bar")); 208 EXPECT_TRUE(it.AdvanceTo("bar"));
188 EXPECT_EQ("bar", it.name()); 209 EXPECT_EQ("bar", it.name());
189 EXPECT_FALSE(it.AdvanceTo("blat")); 210 EXPECT_FALSE(it.AdvanceTo("blat"));
190 EXPECT_FALSE(it.GetNext()); // should be at end of headers 211 EXPECT_FALSE(it.GetNext()); // should be at end of headers
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 EXPECT_TRUE(HttpUtil::HasValidators(v1_1, kEtagWeak, kLastModified)); 1385 EXPECT_TRUE(HttpUtil::HasValidators(v1_1, kEtagWeak, kLastModified));
1365 EXPECT_TRUE(HttpUtil::HasValidators(v1_1, kEtagEmpty, kLastModified)); 1386 EXPECT_TRUE(HttpUtil::HasValidators(v1_1, kEtagEmpty, kLastModified));
1366 1387
1367 EXPECT_FALSE(HttpUtil::HasValidators(v1_1, kMissing, kLastModifiedInvalid)); 1388 EXPECT_FALSE(HttpUtil::HasValidators(v1_1, kMissing, kLastModifiedInvalid));
1368 EXPECT_TRUE(HttpUtil::HasValidators(v1_1, kEtagStrong, kLastModifiedInvalid)); 1389 EXPECT_TRUE(HttpUtil::HasValidators(v1_1, kEtagStrong, kLastModifiedInvalid));
1369 EXPECT_TRUE(HttpUtil::HasValidators(v1_1, kEtagWeak, kLastModifiedInvalid)); 1390 EXPECT_TRUE(HttpUtil::HasValidators(v1_1, kEtagWeak, kLastModifiedInvalid));
1370 EXPECT_TRUE(HttpUtil::HasValidators(v1_1, kEtagEmpty, kLastModifiedInvalid)); 1391 EXPECT_TRUE(HttpUtil::HasValidators(v1_1, kEtagEmpty, kLastModifiedInvalid));
1371 } 1392 }
1372 1393
1373 } // namespace net 1394 } // namespace net
OLDNEW
« net/http/http_util.cc ('K') | « net/http/http_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698