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

Side by Side Diff: net/spdy/spdy_session_unittest.cc

Issue 1545403002: Return false when trusted SPDY proxy advertises HTTPS URL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed bengr comments Created 4 years, 11 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
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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 HTTP SPDY push streams that advertise an origin different from the
4846 // associated stream are accepted from a trusted SPDY proxy.
4847 TEST_P(SpdySessionTest, TrustedSpdyProxy) {
4848 const char kHttpURLFromAnotherOrigin[] = "http://www.example2.org/a.dat";
4849 const char kHttpsURLFromAnotherOrigin[] = "https://www.example2.org/b.dat";
4850
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(
4873 spdy_util_.ConstructSpdyGet(nullptr, 0, false, 1, LOWEST, true));
4874 scoped_ptr<SpdyFrame> reset(
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 const char kHttpURLFromAnotherOrigin[] = "http://www.example2.org/a.dat";
bengr 2016/01/11 21:57:12 nit: I'd move these constants to an anonymous name
tbansal1 2016/01/11 22:15:01 Done.
4940 // Origin of kDefaultURL should be different from the origin of
4941 // kHttpURLFromAnotherOrigin.
4942 ASSERT_NE(GURL(kDefaultURL).host(), GURL(kHttpURLFromAnotherOrigin).host());
4943
4944 // cross_origin_push contains resource for an origin different from the
4945 // origin of kDefaultURL, and should be refused.
4946 scoped_ptr<SpdyFrame> cross_origin_push(spdy_util_.ConstructSpdyPush(
4947 nullptr, 0, 2, 1, kHttpURLFromAnotherOrigin));
4948 MockRead reads[] = {
4949 MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(*cross_origin_push, 2),
4950 MockRead(ASYNC, 0, 4),
4951 };
4952
4953 scoped_ptr<SpdyFrame> req(
4954 spdy_util_.ConstructSpdyGet(nullptr, 0, false, 1, LOWEST, true));
4955 scoped_ptr<SpdyFrame> rst(
4956 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM));
4957 MockWrite writes[] = {
4958 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 3),
4959 };
4960
4961 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
4962 session_deps_.socket_factory->AddSocketDataProvider(&data);
4963
4964 CreateNetworkSession();
4965 CreateInsecureSpdySession();
4966
4967 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously(
4968 SPDY_REQUEST_RESPONSE_STREAM, session_, test_url_, LOWEST, BoundNetLog());
4969 ASSERT_TRUE(spdy_stream.get() != nullptr);
4970 EXPECT_EQ(0u, spdy_stream->stream_id());
4971 test::StreamDelegateDoNothing delegate(spdy_stream);
4972 spdy_stream->SetDelegate(&delegate);
4973
4974 EXPECT_EQ(0u, session_->num_active_streams());
4975 EXPECT_EQ(1u, session_->num_created_streams());
4976 EXPECT_EQ(0u, session_->num_pushed_streams());
4977 EXPECT_EQ(0u, session_->num_active_pushed_streams());
4978
4979 scoped_ptr<SpdyHeaderBlock> headers(
4980 spdy_util_.ConstructGetHeaderBlock(kDefaultURL));
4981 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND);
4982 EXPECT_TRUE(spdy_stream->HasUrlFromHeaders());
4983
4984 // Run until 1st stream is activated.
4985 EXPECT_EQ(0u, delegate.stream_id());
4986 base::RunLoop().RunUntilIdle();
4987 EXPECT_EQ(1u, delegate.stream_id());
4988 EXPECT_EQ(1u, session_->num_active_streams());
4989 EXPECT_EQ(0u, session_->num_created_streams());
4990 EXPECT_EQ(0u, session_->num_pushed_streams());
4991 EXPECT_EQ(0u, session_->num_active_pushed_streams());
4992
4993 // Read EOF.
4994 data.Resume();
4995 base::RunLoop().RunUntilIdle();
4996 EXPECT_FALSE(session_);
4997 }
4998
4845 TEST_P(SpdySessionTest, IgnoreReservedRemoteStreamsCount) { 4999 TEST_P(SpdySessionTest, IgnoreReservedRemoteStreamsCount) {
4846 // Streams in reserved remote state exist only in HTTP/2. 5000 // Streams in reserved remote state exist only in HTTP/2.
4847 if (spdy_util_.spdy_version() < HTTP2) 5001 if (spdy_util_.spdy_version() < HTTP2)
4848 return; 5002 return;
4849 5003
4850 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( 5004 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush(
4851 nullptr, 0, 2, 1, "http://www.example.org/a.dat")); 5005 nullptr, 0, 2, 1, "http://www.example.org/a.dat"));
4852 scoped_ptr<SpdyHeaderBlock> push_headers(new SpdyHeaderBlock); 5006 scoped_ptr<SpdyHeaderBlock> push_headers(new SpdyHeaderBlock);
4853 spdy_util_.AddUrlToHeaderBlock("http://www.example.org/b.dat", 5007 spdy_util_.AddUrlToHeaderBlock("http://www.example.org/b.dat",
4854 push_headers.get()); 5008 push_headers.get());
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
5209 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), 5363 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(),
5210 "spdy_pooling.pem"); 5364 "spdy_pooling.pem");
5211 ssl_info.is_issued_by_known_root = true; 5365 ssl_info.is_issued_by_known_root = true;
5212 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); 5366 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin));
5213 5367
5214 EXPECT_TRUE(SpdySession::CanPool( 5368 EXPECT_TRUE(SpdySession::CanPool(
5215 &tss, ssl_info, "www.example.org", "mail.example.org")); 5369 &tss, ssl_info, "www.example.org", "mail.example.org"));
5216 } 5370 }
5217 5371
5218 } // namespace net 5372 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698