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

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 a different origin than the
bengr 2016/01/05 21:01:37 a different origin than -> an origin different fro
tbansal1 2016/01/08 02:04:04 Done.
4846 // associated stream are accepted from trusted SPDY proxies.
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
bengr 2016/01/05 21:01:37 I'd rename the variables cross_origin_push and cro
tbansal1 2016/01/08 02:04:03 Done.
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"));
bengr 2016/01/05 21:01:37 I'd create another constant called kAnotherURL.
tbansal1 2016/01/08 02:04:04 Done.
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(
bengr 2016/01/05 21:01:37 Call this "request" and the latter one "reset"
tbansal1 2016/01/08 02:04:04 Done.
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 session_deps_.trusted_spdy_proxy = "www.example.org:80";
bengr 2016/01/05 21:01:37 Shouldn't this be HostPortPair::FromURL(GURL(kDefa
tbansal1 2016/01/08 02:04:04 Done.
4875
4876 CreateNetworkSession();
4877 CreateInsecureSpdySession();
4878
4879 base::WeakPtr<SpdyStream> spdy_stream1 = CreateStreamSynchronously(
bengr 2016/01/05 21:01:37 Can you just call this spdy_stream?
tbansal1 2016/01/08 02:04:03 Done.
4880 SPDY_REQUEST_RESPONSE_STREAM, session_, test_url_, LOWEST, BoundNetLog());
4881 ASSERT_TRUE(spdy_stream1.get() != nullptr);
4882 EXPECT_EQ(0u, spdy_stream1->stream_id());
4883 test::StreamDelegateDoNothing delegate1(spdy_stream1);
bengr 2016/01/05 21:01:37 delegate1 -> delegate
tbansal1 2016/01/08 02:04:03 Done.
4884 spdy_stream1->SetDelegate(&delegate1);
4885
4886 EXPECT_EQ(0u, session_->num_active_streams());
4887 EXPECT_EQ(1u, session_->num_created_streams());
4888 EXPECT_EQ(0u, session_->num_pushed_streams());
4889 EXPECT_EQ(0u, session_->num_active_pushed_streams());
4890
4891 scoped_ptr<SpdyHeaderBlock> headers(
4892 spdy_util_.ConstructGetHeaderBlock(kDefaultURL));
4893 spdy_stream1->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND);
4894 EXPECT_TRUE(spdy_stream1->HasUrlFromHeaders());
4895
4896 // Run until 1st stream is activated.
4897 EXPECT_EQ(0u, delegate1.stream_id());
4898 base::RunLoop().RunUntilIdle();
4899 EXPECT_EQ(1u, delegate1.stream_id());
4900 EXPECT_EQ(1u, session_->num_active_streams());
4901 EXPECT_EQ(0u, session_->num_created_streams());
4902 EXPECT_EQ(0u, session_->num_pushed_streams());
4903 EXPECT_EQ(0u, session_->num_active_pushed_streams());
4904
4905 // Run until pushed stream is created.
4906 data.Resume();
4907 base::RunLoop().RunUntilIdle();
4908 EXPECT_EQ(2u, session_->num_active_streams());
4909 EXPECT_EQ(0u, session_->num_created_streams());
4910 EXPECT_EQ(1u, session_->num_pushed_streams());
4911 EXPECT_EQ(1u, session_->num_active_pushed_streams());
4912
4913 // Reset incoming pushed stream.
4914 data.Resume();
4915 base::RunLoop().RunUntilIdle();
4916 EXPECT_EQ(2u, session_->num_active_streams());
4917 EXPECT_EQ(0u, session_->num_created_streams());
4918 EXPECT_EQ(1u, session_->num_pushed_streams());
4919 EXPECT_EQ(1u, session_->num_active_pushed_streams());
4920
4921 // Read EOF.
4922 data.Resume();
4923 base::RunLoop().RunUntilIdle();
4924 EXPECT_FALSE(session_);
4925 }
4926
4927 // Tests that if the SPDY trusted proxy is not set, than push streams that
bengr 2016/01/05 21:01:37 than -> then a different origin than -> an origin
tbansal1 2016/01/08 02:04:03 Done.
4928 // advertise a different origin than the associated stream are refused.
4929 TEST_P(SpdySessionTest, TrustedSpdyProxyNotSet) {
4930 // kDefaultURL should not contain "example2.org".
4931 ASSERT_TRUE(std::string(kDefaultURL).find("example2.org") ==
bengr 2016/01/05 21:01:37 Better to use GURL(kDefaultURL).GetOrigin().
tbansal1 2016/01/08 02:04:04 Done.
4932 std::string::npos);
4933 // push_a contains resource for a origin different than kDefaultURL, and
bengr 2016/01/05 21:01:37 Call push_a cross_origin_push.
tbansal1 2016/01/08 02:04:03 Done.
4934 // should be refused.
4935 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush(
4936 nullptr, 0, 2, 1, "http://www.example2.org/a.dat"));
4937 MockRead reads[] = {
4938 MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(*push_a, 2),
4939 MockRead(ASYNC, 0, 4),
4940 };
4941
4942 scoped_ptr<SpdyFrame> req(
4943 spdy_util_.ConstructSpdyGet(nullptr, 0, false, 1, LOWEST, true));
4944 scoped_ptr<SpdyFrame> rst(
4945 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM));
4946 MockWrite writes[] = {
4947 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 3),
4948 };
4949
4950 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
4951 session_deps_.socket_factory->AddSocketDataProvider(&data);
4952
4953 CreateNetworkSession();
4954 CreateInsecureSpdySession();
4955
4956 base::WeakPtr<SpdyStream> spdy_stream1 = CreateStreamSynchronously(
bengr 2016/01/05 21:01:37 Rename as spdy_stream.
tbansal1 2016/01/08 02:04:04 Done.
4957 SPDY_REQUEST_RESPONSE_STREAM, session_, test_url_, LOWEST, BoundNetLog());
4958 ASSERT_TRUE(spdy_stream1.get() != nullptr);
4959 EXPECT_EQ(0u, spdy_stream1->stream_id());
4960 test::StreamDelegateDoNothing delegate1(spdy_stream1);
4961 spdy_stream1->SetDelegate(&delegate1);
bengr 2016/01/05 21:01:37 delegate1 -> delegate
tbansal1 2016/01/08 02:04:04 Done.
4962
4963 EXPECT_EQ(0u, session_->num_active_streams());
4964 EXPECT_EQ(1u, session_->num_created_streams());
4965 EXPECT_EQ(0u, session_->num_pushed_streams());
4966 EXPECT_EQ(0u, session_->num_active_pushed_streams());
4967
4968 scoped_ptr<SpdyHeaderBlock> headers(
4969 spdy_util_.ConstructGetHeaderBlock(kDefaultURL));
4970 spdy_stream1->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND);
4971 EXPECT_TRUE(spdy_stream1->HasUrlFromHeaders());
4972
4973 // Run until 1st stream is activated.
4974 EXPECT_EQ(0u, delegate1.stream_id());
4975 base::RunLoop().RunUntilIdle();
4976 EXPECT_EQ(1u, delegate1.stream_id());
4977 EXPECT_EQ(1u, session_->num_active_streams());
4978 EXPECT_EQ(0u, session_->num_created_streams());
4979 EXPECT_EQ(0u, session_->num_pushed_streams());
4980 EXPECT_EQ(0u, session_->num_active_pushed_streams());
4981
4982 // Read EOF.
4983 data.Resume();
4984 base::RunLoop().RunUntilIdle();
4985 EXPECT_FALSE(session_);
4986 }
4987
4845 TEST_P(SpdySessionTest, IgnoreReservedRemoteStreamsCount) { 4988 TEST_P(SpdySessionTest, IgnoreReservedRemoteStreamsCount) {
4846 // Streams in reserved remote state exist only in HTTP/2. 4989 // Streams in reserved remote state exist only in HTTP/2.
4847 if (spdy_util_.spdy_version() < HTTP2) 4990 if (spdy_util_.spdy_version() < HTTP2)
4848 return; 4991 return;
4849 4992
4850 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( 4993 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush(
4851 nullptr, 0, 2, 1, "http://www.example.org/a.dat")); 4994 nullptr, 0, 2, 1, "http://www.example.org/a.dat"));
4852 scoped_ptr<SpdyHeaderBlock> push_headers(new SpdyHeaderBlock); 4995 scoped_ptr<SpdyHeaderBlock> push_headers(new SpdyHeaderBlock);
4853 spdy_util_.AddUrlToHeaderBlock("http://www.example.org/b.dat", 4996 spdy_util_.AddUrlToHeaderBlock("http://www.example.org/b.dat",
4854 push_headers.get()); 4997 push_headers.get());
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
5209 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), 5352 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(),
5210 "spdy_pooling.pem"); 5353 "spdy_pooling.pem");
5211 ssl_info.is_issued_by_known_root = true; 5354 ssl_info.is_issued_by_known_root = true;
5212 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); 5355 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin));
5213 5356
5214 EXPECT_TRUE(SpdySession::CanPool( 5357 EXPECT_TRUE(SpdySession::CanPool(
5215 &tss, ssl_info, "www.example.org", "mail.example.org")); 5358 &tss, ssl_info, "www.example.org", "mail.example.org"));
5216 } 5359 }
5217 5360
5218 } // namespace net 5361 } // 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