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

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

Issue 2365263004: Make (almost) all SpdySessions secure in unittests. (Closed)
Patch Set: Created 4 years, 2 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
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_http_stream.h" 5 #include "net/spdy/spdy_http_stream.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "crypto/ec_private_key.h" 13 #include "crypto/ec_private_key.h"
14 #include "crypto/ec_signature_creator.h" 14 #include "crypto/ec_signature_creator.h"
15 #include "crypto/signature_creator.h" 15 #include "crypto/signature_creator.h"
16 #include "net/base/chunked_upload_data_stream.h" 16 #include "net/base/chunked_upload_data_stream.h"
17 #include "net/base/load_timing_info.h" 17 #include "net/base/load_timing_info.h"
18 #include "net/base/load_timing_info_test_util.h" 18 #include "net/base/load_timing_info_test_util.h"
19 #include "net/base/test_completion_callback.h" 19 #include "net/base/test_completion_callback.h"
20 #include "net/cert/asn1_util.h" 20 #include "net/cert/asn1_util.h"
21 #include "net/http/http_request_info.h" 21 #include "net/http/http_request_info.h"
22 #include "net/http/http_response_headers.h" 22 #include "net/http/http_response_headers.h"
23 #include "net/http/http_response_info.h" 23 #include "net/http/http_response_info.h"
24 #include "net/log/test_net_log.h" 24 #include "net/log/test_net_log.h"
25 #include "net/socket/socket_test_util.h" 25 #include "net/socket/socket_test_util.h"
26 #include "net/spdy/spdy_http_utils.h" 26 #include "net/spdy/spdy_http_utils.h"
27 #include "net/spdy/spdy_session.h" 27 #include "net/spdy/spdy_session.h"
28 #include "net/spdy/spdy_test_util_common.h" 28 #include "net/spdy/spdy_test_util_common.h"
29 #include "net/ssl/default_channel_id_store.h" 29 #include "net/ssl/default_channel_id_store.h"
30 #include "net/test/cert_test_util.h"
30 #include "net/test/gtest_util.h" 31 #include "net/test/gtest_util.h"
32 #include "net/test/test_data_directory.h"
31 #include "testing/gmock/include/gmock/gmock.h" 33 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
33 35
34 using net::test::IsError; 36 using net::test::IsError;
35 using net::test::IsOk; 37 using net::test::IsOk;
36 38
37 namespace net { 39 namespace net {
38 40
39 namespace { 41 namespace {
40 42
(...skipping 12 matching lines...) Expand all
53 55
54 // Tests the load timing of a stream that's connected and using a fresh 56 // Tests the load timing of a stream that's connected and using a fresh
55 // connection. 57 // connection.
56 void TestLoadTimingNotReused(const HttpStream& stream) { 58 void TestLoadTimingNotReused(const HttpStream& stream) {
57 LoadTimingInfo load_timing_info; 59 LoadTimingInfo load_timing_info;
58 EXPECT_TRUE(stream.GetLoadTimingInfo(&load_timing_info)); 60 EXPECT_TRUE(stream.GetLoadTimingInfo(&load_timing_info));
59 61
60 EXPECT_FALSE(load_timing_info.socket_reused); 62 EXPECT_FALSE(load_timing_info.socket_reused);
61 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); 63 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
62 64
63 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, 65 ExpectConnectTimingHasTimes(
64 CONNECT_TIMING_HAS_DNS_TIMES); 66 load_timing_info.connect_timing,
67 CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES);
65 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); 68 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info);
66 } 69 }
67 70
68 class ReadErrorUploadDataStream : public UploadDataStream { 71 class ReadErrorUploadDataStream : public UploadDataStream {
69 public: 72 public:
70 enum class FailureMode { SYNC, ASYNC }; 73 enum class FailureMode { SYNC, ASYNC };
71 74
72 explicit ReadErrorUploadDataStream(FailureMode mode) 75 explicit ReadErrorUploadDataStream(FailureMode mode)
73 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {} 76 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {}
74 77
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 SpdyHttpStream* stream_; 118 SpdyHttpStream* stream_;
116 CompletionCallback callback_; 119 CompletionCallback callback_;
117 }; 120 };
118 121
119 } // namespace 122 } // namespace
120 123
121 class SpdyHttpStreamTest : public testing::Test { 124 class SpdyHttpStreamTest : public testing::Test {
122 public: 125 public:
123 SpdyHttpStreamTest() 126 SpdyHttpStreamTest()
124 : host_port_pair_(HostPortPair::FromURL(GURL(kDefaultUrl))), 127 : host_port_pair_(HostPortPair::FromURL(GURL(kDefaultUrl))),
125 key_(host_port_pair_, ProxyServer::Direct(), PRIVACY_MODE_DISABLED) { 128 key_(host_port_pair_, ProxyServer::Direct(), PRIVACY_MODE_DISABLED),
129 ssl_(SYNCHRONOUS, OK) {
126 session_deps_.net_log = &net_log_; 130 session_deps_.net_log = &net_log_;
127 spdy_util_.set_default_url(GURL("http://www.example.org/")); 131 spdy_util_.set_default_url(GURL("http://www.example.org/"));
128 } 132 }
129 133
130 ~SpdyHttpStreamTest() override {} 134 ~SpdyHttpStreamTest() override {}
131 135
132 protected: 136 protected:
133 void TearDown() override { 137 void TearDown() override {
134 crypto::ECSignatureCreator::SetFactoryForTesting(nullptr); 138 crypto::ECSignatureCreator::SetFactoryForTesting(nullptr);
135 base::RunLoop().RunUntilIdle(); 139 base::RunLoop().RunUntilIdle();
136 EXPECT_TRUE(sequenced_data_->AllReadDataConsumed()); 140 EXPECT_TRUE(sequenced_data_->AllReadDataConsumed());
137 EXPECT_TRUE(sequenced_data_->AllWriteDataConsumed()); 141 EXPECT_TRUE(sequenced_data_->AllWriteDataConsumed());
138 } 142 }
139 143
140 // Initializes the session using SequencedSocketData. 144 // Initializes the session using SequencedSocketData.
141 void InitSession(MockRead* reads, 145 void InitSession(MockRead* reads,
142 size_t reads_count, 146 size_t reads_count,
143 MockWrite* writes, 147 MockWrite* writes,
144 size_t writes_count) { 148 size_t writes_count) {
145 sequenced_data_.reset( 149 sequenced_data_.reset(
146 new SequencedSocketData(reads, reads_count, writes, writes_count)); 150 new SequencedSocketData(reads, reads_count, writes, writes_count));
147 session_deps_.socket_factory->AddSocketDataProvider(sequenced_data_.get()); 151 session_deps_.socket_factory->AddSocketDataProvider(sequenced_data_.get());
152
153 ssl_.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem");
154 ASSERT_TRUE(ssl_.cert);
155 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_);
156
148 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); 157 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_);
149 session_ = CreateInsecureSpdySession(http_session_.get(), key_, 158 session_ =
150 NetLogWithSource()); 159 CreateSecureSpdySession(http_session_.get(), key_, NetLogWithSource());
151 } 160 }
152 161
153 void TestSendCredentials( 162 void TestSendCredentials(
154 ChannelIDService* channel_id_service, 163 ChannelIDService* channel_id_service,
155 const std::string& cert, 164 const std::string& cert,
156 const std::string& proof); 165 const std::string& proof);
157 166
158 SpdyTestUtil spdy_util_; 167 SpdyTestUtil spdy_util_;
159 TestNetLog net_log_; 168 TestNetLog net_log_;
160 SpdySessionDependencies session_deps_; 169 SpdySessionDependencies session_deps_;
161 const HostPortPair host_port_pair_; 170 const HostPortPair host_port_pair_;
162 const SpdySessionKey key_; 171 const SpdySessionKey key_;
163 std::unique_ptr<SequencedSocketData> sequenced_data_; 172 std::unique_ptr<SequencedSocketData> sequenced_data_;
164 std::unique_ptr<HttpNetworkSession> http_session_; 173 std::unique_ptr<HttpNetworkSession> http_session_;
165 base::WeakPtr<SpdySession> session_; 174 base::WeakPtr<SpdySession> session_;
166 175
167 private: 176 private:
168 MockECSignatureCreatorFactory ec_signature_creator_factory_; 177 MockECSignatureCreatorFactory ec_signature_creator_factory_;
178 SSLSocketDataProvider ssl_;
169 }; 179 };
170 180
171 TEST_F(SpdyHttpStreamTest, SendRequest) { 181 TEST_F(SpdyHttpStreamTest, SendRequest) {
172 SpdySerializedFrame req( 182 SpdySerializedFrame req(
173 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); 183 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true));
174 MockWrite writes[] = { 184 MockWrite writes[] = {
175 CreateMockWrite(req, 0), 185 CreateMockWrite(req, 0),
176 }; 186 };
177 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); 187 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1));
178 MockRead reads[] = { 188 MockRead reads[] = {
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 // The callback cancels |http_stream|. 1035 // The callback cancels |http_stream|.
1026 EXPECT_THAT(callback.WaitForResult(), IsOk()); 1036 EXPECT_THAT(callback.WaitForResult(), IsOk());
1027 1037
1028 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 1038 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_));
1029 } 1039 }
1030 1040
1031 // TODO(willchan): Write a longer test for SpdyStream that exercises all 1041 // TODO(willchan): Write a longer test for SpdyStream that exercises all
1032 // methods. 1042 // methods.
1033 1043
1034 } // namespace net 1044 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction_unittest.cc ('k') | net/spdy/spdy_proxy_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698