| OLD | NEW |
| 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/spdy/chromium/spdy_session.h" | 5 #include "net/spdy/chromium/spdy_session.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 5619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5630 AddSocketData(altsvc_ir); | 5630 AddSocketData(altsvc_ir); |
| 5631 AddSSLSocketData(); | 5631 AddSSLSocketData(); |
| 5632 | 5632 |
| 5633 CreateNetworkSession(); | 5633 CreateNetworkSession(); |
| 5634 CreateSecureSpdySession(); | 5634 CreateSecureSpdySession(); |
| 5635 | 5635 |
| 5636 base::RunLoop().RunUntilIdle(); | 5636 base::RunLoop().RunUntilIdle(); |
| 5637 | 5637 |
| 5638 const url::SchemeHostPort session_origin("https", test_url_.host(), | 5638 const url::SchemeHostPort session_origin("https", test_url_.host(), |
| 5639 test_url_.EffectiveIntPort()); | 5639 test_url_.EffectiveIntPort()); |
| 5640 AlternativeServiceVector altsvc_vector = | 5640 AlternativeServiceInfoVector altsvc_info_vector = |
| 5641 spdy_session_pool_->http_server_properties()->GetAlternativeServices( | 5641 spdy_session_pool_->http_server_properties()->GetAlternativeServiceInfos( |
| 5642 session_origin); | 5642 session_origin); |
| 5643 ASSERT_TRUE(altsvc_vector.empty()); | 5643 ASSERT_TRUE(altsvc_info_vector.empty()); |
| 5644 | 5644 |
| 5645 altsvc_vector = | 5645 altsvc_info_vector = |
| 5646 spdy_session_pool_->http_server_properties()->GetAlternativeServices( | 5646 spdy_session_pool_->http_server_properties()->GetAlternativeServiceInfos( |
| 5647 url::SchemeHostPort(GURL(origin))); | 5647 url::SchemeHostPort(GURL(origin))); |
| 5648 ASSERT_EQ(1u, altsvc_vector.size()); | 5648 ASSERT_EQ(1u, altsvc_info_vector.size()); |
| 5649 EXPECT_EQ(kProtoQUIC, altsvc_vector[0].protocol); | 5649 AlternativeService alternative_service(kProtoQUIC, "alternative.example.org", |
| 5650 EXPECT_EQ("alternative.example.org", altsvc_vector[0].host); | 5650 443u); |
| 5651 EXPECT_EQ(443u, altsvc_vector[0].port); | 5651 EXPECT_EQ(alternative_service, altsvc_info_vector[0].alternative_service); |
| 5652 } | 5652 } |
| 5653 | 5653 |
| 5654 TEST_F(AltSvcFrameTest, DoNotProcessAltSvcFrameOnInsecureSession) { | 5654 TEST_F(AltSvcFrameTest, DoNotProcessAltSvcFrameOnInsecureSession) { |
| 5655 const char origin[] = "https://mail.example.org"; | 5655 const char origin[] = "https://mail.example.org"; |
| 5656 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 0); | 5656 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 0); |
| 5657 altsvc_ir.add_altsvc(alternative_service_); | 5657 altsvc_ir.add_altsvc(alternative_service_); |
| 5658 altsvc_ir.set_origin(origin); | 5658 altsvc_ir.set_origin(origin); |
| 5659 AddSocketData(altsvc_ir); | 5659 AddSocketData(altsvc_ir); |
| 5660 AddSSLSocketData(); | 5660 AddSSLSocketData(); |
| 5661 | 5661 |
| 5662 CreateNetworkSession(); | 5662 CreateNetworkSession(); |
| 5663 CreateInsecureSpdySession(); | 5663 CreateInsecureSpdySession(); |
| 5664 | 5664 |
| 5665 base::RunLoop().RunUntilIdle(); | 5665 base::RunLoop().RunUntilIdle(); |
| 5666 | 5666 |
| 5667 const url::SchemeHostPort session_origin("https", test_url_.host(), | 5667 const url::SchemeHostPort session_origin("https", test_url_.host(), |
| 5668 test_url_.EffectiveIntPort()); | 5668 test_url_.EffectiveIntPort()); |
| 5669 AlternativeServiceVector altsvc_vector = | 5669 ASSERT_TRUE(spdy_session_pool_->http_server_properties() |
| 5670 spdy_session_pool_->http_server_properties()->GetAlternativeServices( | 5670 ->GetAlternativeServiceInfos(session_origin) |
| 5671 session_origin); | 5671 .empty()); |
| 5672 ASSERT_TRUE(altsvc_vector.empty()); | |
| 5673 | 5672 |
| 5674 altsvc_vector = | 5673 ASSERT_TRUE( |
| 5675 spdy_session_pool_->http_server_properties()->GetAlternativeServices( | 5674 spdy_session_pool_->http_server_properties() |
| 5676 url::SchemeHostPort(GURL(origin))); | 5675 ->GetAlternativeServiceInfos(url::SchemeHostPort(GURL(origin))) |
| 5677 ASSERT_TRUE(altsvc_vector.empty()); | 5676 .empty()); |
| 5678 } | 5677 } |
| 5679 | 5678 |
| 5680 TEST_F(AltSvcFrameTest, DoNotProcessAltSvcFrameForOriginNotCoveredByCert) { | 5679 TEST_F(AltSvcFrameTest, DoNotProcessAltSvcFrameForOriginNotCoveredByCert) { |
| 5681 const char origin[] = "https://invalid.example.org"; | 5680 const char origin[] = "https://invalid.example.org"; |
| 5682 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 0); | 5681 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 0); |
| 5683 altsvc_ir.add_altsvc(alternative_service_); | 5682 altsvc_ir.add_altsvc(alternative_service_); |
| 5684 altsvc_ir.set_origin(origin); | 5683 altsvc_ir.set_origin(origin); |
| 5685 AddSocketData(altsvc_ir); | 5684 AddSocketData(altsvc_ir); |
| 5686 AddSSLSocketData(); | 5685 AddSSLSocketData(); |
| 5687 | 5686 |
| 5688 CreateNetworkSession(); | 5687 CreateNetworkSession(); |
| 5689 CreateSecureSpdySession(); | 5688 CreateSecureSpdySession(); |
| 5690 | 5689 |
| 5691 base::RunLoop().RunUntilIdle(); | 5690 base::RunLoop().RunUntilIdle(); |
| 5692 | 5691 |
| 5693 const url::SchemeHostPort session_origin("https", test_url_.host(), | 5692 const url::SchemeHostPort session_origin("https", test_url_.host(), |
| 5694 test_url_.EffectiveIntPort()); | 5693 test_url_.EffectiveIntPort()); |
| 5695 AlternativeServiceVector altsvc_vector = | 5694 ASSERT_TRUE(spdy_session_pool_->http_server_properties() |
| 5696 spdy_session_pool_->http_server_properties()->GetAlternativeServices( | 5695 ->GetAlternativeServiceInfos(session_origin) |
| 5697 session_origin); | 5696 .empty()); |
| 5698 ASSERT_TRUE(altsvc_vector.empty()); | |
| 5699 | 5697 |
| 5700 altsvc_vector = | 5698 ASSERT_TRUE( |
| 5701 spdy_session_pool_->http_server_properties()->GetAlternativeServices( | 5699 spdy_session_pool_->http_server_properties() |
| 5702 url::SchemeHostPort(GURL(origin))); | 5700 ->GetAlternativeServiceInfos(url::SchemeHostPort(GURL(origin))) |
| 5703 ASSERT_TRUE(altsvc_vector.empty()); | 5701 .empty()); |
| 5704 } | 5702 } |
| 5705 | 5703 |
| 5706 // An ALTSVC frame on stream 0 with empty origin MUST be ignored. | 5704 // An ALTSVC frame on stream 0 with empty origin MUST be ignored. |
| 5707 // (RFC 7838 Section 4) | 5705 // (RFC 7838 Section 4) |
| 5708 TEST_F(AltSvcFrameTest, DoNotProcessAltSvcFrameWithEmptyOriginOnStreamZero) { | 5706 TEST_F(AltSvcFrameTest, DoNotProcessAltSvcFrameWithEmptyOriginOnStreamZero) { |
| 5709 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 0); | 5707 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 0); |
| 5710 altsvc_ir.add_altsvc(alternative_service_); | 5708 altsvc_ir.add_altsvc(alternative_service_); |
| 5711 AddSocketData(altsvc_ir); | 5709 AddSocketData(altsvc_ir); |
| 5712 AddSSLSocketData(); | 5710 AddSSLSocketData(); |
| 5713 | 5711 |
| 5714 CreateNetworkSession(); | 5712 CreateNetworkSession(); |
| 5715 CreateSecureSpdySession(); | 5713 CreateSecureSpdySession(); |
| 5716 | 5714 |
| 5717 base::RunLoop().RunUntilIdle(); | 5715 base::RunLoop().RunUntilIdle(); |
| 5718 | 5716 |
| 5719 const url::SchemeHostPort session_origin("https", test_url_.host(), | 5717 const url::SchemeHostPort session_origin("https", test_url_.host(), |
| 5720 test_url_.EffectiveIntPort()); | 5718 test_url_.EffectiveIntPort()); |
| 5721 AlternativeServiceVector altsvc_vector = | 5719 ASSERT_TRUE(spdy_session_pool_->http_server_properties() |
| 5722 spdy_session_pool_->http_server_properties()->GetAlternativeServices( | 5720 ->GetAlternativeServiceInfos(session_origin) |
| 5723 session_origin); | 5721 .empty()); |
| 5724 ASSERT_TRUE(altsvc_vector.empty()); | |
| 5725 } | 5722 } |
| 5726 | 5723 |
| 5727 // An ALTSVC frame on a stream other than stream 0 with non-empty origin MUST be | 5724 // An ALTSVC frame on a stream other than stream 0 with non-empty origin MUST be |
| 5728 // ignored. (RFC 7838 Section 4) | 5725 // ignored. (RFC 7838 Section 4) |
| 5729 TEST_F(AltSvcFrameTest, | 5726 TEST_F(AltSvcFrameTest, |
| 5730 DoNotProcessAltSvcFrameWithNonEmptyOriginOnNonZeroStream) { | 5727 DoNotProcessAltSvcFrameWithNonEmptyOriginOnNonZeroStream) { |
| 5731 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 1); | 5728 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 1); |
| 5732 altsvc_ir.add_altsvc(alternative_service_); | 5729 altsvc_ir.add_altsvc(alternative_service_); |
| 5733 altsvc_ir.set_origin("https://mail.example.org"); | 5730 altsvc_ir.set_origin("https://mail.example.org"); |
| 5734 AddSocketData(altsvc_ir); | 5731 AddSocketData(altsvc_ir); |
| 5735 AddSSLSocketData(); | 5732 AddSSLSocketData(); |
| 5736 | 5733 |
| 5737 CreateNetworkSession(); | 5734 CreateNetworkSession(); |
| 5738 CreateSecureSpdySession(); | 5735 CreateSecureSpdySession(); |
| 5739 | 5736 |
| 5740 base::RunLoop().RunUntilIdle(); | 5737 base::RunLoop().RunUntilIdle(); |
| 5741 | 5738 |
| 5742 const url::SchemeHostPort session_origin("https", test_url_.host(), | 5739 const url::SchemeHostPort session_origin("https", test_url_.host(), |
| 5743 test_url_.EffectiveIntPort()); | 5740 test_url_.EffectiveIntPort()); |
| 5744 AlternativeServiceVector altsvc_vector = | 5741 ASSERT_TRUE(spdy_session_pool_->http_server_properties() |
| 5745 spdy_session_pool_->http_server_properties()->GetAlternativeServices( | 5742 ->GetAlternativeServiceInfos(session_origin) |
| 5746 session_origin); | 5743 .empty()); |
| 5747 ASSERT_TRUE(altsvc_vector.empty()); | |
| 5748 } | 5744 } |
| 5749 | 5745 |
| 5750 TEST_F(AltSvcFrameTest, ProcessAltSvcFrameOnActiveStream) { | 5746 TEST_F(AltSvcFrameTest, ProcessAltSvcFrameOnActiveStream) { |
| 5751 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 1); | 5747 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 1); |
| 5752 altsvc_ir.add_altsvc(alternative_service_); | 5748 altsvc_ir.add_altsvc(alternative_service_); |
| 5753 | 5749 |
| 5754 SpdySerializedFrame altsvc_frame(spdy_util_.SerializeFrame(altsvc_ir)); | 5750 SpdySerializedFrame altsvc_frame(spdy_util_.SerializeFrame(altsvc_ir)); |
| 5755 SpdySerializedFrame rst( | 5751 SpdySerializedFrame rst( |
| 5756 spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_REFUSED_STREAM)); | 5752 spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_REFUSED_STREAM)); |
| 5757 MockRead reads[] = { | 5753 MockRead reads[] = { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 5780 spdy_stream1->SetDelegate(&delegate1); | 5776 spdy_stream1->SetDelegate(&delegate1); |
| 5781 | 5777 |
| 5782 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(request_origin)); | 5778 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(request_origin)); |
| 5783 | 5779 |
| 5784 spdy_stream1->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); | 5780 spdy_stream1->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); |
| 5785 | 5781 |
| 5786 base::RunLoop().RunUntilIdle(); | 5782 base::RunLoop().RunUntilIdle(); |
| 5787 | 5783 |
| 5788 const url::SchemeHostPort session_origin("https", test_url_.host(), | 5784 const url::SchemeHostPort session_origin("https", test_url_.host(), |
| 5789 test_url_.EffectiveIntPort()); | 5785 test_url_.EffectiveIntPort()); |
| 5790 AlternativeServiceVector altsvc_vector = | 5786 ASSERT_TRUE(spdy_session_pool_->http_server_properties() |
| 5791 spdy_session_pool_->http_server_properties()->GetAlternativeServices( | 5787 ->GetAlternativeServiceInfos(session_origin) |
| 5792 session_origin); | 5788 .empty()); |
| 5793 ASSERT_TRUE(altsvc_vector.empty()); | |
| 5794 | 5789 |
| 5795 altsvc_vector = | 5790 AlternativeServiceInfoVector altsvc_info_vector = |
| 5796 spdy_session_pool_->http_server_properties()->GetAlternativeServices( | 5791 spdy_session_pool_->http_server_properties()->GetAlternativeServiceInfos( |
| 5797 url::SchemeHostPort(GURL(request_origin))); | 5792 url::SchemeHostPort(GURL(request_origin))); |
| 5798 ASSERT_EQ(1u, altsvc_vector.size()); | 5793 ASSERT_EQ(1u, altsvc_info_vector.size()); |
| 5799 EXPECT_EQ(kProtoQUIC, altsvc_vector[0].protocol); | 5794 EXPECT_EQ(kProtoQUIC, altsvc_info_vector[0].alternative_service.protocol); |
| 5800 EXPECT_EQ("alternative.example.org", altsvc_vector[0].host); | 5795 EXPECT_EQ("alternative.example.org", |
| 5801 EXPECT_EQ(443u, altsvc_vector[0].port); | 5796 altsvc_info_vector[0].alternative_service.host); |
| 5797 EXPECT_EQ(443u, altsvc_info_vector[0].alternative_service.port); |
| 5802 } | 5798 } |
| 5803 | 5799 |
| 5804 TEST_F(AltSvcFrameTest, DoNotProcessAltSvcFrameOnStreamWithInsecureOrigin) { | 5800 TEST_F(AltSvcFrameTest, DoNotProcessAltSvcFrameOnStreamWithInsecureOrigin) { |
| 5805 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 1); | 5801 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 1); |
| 5806 altsvc_ir.add_altsvc(alternative_service_); | 5802 altsvc_ir.add_altsvc(alternative_service_); |
| 5807 | 5803 |
| 5808 SpdySerializedFrame altsvc_frame(spdy_util_.SerializeFrame(altsvc_ir)); | 5804 SpdySerializedFrame altsvc_frame(spdy_util_.SerializeFrame(altsvc_ir)); |
| 5809 SpdySerializedFrame rst( | 5805 SpdySerializedFrame rst( |
| 5810 spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_REFUSED_STREAM)); | 5806 spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_REFUSED_STREAM)); |
| 5811 MockRead reads[] = { | 5807 MockRead reads[] = { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 5834 spdy_stream1->SetDelegate(&delegate1); | 5830 spdy_stream1->SetDelegate(&delegate1); |
| 5835 | 5831 |
| 5836 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(request_origin)); | 5832 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(request_origin)); |
| 5837 | 5833 |
| 5838 spdy_stream1->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); | 5834 spdy_stream1->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); |
| 5839 | 5835 |
| 5840 base::RunLoop().RunUntilIdle(); | 5836 base::RunLoop().RunUntilIdle(); |
| 5841 | 5837 |
| 5842 const url::SchemeHostPort session_origin("https", test_url_.host(), | 5838 const url::SchemeHostPort session_origin("https", test_url_.host(), |
| 5843 test_url_.EffectiveIntPort()); | 5839 test_url_.EffectiveIntPort()); |
| 5844 AlternativeServiceVector altsvc_vector = | 5840 ASSERT_TRUE(spdy_session_pool_->http_server_properties() |
| 5845 spdy_session_pool_->http_server_properties()->GetAlternativeServices( | 5841 ->GetAlternativeServiceInfos(session_origin) |
| 5846 session_origin); | 5842 .empty()); |
| 5847 ASSERT_TRUE(altsvc_vector.empty()); | |
| 5848 | 5843 |
| 5849 altsvc_vector = | 5844 ASSERT_TRUE(spdy_session_pool_->http_server_properties() |
| 5850 spdy_session_pool_->http_server_properties()->GetAlternativeServices( | 5845 ->GetAlternativeServiceInfos( |
| 5851 url::SchemeHostPort(GURL(request_origin))); | 5846 url::SchemeHostPort(GURL(request_origin))) |
| 5852 ASSERT_TRUE(altsvc_vector.empty()); | 5847 .empty()); |
| 5853 } | 5848 } |
| 5854 | 5849 |
| 5855 TEST_F(AltSvcFrameTest, DoNotProcessAltSvcFrameOnNonExistentStream) { | 5850 TEST_F(AltSvcFrameTest, DoNotProcessAltSvcFrameOnNonExistentStream) { |
| 5856 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 1); | 5851 SpdyAltSvcIR altsvc_ir(/* stream_id = */ 1); |
| 5857 altsvc_ir.add_altsvc(alternative_service_); | 5852 altsvc_ir.add_altsvc(alternative_service_); |
| 5858 AddSocketData(altsvc_ir); | 5853 AddSocketData(altsvc_ir); |
| 5859 AddSSLSocketData(); | 5854 AddSSLSocketData(); |
| 5860 | 5855 |
| 5861 CreateNetworkSession(); | 5856 CreateNetworkSession(); |
| 5862 CreateSecureSpdySession(); | 5857 CreateSecureSpdySession(); |
| 5863 | 5858 |
| 5864 base::RunLoop().RunUntilIdle(); | 5859 base::RunLoop().RunUntilIdle(); |
| 5865 | 5860 |
| 5866 const url::SchemeHostPort session_origin("https", test_url_.host(), | 5861 const url::SchemeHostPort session_origin("https", test_url_.host(), |
| 5867 test_url_.EffectiveIntPort()); | 5862 test_url_.EffectiveIntPort()); |
| 5868 AlternativeServiceVector altsvc_vector = | 5863 ASSERT_TRUE(spdy_session_pool_->http_server_properties() |
| 5869 spdy_session_pool_->http_server_properties()->GetAlternativeServices( | 5864 ->GetAlternativeServiceInfos(session_origin) |
| 5870 session_origin); | 5865 .empty()); |
| 5871 ASSERT_TRUE(altsvc_vector.empty()); | |
| 5872 } | 5866 } |
| 5873 | 5867 |
| 5874 TEST(MapFramerErrorToProtocolError, MapsValues) { | 5868 TEST(MapFramerErrorToProtocolError, MapsValues) { |
| 5875 CHECK_EQ( | 5869 CHECK_EQ( |
| 5876 SPDY_ERROR_INVALID_CONTROL_FRAME, | 5870 SPDY_ERROR_INVALID_CONTROL_FRAME, |
| 5877 MapFramerErrorToProtocolError(SpdyFramer::SPDY_INVALID_CONTROL_FRAME)); | 5871 MapFramerErrorToProtocolError(SpdyFramer::SPDY_INVALID_CONTROL_FRAME)); |
| 5878 CHECK_EQ( | 5872 CHECK_EQ( |
| 5879 SPDY_ERROR_INVALID_DATA_FRAME_FLAGS, | 5873 SPDY_ERROR_INVALID_DATA_FRAME_FLAGS, |
| 5880 MapFramerErrorToProtocolError(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS)); | 5874 MapFramerErrorToProtocolError(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS)); |
| 5881 CHECK_EQ( | 5875 CHECK_EQ( |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6146 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 6140 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
| 6147 "spdy_pooling.pem"); | 6141 "spdy_pooling.pem"); |
| 6148 ssl_info.is_issued_by_known_root = true; | 6142 ssl_info.is_issued_by_known_root = true; |
| 6149 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); | 6143 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); |
| 6150 | 6144 |
| 6151 EXPECT_TRUE(SpdySession::CanPool( | 6145 EXPECT_TRUE(SpdySession::CanPool( |
| 6152 &tss, ssl_info, "www.example.org", "mail.example.org")); | 6146 &tss, ssl_info, "www.example.org", "mail.example.org")); |
| 6153 } | 6147 } |
| 6154 | 6148 |
| 6155 } // namespace net | 6149 } // namespace net |
| OLD | NEW |