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

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

Issue 15688012: net: don't process truncated headers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only enforce this for HTTPS URLs. Created 7 years, 6 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 | Annotate | Revision Log
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 "net/http/http_stream_parser.h" 5 #include "net/http/http_stream_parser.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 scoped_refptr<IOBuffer> body_buffer(new IOBuffer(kBodySize)); 294 scoped_refptr<IOBuffer> body_buffer(new IOBuffer(kBodySize));
295 rv = parser.ReadResponseBody(body_buffer, kBodySize, callback.callback()); 295 rv = parser.ReadResponseBody(body_buffer, kBodySize, callback.callback());
296 ASSERT_EQ(ERR_IO_PENDING, rv); 296 ASSERT_EQ(ERR_IO_PENDING, rv);
297 data.RunFor(1); 297 data.RunFor(1);
298 298
299 ASSERT_TRUE(callback.have_result()); 299 ASSERT_TRUE(callback.have_result());
300 rv = callback.WaitForResult(); 300 rv = callback.WaitForResult();
301 ASSERT_EQ(kBodySize, rv); 301 ASSERT_EQ(kBodySize, rv);
302 } 302 }
303 303
304 TEST(HttpStreamParser, TruncatedHeaders) {
305 MockRead truncated_status_reads[] = {
306 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 20"),
307 MockRead(SYNCHRONOUS, 0, 2), // EOF
308 };
309
310 MockRead truncated_after_status_reads[] = {
311 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 Ok\r\n"),
312 MockRead(SYNCHRONOUS, 0, 2), // EOF
313 };
314
315 MockRead truncated_in_header_reads[] = {
316 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 Ok\r\nHead"),
317 MockRead(SYNCHRONOUS, 0, 2), // EOF
318 };
319
320 MockRead truncated_after_header_reads[] = {
321 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 Ok\r\nHeader: foo\r\n"),
322 MockRead(SYNCHRONOUS, 0, 2), // EOF
323 };
324
325 MockRead truncated_after_final_newline_reads[] = {
326 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 Ok\r\nHeader: foo\r\n\r"),
327 MockRead(SYNCHRONOUS, 0, 2), // EOF
328 };
329
330 MockRead not_truncated_reads[] = {
331 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 Ok\r\nHeader: foo\r\n\r\n"),
332 MockRead(SYNCHRONOUS, 0, 2), // EOF
333 };
334
335 MockRead* reads[] = {
336 truncated_status_reads,
337 truncated_after_status_reads,
338 truncated_in_header_reads,
339 truncated_after_header_reads,
340 truncated_after_final_newline_reads,
341 not_truncated_reads,
342 };
343
344 MockWrite writes[] = {
345 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n\r\n"),
346 };
347
348 enum {
349 HTTP = 0,
350 HTTPS,
351 NUM_PROTOCOLS,
352 };
353
354 for (size_t protocol = 0; protocol < NUM_PROTOCOLS; protocol++) {
355 SCOPED_TRACE(protocol);
356
357 for (size_t i = 0; i < arraysize(reads); i++) {
358 SCOPED_TRACE(i);
359 DeterministicSocketData data(reads[i], 2, writes, arraysize(writes));
360 data.set_connect_data(MockConnect(SYNCHRONOUS, OK));
361 data.SetStop(3);
362
363 scoped_ptr<DeterministicMockTCPClientSocket> transport(
364 new DeterministicMockTCPClientSocket(NULL, &data));
365 data.set_delegate(transport->AsWeakPtr());
366
367 TestCompletionCallback callback;
368 int rv = transport->Connect(callback.callback());
369 rv = callback.GetResult(rv);
370 ASSERT_EQ(OK, rv);
371
372 scoped_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle);
373 socket_handle->set_socket(transport.release());
374
375 HttpRequestInfo request_info;
376 request_info.method = "GET";
377 if (protocol == HTTP) {
378 request_info.url = GURL("http://localhost");
379 } else {
380 request_info.url = GURL("https://localhost");
381 }
382 request_info.load_flags = LOAD_NORMAL;
383
384 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer);
385 HttpStreamParser parser(socket_handle.get(), &request_info, read_buffer,
386 BoundNetLog());
387
388 HttpRequestHeaders request_headers;
389 HttpResponseInfo response_info;
390 rv = parser.SendRequest("GET / HTTP/1.1\r\n", request_headers,
391 &response_info, callback.callback());
392 ASSERT_EQ(OK, rv);
393
394 rv = parser.ReadResponseHeaders(callback.callback());
395 if (i == arraysize(reads) - 1) {
396 EXPECT_EQ(OK, rv);
397 EXPECT_TRUE(response_info.headers.get());
398 } else {
399 if (protocol == HTTP) {
400 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv);
401 EXPECT_TRUE(response_info.headers.get());
402 } else {
403 EXPECT_EQ(ERR_HEADERS_TRUNCATED, rv);
404 EXPECT_FALSE(response_info.headers.get());
405 }
406 }
407 }
408 }
409 }
410
304 } // namespace net 411 } // namespace net
OLDNEW
« net/http/http_stream_parser.cc ('K') | « net/http/http_stream_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698