Chromium Code Reviews| 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/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 | 43 |
| 44 // Test using the HTTP/2 protocol, without specifying a stream | 44 // Test using the HTTP/2 protocol, without specifying a stream |
| 45 // dependency based on the RequestPriority. | 45 // dependency based on the RequestPriority. |
| 46 kTestCaseHTTP2NoPriorityDependencies, | 46 kTestCaseHTTP2NoPriorityDependencies, |
| 47 | 47 |
| 48 // Test using the HTTP/2 protocol, specifying a stream | 48 // Test using the HTTP/2 protocol, specifying a stream |
| 49 // dependency based on the RequestPriority. | 49 // dependency based on the RequestPriority. |
| 50 kTestCaseHTTP2PriorityDependencies | 50 kTestCaseHTTP2PriorityDependencies |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 const char kHttpURLFromAnotherOrigin[] = "http://www.example2.org/a.dat"; | |
| 54 const char kHttpsURLFromAnotherOrigin[] = "https://www.example2.org/b.dat"; | |
| 55 | |
| 53 const char kBodyData[] = "Body data"; | 56 const char kBodyData[] = "Body data"; |
| 54 const size_t kBodyDataSize = arraysize(kBodyData); | 57 const size_t kBodyDataSize = arraysize(kBodyData); |
| 55 const base::StringPiece kBodyDataStringPiece(kBodyData, kBodyDataSize); | 58 const base::StringPiece kBodyDataStringPiece(kBodyData, kBodyDataSize); |
| 56 | 59 |
| 57 static base::TimeDelta g_time_delta; | 60 static base::TimeDelta g_time_delta; |
| 58 static base::TimeTicks g_time_now; | 61 static base::TimeTicks g_time_now; |
| 59 | 62 |
| 60 base::TimeTicks TheNearFuture() { | 63 base::TimeTicks TheNearFuture() { |
| 61 return base::TimeTicks::Now() + g_time_delta; | 64 return base::TimeTicks::Now() + g_time_delta; |
| 62 } | 65 } |
| (...skipping 4772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4835 EXPECT_EQ(0u, session_->num_created_streams()); | 4838 EXPECT_EQ(0u, session_->num_created_streams()); |
| 4836 EXPECT_EQ(1u, session_->num_pushed_streams()); | 4839 EXPECT_EQ(1u, session_->num_pushed_streams()); |
| 4837 EXPECT_EQ(1u, session_->num_active_pushed_streams()); | 4840 EXPECT_EQ(1u, session_->num_active_pushed_streams()); |
| 4838 | 4841 |
| 4839 // Read EOF. | 4842 // Read EOF. |
| 4840 data.Resume(); | 4843 data.Resume(); |
| 4841 base::RunLoop().RunUntilIdle(); | 4844 base::RunLoop().RunUntilIdle(); |
| 4842 EXPECT_FALSE(session_); | 4845 EXPECT_FALSE(session_); |
| 4843 } | 4846 } |
| 4844 | 4847 |
| 4848 // Tests that HTTP SPDY push streams that advertise an origin different from the | |
| 4849 // associated stream are accepted from a trusted SPDY proxy. | |
| 4850 TEST_P(SpdySessionTest, TrustedSpdyProxy) { | |
| 4851 // Origin of kDefaultURL should be different from the origin of | |
| 4852 // kHttpURLFromAnotherOrigin and kHttpsURLFromAnotherOrigin. | |
| 4853 ASSERT_NE(GURL(kDefaultURL).host(), GURL(kHttpURLFromAnotherOrigin).host()); | |
| 4854 ASSERT_NE(GURL(kDefaultURL).host(), GURL(kHttpsURLFromAnotherOrigin).host()); | |
| 4855 | |
| 4856 // cross_origin_push contains HTTP resource for an origin different from the | |
| 4857 // origin of kDefaultURL, and should be accepted. | |
| 4858 scoped_ptr<SpdyFrame> cross_origin_push(spdy_util_.ConstructSpdyPush( | |
| 4859 nullptr, 0, 2, 1, kHttpURLFromAnotherOrigin)); | |
| 4860 // cross_origin_https_push contains HTTPS resource, and should be refused. | |
| 4861 scoped_ptr<SpdyFrame> cross_origin_https_push(spdy_util_.ConstructSpdyPush( | |
| 4862 nullptr, 0, 4, 1, kHttpsURLFromAnotherOrigin)); | |
| 4863 MockRead reads[] = { | |
| 4864 MockRead(ASYNC, ERR_IO_PENDING, 1), | |
| 4865 CreateMockRead(*cross_origin_push, 2), | |
| 4866 MockRead(ASYNC, ERR_IO_PENDING, 3), | |
| 4867 CreateMockRead(*cross_origin_https_push, 4), | |
| 4868 MockRead(ASYNC, ERR_IO_PENDING, 6), | |
| 4869 MockRead(ASYNC, 0, 7), | |
| 4870 }; | |
| 4871 | |
| 4872 scoped_ptr<SpdyFrame> request( | |
|
Bence
2016/01/12 13:10:19
The name |req| is used everywhere in this file, pl
tbansal1
2016/01/12 18:04:39
Done.
| |
| 4873 spdy_util_.ConstructSpdyGet(nullptr, 0, false, 1, LOWEST, true)); | |
| 4874 scoped_ptr<SpdyFrame> reset( | |
|
Bence
2016/01/12 13:10:19
The name |rst| is used everywhere in this file, pl
tbansal1
2016/01/12 18:04:39
Done.
| |
| 4875 spdy_util_.ConstructSpdyRstStream(4, RST_STREAM_REFUSED_STREAM)); | |
| 4876 MockWrite writes[] = { | |
| 4877 CreateMockWrite(*request, 0), CreateMockWrite(*reset, 5), | |
| 4878 }; | |
| 4879 | |
| 4880 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | |
| 4881 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 4882 session_deps_.trusted_spdy_proxy = | |
| 4883 HostPortPair::FromURL(GURL(kDefaultURL)).ToString(); | |
| 4884 | |
| 4885 CreateNetworkSession(); | |
| 4886 CreateInsecureSpdySession(); | |
| 4887 | |
| 4888 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously( | |
| 4889 SPDY_REQUEST_RESPONSE_STREAM, session_, test_url_, LOWEST, BoundNetLog()); | |
| 4890 ASSERT_TRUE(spdy_stream.get() != nullptr); | |
| 4891 EXPECT_EQ(0u, spdy_stream->stream_id()); | |
| 4892 test::StreamDelegateDoNothing delegate(spdy_stream); | |
| 4893 spdy_stream->SetDelegate(&delegate); | |
| 4894 | |
| 4895 EXPECT_EQ(0u, session_->num_active_streams()); | |
| 4896 EXPECT_EQ(1u, session_->num_created_streams()); | |
| 4897 EXPECT_EQ(0u, session_->num_pushed_streams()); | |
| 4898 EXPECT_EQ(0u, session_->num_active_pushed_streams()); | |
| 4899 | |
| 4900 scoped_ptr<SpdyHeaderBlock> headers( | |
| 4901 spdy_util_.ConstructGetHeaderBlock(kDefaultURL)); | |
| 4902 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); | |
| 4903 EXPECT_TRUE(spdy_stream->HasUrlFromHeaders()); | |
| 4904 | |
| 4905 // Run until 1st stream is activated. | |
| 4906 EXPECT_EQ(0u, delegate.stream_id()); | |
| 4907 base::RunLoop().RunUntilIdle(); | |
| 4908 EXPECT_EQ(1u, delegate.stream_id()); | |
| 4909 EXPECT_EQ(1u, session_->num_active_streams()); | |
| 4910 EXPECT_EQ(0u, session_->num_created_streams()); | |
| 4911 EXPECT_EQ(0u, session_->num_pushed_streams()); | |
| 4912 EXPECT_EQ(0u, session_->num_active_pushed_streams()); | |
| 4913 | |
| 4914 // Run until pushed stream is created. | |
| 4915 data.Resume(); | |
| 4916 base::RunLoop().RunUntilIdle(); | |
| 4917 EXPECT_EQ(2u, session_->num_active_streams()); | |
| 4918 EXPECT_EQ(0u, session_->num_created_streams()); | |
| 4919 EXPECT_EQ(1u, session_->num_pushed_streams()); | |
| 4920 EXPECT_EQ(1u, session_->num_active_pushed_streams()); | |
| 4921 | |
| 4922 // Reset incoming pushed stream. | |
| 4923 data.Resume(); | |
| 4924 base::RunLoop().RunUntilIdle(); | |
| 4925 EXPECT_EQ(2u, session_->num_active_streams()); | |
| 4926 EXPECT_EQ(0u, session_->num_created_streams()); | |
| 4927 EXPECT_EQ(1u, session_->num_pushed_streams()); | |
| 4928 EXPECT_EQ(1u, session_->num_active_pushed_streams()); | |
| 4929 | |
| 4930 // Read EOF. | |
| 4931 data.Resume(); | |
| 4932 base::RunLoop().RunUntilIdle(); | |
| 4933 EXPECT_FALSE(session_); | |
| 4934 } | |
| 4935 | |
| 4936 // Tests that if the SPDY trusted proxy is not set, then push streams that | |
| 4937 // advertise an origin different from the associated stream are refused. | |
| 4938 TEST_P(SpdySessionTest, TrustedSpdyProxyNotSet) { | |
| 4939 // Origin of kDefaultURL should be different from the origin of | |
| 4940 // kHttpURLFromAnotherOrigin. | |
| 4941 ASSERT_NE(GURL(kDefaultURL).host(), GURL(kHttpURLFromAnotherOrigin).host()); | |
| 4942 | |
| 4943 // cross_origin_push contains resource for an origin different from the | |
| 4944 // origin of kDefaultURL, and should be refused. | |
| 4945 scoped_ptr<SpdyFrame> cross_origin_push(spdy_util_.ConstructSpdyPush( | |
| 4946 nullptr, 0, 2, 1, kHttpURLFromAnotherOrigin)); | |
| 4947 MockRead reads[] = { | |
| 4948 MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(*cross_origin_push, 2), | |
| 4949 MockRead(ASYNC, 0, 4), | |
| 4950 }; | |
| 4951 | |
| 4952 scoped_ptr<SpdyFrame> req( | |
| 4953 spdy_util_.ConstructSpdyGet(nullptr, 0, false, 1, LOWEST, true)); | |
| 4954 scoped_ptr<SpdyFrame> rst( | |
| 4955 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); | |
| 4956 MockWrite writes[] = { | |
| 4957 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 3), | |
| 4958 }; | |
| 4959 | |
| 4960 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | |
| 4961 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 4962 | |
| 4963 CreateNetworkSession(); | |
| 4964 CreateInsecureSpdySession(); | |
| 4965 | |
| 4966 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously( | |
| 4967 SPDY_REQUEST_RESPONSE_STREAM, session_, test_url_, LOWEST, BoundNetLog()); | |
| 4968 ASSERT_TRUE(spdy_stream.get() != nullptr); | |
| 4969 EXPECT_EQ(0u, spdy_stream->stream_id()); | |
| 4970 test::StreamDelegateDoNothing delegate(spdy_stream); | |
| 4971 spdy_stream->SetDelegate(&delegate); | |
| 4972 | |
| 4973 EXPECT_EQ(0u, session_->num_active_streams()); | |
| 4974 EXPECT_EQ(1u, session_->num_created_streams()); | |
| 4975 EXPECT_EQ(0u, session_->num_pushed_streams()); | |
| 4976 EXPECT_EQ(0u, session_->num_active_pushed_streams()); | |
| 4977 | |
| 4978 scoped_ptr<SpdyHeaderBlock> headers( | |
| 4979 spdy_util_.ConstructGetHeaderBlock(kDefaultURL)); | |
| 4980 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); | |
| 4981 EXPECT_TRUE(spdy_stream->HasUrlFromHeaders()); | |
| 4982 | |
| 4983 // Run until 1st stream is activated. | |
| 4984 EXPECT_EQ(0u, delegate.stream_id()); | |
| 4985 base::RunLoop().RunUntilIdle(); | |
| 4986 EXPECT_EQ(1u, delegate.stream_id()); | |
| 4987 EXPECT_EQ(1u, session_->num_active_streams()); | |
| 4988 EXPECT_EQ(0u, session_->num_created_streams()); | |
| 4989 EXPECT_EQ(0u, session_->num_pushed_streams()); | |
| 4990 EXPECT_EQ(0u, session_->num_active_pushed_streams()); | |
| 4991 | |
| 4992 // Read EOF. | |
| 4993 data.Resume(); | |
| 4994 base::RunLoop().RunUntilIdle(); | |
| 4995 EXPECT_FALSE(session_); | |
| 4996 } | |
| 4997 | |
| 4845 TEST_P(SpdySessionTest, IgnoreReservedRemoteStreamsCount) { | 4998 TEST_P(SpdySessionTest, IgnoreReservedRemoteStreamsCount) { |
| 4846 // Streams in reserved remote state exist only in HTTP/2. | 4999 // Streams in reserved remote state exist only in HTTP/2. |
| 4847 if (spdy_util_.spdy_version() < HTTP2) | 5000 if (spdy_util_.spdy_version() < HTTP2) |
| 4848 return; | 5001 return; |
| 4849 | 5002 |
| 4850 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( | 5003 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( |
| 4851 nullptr, 0, 2, 1, "http://www.example.org/a.dat")); | 5004 nullptr, 0, 2, 1, "http://www.example.org/a.dat")); |
| 4852 scoped_ptr<SpdyHeaderBlock> push_headers(new SpdyHeaderBlock); | 5005 scoped_ptr<SpdyHeaderBlock> push_headers(new SpdyHeaderBlock); |
| 4853 spdy_util_.AddUrlToHeaderBlock("http://www.example.org/b.dat", | 5006 spdy_util_.AddUrlToHeaderBlock("http://www.example.org/b.dat", |
| 4854 push_headers.get()); | 5007 push_headers.get()); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5209 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 5362 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
| 5210 "spdy_pooling.pem"); | 5363 "spdy_pooling.pem"); |
| 5211 ssl_info.is_issued_by_known_root = true; | 5364 ssl_info.is_issued_by_known_root = true; |
| 5212 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); | 5365 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); |
| 5213 | 5366 |
| 5214 EXPECT_TRUE(SpdySession::CanPool( | 5367 EXPECT_TRUE(SpdySession::CanPool( |
| 5215 &tss, ssl_info, "www.example.org", "mail.example.org")); | 5368 &tss, ssl_info, "www.example.org", "mail.example.org")); |
| 5216 } | 5369 } |
| 5217 | 5370 |
| 5218 } // namespace net | 5371 } // namespace net |
| OLD | NEW |