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 4824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4835 EXPECT_EQ(0u, session_->num_created_streams()); | 4835 EXPECT_EQ(0u, session_->num_created_streams()); |
| 4836 EXPECT_EQ(1u, session_->num_pushed_streams()); | 4836 EXPECT_EQ(1u, session_->num_pushed_streams()); |
| 4837 EXPECT_EQ(1u, session_->num_active_pushed_streams()); | 4837 EXPECT_EQ(1u, session_->num_active_pushed_streams()); |
| 4838 | 4838 |
| 4839 // Read EOF. | 4839 // Read EOF. |
| 4840 data.Resume(); | 4840 data.Resume(); |
| 4841 base::RunLoop().RunUntilIdle(); | 4841 base::RunLoop().RunUntilIdle(); |
| 4842 EXPECT_FALSE(session_); | 4842 EXPECT_FALSE(session_); |
| 4843 } | 4843 } |
| 4844 | 4844 |
| 4845 // Tests that only the HTTP SPDY push requests from trusted SPDY proxies are | |
|
bengr
2015/12/29 18:02:33
Shouldn't SPDY push work for same origin pushes ev
tbansal1
2015/12/30 00:00:53
Fixed the comment.
| |
| 4846 // accepted. | |
| 4847 TEST_P(SpdySessionTest, TrustedSpdyProxy) { | |
| 4848 // kDefaultURL should not contain "example2.org". | |
| 4849 ASSERT_TRUE(std::string(kDefaultURL).find("example2.org") == | |
| 4850 std::string::npos); | |
| 4851 // push_a pushes resources for example2.org which is different from | |
| 4852 // kDefaultURL. push_a is HTTP, and should be accepted. | |
| 4853 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( | |
| 4854 nullptr, 0, 2, 1, "http://www.example2.org/a.dat")); | |
| 4855 // push_b is HTTPS, and should be refused. | |
| 4856 scoped_ptr<SpdyFrame> push_b(spdy_util_.ConstructSpdyPush( | |
| 4857 nullptr, 0, 4, 1, "https://www.example2.org/b.dat")); | |
| 4858 MockRead reads[] = { | |
| 4859 MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(*push_a, 2), | |
| 4860 MockRead(ASYNC, ERR_IO_PENDING, 3), CreateMockRead(*push_b, 4), | |
| 4861 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7), | |
| 4862 }; | |
| 4863 | |
| 4864 scoped_ptr<SpdyFrame> req( | |
| 4865 spdy_util_.ConstructSpdyGet(nullptr, 0, false, 1, LOWEST, true)); | |
| 4866 scoped_ptr<SpdyFrame> rst( | |
| 4867 spdy_util_.ConstructSpdyRstStream(4, RST_STREAM_REFUSED_STREAM)); | |
| 4868 MockWrite writes[] = { | |
| 4869 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 5), | |
| 4870 }; | |
| 4871 | |
| 4872 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | |
| 4873 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 4874 | |
| 4875 CreateNetworkSession(); | |
|
bengr
2015/12/29 18:02:33
You should be able to pass in the trusted SPDY pro
tbansal1
2015/12/30 00:00:52
Done.
| |
| 4876 CreateInsecureSpdySession(); | |
| 4877 | |
| 4878 session_->set_trusted_spdy_proxy_for_tests( | |
| 4879 HostPortPair::FromString("www.example.org:80")); | |
| 4880 | |
| 4881 base::WeakPtr<SpdyStream> spdy_stream1 = CreateStreamSynchronously( | |
| 4882 SPDY_REQUEST_RESPONSE_STREAM, session_, test_url_, LOWEST, BoundNetLog()); | |
| 4883 ASSERT_TRUE(spdy_stream1.get() != nullptr); | |
| 4884 EXPECT_EQ(0u, spdy_stream1->stream_id()); | |
| 4885 test::StreamDelegateDoNothing delegate1(spdy_stream1); | |
| 4886 spdy_stream1->SetDelegate(&delegate1); | |
| 4887 | |
| 4888 EXPECT_EQ(0u, session_->num_active_streams()); | |
| 4889 EXPECT_EQ(1u, session_->num_created_streams()); | |
| 4890 EXPECT_EQ(0u, session_->num_pushed_streams()); | |
| 4891 EXPECT_EQ(0u, session_->num_active_pushed_streams()); | |
| 4892 | |
| 4893 scoped_ptr<SpdyHeaderBlock> headers( | |
| 4894 spdy_util_.ConstructGetHeaderBlock(kDefaultURL)); | |
| 4895 spdy_stream1->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); | |
| 4896 EXPECT_TRUE(spdy_stream1->HasUrlFromHeaders()); | |
| 4897 | |
| 4898 // Run until 1st stream is activated. | |
| 4899 EXPECT_EQ(0u, delegate1.stream_id()); | |
| 4900 base::RunLoop().RunUntilIdle(); | |
| 4901 EXPECT_EQ(1u, delegate1.stream_id()); | |
| 4902 EXPECT_EQ(1u, session_->num_active_streams()); | |
| 4903 EXPECT_EQ(0u, session_->num_created_streams()); | |
| 4904 EXPECT_EQ(0u, session_->num_pushed_streams()); | |
| 4905 EXPECT_EQ(0u, session_->num_active_pushed_streams()); | |
| 4906 | |
| 4907 // Run until pushed stream is created. | |
| 4908 data.Resume(); | |
| 4909 base::RunLoop().RunUntilIdle(); | |
| 4910 EXPECT_EQ(2u, session_->num_active_streams()); | |
| 4911 EXPECT_EQ(0u, session_->num_created_streams()); | |
| 4912 EXPECT_EQ(1u, session_->num_pushed_streams()); | |
| 4913 EXPECT_EQ(1u, session_->num_active_pushed_streams()); | |
| 4914 | |
| 4915 // Reset incoming pushed stream. | |
| 4916 data.Resume(); | |
| 4917 base::RunLoop().RunUntilIdle(); | |
| 4918 EXPECT_EQ(2u, session_->num_active_streams()); | |
| 4919 EXPECT_EQ(0u, session_->num_created_streams()); | |
| 4920 EXPECT_EQ(1u, session_->num_pushed_streams()); | |
| 4921 EXPECT_EQ(1u, session_->num_active_pushed_streams()); | |
| 4922 | |
| 4923 // Read EOF. | |
| 4924 data.Resume(); | |
| 4925 base::RunLoop().RunUntilIdle(); | |
| 4926 EXPECT_FALSE(session_); | |
| 4927 } | |
| 4928 | |
| 4929 // Tests that if the SPDY trusted proxy is not set, than push requests for a | |
|
bengr
2015/12/29 18:02:33
Test that a push from the same origin should succe
tbansal1
2015/12/30 00:00:53
That's already checked in another existing test: R
| |
| 4930 // non-matching domain are refused. | |
| 4931 TEST_P(SpdySessionTest, TrustedSpdyProxyNotSet) { | |
| 4932 // kDefaultURL should not contain "example2.org". | |
| 4933 ASSERT_TRUE(std::string(kDefaultURL).find("example2.org") == | |
| 4934 std::string::npos); | |
| 4935 // push_a contains resource for a origin different than kDefaultURL, and | |
| 4936 // should be refused. | |
| 4937 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( | |
| 4938 nullptr, 0, 2, 1, "http://www.example2.org/a.dat")); | |
| 4939 MockRead reads[] = { | |
| 4940 MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(*push_a, 2), | |
| 4941 MockRead(ASYNC, 0, 4), | |
| 4942 }; | |
| 4943 | |
| 4944 scoped_ptr<SpdyFrame> req( | |
| 4945 spdy_util_.ConstructSpdyGet(nullptr, 0, false, 1, LOWEST, true)); | |
| 4946 scoped_ptr<SpdyFrame> rst( | |
| 4947 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); | |
| 4948 MockWrite writes[] = { | |
| 4949 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 3), | |
| 4950 }; | |
| 4951 | |
| 4952 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | |
| 4953 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 4954 | |
| 4955 CreateNetworkSession(); | |
| 4956 CreateInsecureSpdySession(); | |
| 4957 | |
| 4958 base::WeakPtr<SpdyStream> spdy_stream1 = CreateStreamSynchronously( | |
| 4959 SPDY_REQUEST_RESPONSE_STREAM, session_, test_url_, LOWEST, BoundNetLog()); | |
| 4960 ASSERT_TRUE(spdy_stream1.get() != nullptr); | |
| 4961 EXPECT_EQ(0u, spdy_stream1->stream_id()); | |
| 4962 test::StreamDelegateDoNothing delegate1(spdy_stream1); | |
| 4963 spdy_stream1->SetDelegate(&delegate1); | |
| 4964 | |
| 4965 EXPECT_EQ(0u, session_->num_active_streams()); | |
| 4966 EXPECT_EQ(1u, session_->num_created_streams()); | |
| 4967 EXPECT_EQ(0u, session_->num_pushed_streams()); | |
| 4968 EXPECT_EQ(0u, session_->num_active_pushed_streams()); | |
| 4969 | |
| 4970 scoped_ptr<SpdyHeaderBlock> headers( | |
| 4971 spdy_util_.ConstructGetHeaderBlock(kDefaultURL)); | |
| 4972 spdy_stream1->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); | |
| 4973 EXPECT_TRUE(spdy_stream1->HasUrlFromHeaders()); | |
| 4974 | |
| 4975 // Run until 1st stream is activated. | |
| 4976 EXPECT_EQ(0u, delegate1.stream_id()); | |
| 4977 base::RunLoop().RunUntilIdle(); | |
| 4978 EXPECT_EQ(1u, delegate1.stream_id()); | |
| 4979 EXPECT_EQ(1u, session_->num_active_streams()); | |
| 4980 EXPECT_EQ(0u, session_->num_created_streams()); | |
| 4981 EXPECT_EQ(0u, session_->num_pushed_streams()); | |
| 4982 EXPECT_EQ(0u, session_->num_active_pushed_streams()); | |
| 4983 | |
| 4984 // Read EOF. | |
| 4985 data.Resume(); | |
| 4986 base::RunLoop().RunUntilIdle(); | |
| 4987 EXPECT_FALSE(session_); | |
| 4988 } | |
| 4989 | |
| 4845 TEST_P(SpdySessionTest, IgnoreReservedRemoteStreamsCount) { | 4990 TEST_P(SpdySessionTest, IgnoreReservedRemoteStreamsCount) { |
| 4846 // Streams in reserved remote state exist only in HTTP/2. | 4991 // Streams in reserved remote state exist only in HTTP/2. |
| 4847 if (spdy_util_.spdy_version() < HTTP2) | 4992 if (spdy_util_.spdy_version() < HTTP2) |
| 4848 return; | 4993 return; |
| 4849 | 4994 |
| 4850 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( | 4995 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( |
| 4851 nullptr, 0, 2, 1, "http://www.example.org/a.dat")); | 4996 nullptr, 0, 2, 1, "http://www.example.org/a.dat")); |
| 4852 scoped_ptr<SpdyHeaderBlock> push_headers(new SpdyHeaderBlock); | 4997 scoped_ptr<SpdyHeaderBlock> push_headers(new SpdyHeaderBlock); |
| 4853 spdy_util_.AddUrlToHeaderBlock("http://www.example.org/b.dat", | 4998 spdy_util_.AddUrlToHeaderBlock("http://www.example.org/b.dat", |
| 4854 push_headers.get()); | 4999 push_headers.get()); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5209 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 5354 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
| 5210 "spdy_pooling.pem"); | 5355 "spdy_pooling.pem"); |
| 5211 ssl_info.is_issued_by_known_root = true; | 5356 ssl_info.is_issued_by_known_root = true; |
| 5212 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); | 5357 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); |
| 5213 | 5358 |
| 5214 EXPECT_TRUE(SpdySession::CanPool( | 5359 EXPECT_TRUE(SpdySession::CanPool( |
| 5215 &tss, ssl_info, "www.example.org", "mail.example.org")); | 5360 &tss, ssl_info, "www.example.org", "mail.example.org")); |
| 5216 } | 5361 } |
| 5217 | 5362 |
| 5218 } // namespace net | 5363 } // namespace net |
| OLD | NEW |