OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/tools/quic/quic_simple_server_stream.h" | 5 #include "net/tools/quic/quic_simple_server_stream.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/strings/string_piece.h" | |
12 #include "net/quic/core/quic_utils.h" | 11 #include "net/quic/core/quic_utils.h" |
13 #include "net/quic/core/spdy_utils.h" | 12 #include "net/quic/core/spdy_utils.h" |
14 #include "net/quic/platform/api/quic_ptr_util.h" | 13 #include "net/quic/platform/api/quic_ptr_util.h" |
15 #include "net/quic/platform/api/quic_socket_address.h" | 14 #include "net/quic/platform/api/quic_socket_address.h" |
16 #include "net/quic/test_tools/crypto_test_utils.h" | 15 #include "net/quic/test_tools/crypto_test_utils.h" |
17 #include "net/quic/test_tools/quic_stream_peer.h" | 16 #include "net/quic/test_tools/quic_stream_peer.h" |
18 #include "net/quic/test_tools/quic_test_utils.h" | 17 #include "net/quic/test_tools/quic_test_utils.h" |
19 #include "net/test/gtest_util.h" | 18 #include "net/test/gtest_util.h" |
20 #include "net/tools/quic/quic_http_response_cache.h" | 19 #include "net/tools/quic/quic_http_response_cache.h" |
21 #include "net/tools/quic/quic_simple_server_session.h" | 20 #include "net/tools/quic/quic_simple_server_session.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
24 | 23 |
25 using base::StringPiece; | |
26 using std::string; | 24 using std::string; |
27 using testing::_; | 25 using testing::_; |
28 using testing::AnyNumber; | 26 using testing::AnyNumber; |
29 using testing::Invoke; | 27 using testing::Invoke; |
30 using testing::InSequence; | 28 using testing::InSequence; |
31 using testing::Return; | 29 using testing::Return; |
32 using testing::StrictMock; | 30 using testing::StrictMock; |
33 | 31 |
34 namespace net { | 32 namespace net { |
35 namespace test { | 33 namespace test { |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 EXPECT_TRUE(stream_->reading_stopped()); | 525 EXPECT_TRUE(stream_->reading_stopped()); |
528 } | 526 } |
529 EXPECT_TRUE(stream_->write_side_closed()); | 527 EXPECT_TRUE(stream_->write_side_closed()); |
530 } | 528 } |
531 | 529 |
532 TEST_P(QuicSimpleServerStreamTest, InvalidMultipleContentLength) { | 530 TEST_P(QuicSimpleServerStreamTest, InvalidMultipleContentLength) { |
533 EXPECT_CALL(session_, SendRstStream(_, QUIC_STREAM_NO_ERROR, _)).Times(0); | 531 EXPECT_CALL(session_, SendRstStream(_, QUIC_STREAM_NO_ERROR, _)).Times(0); |
534 | 532 |
535 SpdyHeaderBlock request_headers; | 533 SpdyHeaderBlock request_headers; |
536 // \000 is a way to write the null byte when followed by a literal digit. | 534 // \000 is a way to write the null byte when followed by a literal digit. |
537 header_list_.OnHeader("content-length", StringPiece("11\00012", 5)); | 535 header_list_.OnHeader("content-length", QuicStringPiece("11\00012", 5)); |
538 | 536 |
539 headers_string_ = SpdyUtils::SerializeUncompressedHeaders(request_headers); | 537 headers_string_ = SpdyUtils::SerializeUncompressedHeaders(request_headers); |
540 | 538 |
541 EXPECT_CALL(session_, WriteHeadersMock(_, _, _, _, _)); | 539 EXPECT_CALL(session_, WriteHeadersMock(_, _, _, _, _)); |
542 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 540 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
543 .Times(AnyNumber()) | 541 .Times(AnyNumber()) |
544 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); | 542 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
545 stream_->OnStreamHeaderList(true, kFakeFrameLen, header_list_); | 543 stream_->OnStreamHeaderList(true, kFakeFrameLen, header_list_); |
546 | 544 |
547 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); | 545 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); |
548 EXPECT_TRUE(stream_->reading_stopped()); | 546 EXPECT_TRUE(stream_->reading_stopped()); |
549 EXPECT_TRUE(stream_->write_side_closed()); | 547 EXPECT_TRUE(stream_->write_side_closed()); |
550 } | 548 } |
551 | 549 |
552 TEST_P(QuicSimpleServerStreamTest, InvalidLeadingNullContentLength) { | 550 TEST_P(QuicSimpleServerStreamTest, InvalidLeadingNullContentLength) { |
553 EXPECT_CALL(session_, SendRstStream(_, QUIC_STREAM_NO_ERROR, _)).Times(0); | 551 EXPECT_CALL(session_, SendRstStream(_, QUIC_STREAM_NO_ERROR, _)).Times(0); |
554 | 552 |
555 SpdyHeaderBlock request_headers; | 553 SpdyHeaderBlock request_headers; |
556 // \000 is a way to write the null byte when followed by a literal digit. | 554 // \000 is a way to write the null byte when followed by a literal digit. |
557 header_list_.OnHeader("content-length", StringPiece("\00012", 3)); | 555 header_list_.OnHeader("content-length", QuicStringPiece("\00012", 3)); |
558 | 556 |
559 headers_string_ = SpdyUtils::SerializeUncompressedHeaders(request_headers); | 557 headers_string_ = SpdyUtils::SerializeUncompressedHeaders(request_headers); |
560 | 558 |
561 EXPECT_CALL(session_, WriteHeadersMock(_, _, _, _, _)); | 559 EXPECT_CALL(session_, WriteHeadersMock(_, _, _, _, _)); |
562 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 560 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
563 .Times(AnyNumber()) | 561 .Times(AnyNumber()) |
564 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); | 562 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
565 stream_->OnStreamHeaderList(true, kFakeFrameLen, header_list_); | 563 stream_->OnStreamHeaderList(true, kFakeFrameLen, header_list_); |
566 | 564 |
567 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); | 565 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); |
568 EXPECT_TRUE(stream_->reading_stopped()); | 566 EXPECT_TRUE(stream_->reading_stopped()); |
569 EXPECT_TRUE(stream_->write_side_closed()); | 567 EXPECT_TRUE(stream_->write_side_closed()); |
570 } | 568 } |
571 | 569 |
572 TEST_P(QuicSimpleServerStreamTest, ValidMultipleContentLength) { | 570 TEST_P(QuicSimpleServerStreamTest, ValidMultipleContentLength) { |
573 SpdyHeaderBlock request_headers; | 571 SpdyHeaderBlock request_headers; |
574 // \000 is a way to write the null byte when followed by a literal digit. | 572 // \000 is a way to write the null byte when followed by a literal digit. |
575 header_list_.OnHeader("content-length", StringPiece("11\00011", 5)); | 573 header_list_.OnHeader("content-length", QuicStringPiece("11\00011", 5)); |
576 | 574 |
577 headers_string_ = SpdyUtils::SerializeUncompressedHeaders(request_headers); | 575 headers_string_ = SpdyUtils::SerializeUncompressedHeaders(request_headers); |
578 | 576 |
579 stream_->OnStreamHeaderList(false, kFakeFrameLen, header_list_); | 577 stream_->OnStreamHeaderList(false, kFakeFrameLen, header_list_); |
580 | 578 |
581 EXPECT_EQ(11, QuicSimpleServerStreamPeer::content_length(stream_)); | 579 EXPECT_EQ(11, QuicSimpleServerStreamPeer::content_length(stream_)); |
582 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); | 580 EXPECT_FALSE(QuicStreamPeer::read_side_closed(stream_)); |
583 EXPECT_FALSE(stream_->reading_stopped()); | 581 EXPECT_FALSE(stream_->reading_stopped()); |
584 EXPECT_FALSE(stream_->write_side_closed()); | 582 EXPECT_FALSE(stream_->write_side_closed()); |
585 } | 583 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 0x3a, 0x73, 0x63, 0x68, // :sch | 629 0x3a, 0x73, 0x63, 0x68, // :sch |
632 0x65, 0x6d, 0x65, 0x00, // eme. | 630 0x65, 0x6d, 0x65, 0x00, // eme. |
633 0x00, 0x00, 0x00, 0x00, // .... | 631 0x00, 0x00, 0x00, 0x00, // .... |
634 0x00, 0x00, 0x08, 0x3a, // ...: | 632 0x00, 0x00, 0x08, 0x3a, // ...: |
635 0x76, 0x65, 0x72, 0x73, // vers | 633 0x76, 0x65, 0x72, 0x73, // vers |
636 0x96, 0x6f, 0x6e, 0x00, // <i(69)>on. | 634 0x96, 0x6f, 0x6e, 0x00, // <i(69)>on. |
637 0x00, 0x00, 0x08, 0x48, // ...H | 635 0x00, 0x00, 0x08, 0x48, // ...H |
638 0x54, 0x54, 0x50, 0x2f, // TTP/ | 636 0x54, 0x54, 0x50, 0x2f, // TTP/ |
639 0x31, 0x2e, 0x31, // 1.1 | 637 0x31, 0x2e, 0x31, // 1.1 |
640 }; | 638 }; |
641 StringPiece data(arr, arraysize(arr)); | 639 QuicStringPiece data(arr, arraysize(arr)); |
642 QuicStreamFrame frame(stream_->id(), true, 0, data); | 640 QuicStreamFrame frame(stream_->id(), true, 0, data); |
643 // Verify that we don't crash when we get a invalid headers in stream frame. | 641 // Verify that we don't crash when we get a invalid headers in stream frame. |
644 stream_->OnStreamFrame(frame); | 642 stream_->OnStreamFrame(frame); |
645 } | 643 } |
646 | 644 |
647 } // namespace | 645 } // namespace |
648 } // namespace test | 646 } // namespace test |
649 } // namespace net | 647 } // namespace net |
OLD | NEW |