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

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

Issue 291093002: Fail the SPDY transaction if it does not meet TLS base requirements. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address forgotten comment. Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « net/socket/socket_test_util.cc ('k') | net/spdy/spdy_session.h » ('j') | 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 15 matching lines...) Expand all
26 #include "net/http/http_transaction_test_util.h" 26 #include "net/http/http_transaction_test_util.h"
27 #include "net/socket/client_socket_pool_base.h" 27 #include "net/socket/client_socket_pool_base.h"
28 #include "net/socket/next_proto.h" 28 #include "net/socket/next_proto.h"
29 #include "net/spdy/buffered_spdy_framer.h" 29 #include "net/spdy/buffered_spdy_framer.h"
30 #include "net/spdy/spdy_http_stream.h" 30 #include "net/spdy/spdy_http_stream.h"
31 #include "net/spdy/spdy_http_utils.h" 31 #include "net/spdy/spdy_http_utils.h"
32 #include "net/spdy/spdy_session.h" 32 #include "net/spdy/spdy_session.h"
33 #include "net/spdy/spdy_session_pool.h" 33 #include "net/spdy/spdy_session_pool.h"
34 #include "net/spdy/spdy_test_util_common.h" 34 #include "net/spdy/spdy_test_util_common.h"
35 #include "net/spdy/spdy_test_utils.h" 35 #include "net/spdy/spdy_test_utils.h"
36 #include "net/ssl/ssl_connection_status_flags.h"
36 #include "net/url_request/url_request_test_util.h" 37 #include "net/url_request/url_request_test_util.h"
37 #include "testing/gmock/include/gmock/gmock.h" 38 #include "testing/gmock/include/gmock/gmock.h"
38 #include "testing/platform_test.h" 39 #include "testing/platform_test.h"
39 40
40 //----------------------------------------------------------------------------- 41 //-----------------------------------------------------------------------------
41 42
42 namespace net { 43 namespace net {
43 44
44 namespace { 45 namespace {
45 46
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // Start the transaction, read some data, finish. 211 // Start the transaction, read some data, finish.
211 void RunDefaultTest() { 212 void RunDefaultTest() {
212 LOG(INFO) << __FUNCTION__; 213 LOG(INFO) << __FUNCTION__;
213 if (!StartDefaultTest()) 214 if (!StartDefaultTest())
214 return; 215 return;
215 FinishDefaultTest(); 216 FinishDefaultTest();
216 LOG(INFO) << __FUNCTION__; 217 LOG(INFO) << __FUNCTION__;
217 } 218 }
218 219
219 bool StartDefaultTest() { 220 bool StartDefaultTest() {
220 output_.rv = trans_->Start(&request_, callback.callback(), log_); 221 output_.rv = trans_->Start(&request_, callback_.callback(), log_);
221 222
222 // We expect an IO Pending or some sort of error. 223 // We expect an IO Pending or some sort of error.
223 EXPECT_LT(output_.rv, 0); 224 EXPECT_LT(output_.rv, 0);
224 return output_.rv == ERR_IO_PENDING; 225 return output_.rv == ERR_IO_PENDING;
225 } 226 }
226 227
227 void FinishDefaultTest() { 228 void FinishDefaultTest() {
228 output_.rv = callback.WaitForResult(); 229 output_.rv = callback_.WaitForResult();
229 if (output_.rv != OK) { 230 if (output_.rv != OK) {
230 session_->spdy_session_pool()->CloseCurrentSessions(net::ERR_ABORTED); 231 session_->spdy_session_pool()->CloseCurrentSessions(net::ERR_ABORTED);
231 return; 232 return;
232 } 233 }
233 234
234 // Verify responses. 235 // Verify responses.
235 const HttpResponseInfo* response = trans_->GetResponseInfo(); 236 const HttpResponseInfo* response = trans_->GetResponseInfo();
236 ASSERT_TRUE(response != NULL); 237 ASSERT_TRUE(response != NULL);
237 ASSERT_TRUE(response->headers.get() != NULL); 238 ASSERT_TRUE(response->headers.get() != NULL);
238 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 239 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 299 }
299 } 300 }
300 301
301 void RunToCompletion(StaticSocketDataProvider* data) { 302 void RunToCompletion(StaticSocketDataProvider* data) {
302 RunPreTestSetup(); 303 RunPreTestSetup();
303 AddData(data); 304 AddData(data);
304 RunDefaultTest(); 305 RunDefaultTest();
305 VerifyDataConsumed(); 306 VerifyDataConsumed();
306 } 307 }
307 308
309 void RunToCompletionWithSSLData(
310 StaticSocketDataProvider* data,
311 scoped_ptr<SSLSocketDataProvider> ssl_provider) {
312 RunPreTestSetup();
313 AddDataWithSSLSocketDataProvider(data, ssl_provider.Pass());
314 RunDefaultTest();
315 VerifyDataConsumed();
316 }
317
308 void AddData(StaticSocketDataProvider* data) { 318 void AddData(StaticSocketDataProvider* data) {
319 scoped_ptr<SSLSocketDataProvider> ssl_provider(
320 new SSLSocketDataProvider(ASYNC, OK));
321 AddDataWithSSLSocketDataProvider(data, ssl_provider.Pass());
322 }
323
324 void AddDataWithSSLSocketDataProvider(
325 StaticSocketDataProvider* data,
326 scoped_ptr<SSLSocketDataProvider> ssl_provider) {
309 DCHECK(!deterministic_); 327 DCHECK(!deterministic_);
310 data_vector_.push_back(data); 328 data_vector_.push_back(data);
311 SSLSocketDataProvider* ssl_provider =
312 new SSLSocketDataProvider(ASYNC, OK);
313 if (test_params_.ssl_type == SPDYNPN) 329 if (test_params_.ssl_type == SPDYNPN)
314 ssl_provider->SetNextProto(test_params_.protocol); 330 ssl_provider->SetNextProto(test_params_.protocol);
315 331
316 ssl_vector_.push_back(ssl_provider); 332 if (test_params_.ssl_type == SPDYNPN ||
317 if (test_params_.ssl_type == SPDYNPN || test_params_.ssl_type == SPDYSSL) 333 test_params_.ssl_type == SPDYSSL) {
318 session_deps_->socket_factory->AddSSLSocketDataProvider(ssl_provider); 334 session_deps_->socket_factory->AddSSLSocketDataProvider(
335 ssl_provider.get());
336 }
337 ssl_vector_.push_back(ssl_provider.release());
319 338
320 session_deps_->socket_factory->AddSocketDataProvider(data); 339 session_deps_->socket_factory->AddSocketDataProvider(data);
321 if (test_params_.ssl_type == SPDYNPN) { 340 if (test_params_.ssl_type == SPDYNPN) {
322 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); 341 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
323 StaticSocketDataProvider* hanging_non_alternate_protocol_socket = 342 StaticSocketDataProvider* hanging_non_alternate_protocol_socket =
324 new StaticSocketDataProvider(NULL, 0, NULL, 0); 343 new StaticSocketDataProvider(NULL, 0, NULL, 0);
325 hanging_non_alternate_protocol_socket->set_connect_data( 344 hanging_non_alternate_protocol_socket->set_connect_data(
326 never_finishing_connect); 345 never_finishing_connect);
327 session_deps_->socket_factory->AddSocketDataProvider( 346 session_deps_->socket_factory->AddSocketDataProvider(
328 hanging_non_alternate_protocol_socket); 347 hanging_non_alternate_protocol_socket);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 typedef ScopedVector<SSLSocketDataProvider> SSLVector; 400 typedef ScopedVector<SSLSocketDataProvider> SSLVector;
382 typedef ScopedVector<StaticSocketDataProvider> AlternateVector; 401 typedef ScopedVector<StaticSocketDataProvider> AlternateVector;
383 typedef ScopedVector<DeterministicSocketData> AlternateDeterministicVector; 402 typedef ScopedVector<DeterministicSocketData> AlternateDeterministicVector;
384 HttpRequestInfo request_; 403 HttpRequestInfo request_;
385 RequestPriority priority_; 404 RequestPriority priority_;
386 scoped_ptr<SpdySessionDependencies> session_deps_; 405 scoped_ptr<SpdySessionDependencies> session_deps_;
387 scoped_refptr<HttpNetworkSession> session_; 406 scoped_refptr<HttpNetworkSession> session_;
388 TransactionHelperResult output_; 407 TransactionHelperResult output_;
389 scoped_ptr<StaticSocketDataProvider> first_transaction_; 408 scoped_ptr<StaticSocketDataProvider> first_transaction_;
390 SSLVector ssl_vector_; 409 SSLVector ssl_vector_;
391 TestCompletionCallback callback; 410 TestCompletionCallback callback_;
392 scoped_ptr<HttpNetworkTransaction> trans_; 411 scoped_ptr<HttpNetworkTransaction> trans_;
393 scoped_ptr<HttpNetworkTransaction> trans_http_; 412 scoped_ptr<HttpNetworkTransaction> trans_http_;
394 DataVector data_vector_; 413 DataVector data_vector_;
395 AlternateVector alternate_vector_; 414 AlternateVector alternate_vector_;
396 AlternateDeterministicVector alternate_deterministic_vector_; 415 AlternateDeterministicVector alternate_deterministic_vector_;
397 const BoundNetLog& log_; 416 const BoundNetLog& log_;
398 SpdyNetworkTransactionTestParams test_params_; 417 SpdyNetworkTransactionTestParams test_params_;
399 int port_; 418 int port_;
400 bool deterministic_; 419 bool deterministic_;
401 bool spdy_enabled_; 420 bool spdy_enabled_;
(...skipping 6170 matching lines...) Expand 10 before | Expand all | Expand 10 after
6572 // But the body is not yet fully sent (kUploadData is not yet sent) 6591 // But the body is not yet fully sent (kUploadData is not yet sent)
6573 // since we're send-stalled. 6592 // since we're send-stalled.
6574 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); 6593 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control());
6575 6594
6576 // Read in WINDOW_UPDATE or SETTINGS frame. 6595 // Read in WINDOW_UPDATE or SETTINGS frame.
6577 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 9 : 8); 6596 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 9 : 8);
6578 rv = callback.WaitForResult(); 6597 rv = callback.WaitForResult();
6579 helper.VerifyDataConsumed(); 6598 helper.VerifyDataConsumed();
6580 } 6599 }
6581 6600
6601 class SpdyNetworkTransactionNoTLSUsageCheckTest
6602 : public SpdyNetworkTransactionTest {
6603 protected:
6604 void RunNoTLSUsageCheckTest(scoped_ptr<SSLSocketDataProvider> ssl_provider) {
6605 // Construct the request.
6606 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyGet(
6607 "https://www.google.com/", false, 1, LOWEST));
6608 MockWrite writes[] = {CreateMockWrite(*req)};
6609
6610 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
6611 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
6612 MockRead reads[] = {
6613 CreateMockRead(*resp), CreateMockRead(*body),
6614 MockRead(ASYNC, 0, 0) // EOF
6615 };
6616
6617 DelayedSocketData data(
6618 1, reads, arraysize(reads), writes, arraysize(writes));
6619 HttpRequestInfo request;
6620 request.method = "GET";
6621 request.url = GURL("https://www.google.com/");
6622 NormalSpdyTransactionHelper helper(
6623 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL);
6624 helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass());
6625 TransactionHelperResult out = helper.output();
6626 EXPECT_EQ(OK, out.rv);
6627 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
6628 EXPECT_EQ("hello!", out.response_data);
6629 }
6630 };
6631
6632 //-----------------------------------------------------------------------------
6633 // All tests are run with three different connection types: SPDY after NPN
6634 // negotiation, SPDY without SSL, and SPDY with SSL.
6635 //
6636 // TODO(akalin): Use ::testing::Combine() when we are able to use
6637 // <tr1/tuple>.
6638 INSTANTIATE_TEST_CASE_P(
6639 Spdy,
6640 SpdyNetworkTransactionNoTLSUsageCheckTest,
6641 ::testing::Values(SpdyNetworkTransactionTestParams(kProtoDeprecatedSPDY2,
6642 SPDYNPN),
6643 SpdyNetworkTransactionTestParams(kProtoSPDY3, SPDYNPN),
6644 SpdyNetworkTransactionTestParams(kProtoSPDY31, SPDYNPN)));
6645
6646 TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest, TLSVersionTooOld) {
6647 scoped_ptr<SSLSocketDataProvider> ssl_provider(
6648 new SSLSocketDataProvider(ASYNC, OK));
6649 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3,
6650 &ssl_provider->connection_status);
6651
6652 RunNoTLSUsageCheckTest(ssl_provider.Pass());
6653 }
6654
6655 TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest, TLSCipherSuiteSucky) {
6656 scoped_ptr<SSLSocketDataProvider> ssl_provider(
6657 new SSLSocketDataProvider(ASYNC, OK));
6658 // Set to TLS_RSA_WITH_NULL_MD5
6659 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status);
6660
6661 RunNoTLSUsageCheckTest(ssl_provider.Pass());
6662 }
6663
6664 class SpdyNetworkTransactionTLSUsageCheckTest
6665 : public SpdyNetworkTransactionTest {
6666 protected:
6667 void RunTLSUsageCheckTest(scoped_ptr<SSLSocketDataProvider> ssl_provider) {
6668 // TODO(willchan): Fix crbug.com/375033 to send GOAWAYs.
6669 // scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway());
6670 // MockWrite writes[] = {
6671 // CreateMockWrite(*goaway)
6672 // };
6673
6674 // DelayedSocketData data(1, NULL, 0, writes, arraysize(writes));
6675 DelayedSocketData data(1, NULL, 0, NULL, 0);
6676 HttpRequestInfo request;
6677 request.method = "GET";
6678 request.url = GURL("https://www.google.com/");
6679 NormalSpdyTransactionHelper helper(
6680 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL);
6681 helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass());
6682 TransactionHelperResult out = helper.output();
6683 EXPECT_EQ(ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY, out.rv);
6684 }
6685 };
6686
6687 INSTANTIATE_TEST_CASE_P(
6688 Spdy,
6689 SpdyNetworkTransactionTLSUsageCheckTest,
6690 ::testing::Values(SpdyNetworkTransactionTestParams(kProtoSPDY4, SPDYNPN)));
6691
6692 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSVersionTooOld) {
6693 scoped_ptr<SSLSocketDataProvider> ssl_provider(
6694 new SSLSocketDataProvider(ASYNC, OK));
6695 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3,
6696 &ssl_provider->connection_status);
6697
6698 RunTLSUsageCheckTest(ssl_provider.Pass());
6699 }
6700
6701 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) {
6702 scoped_ptr<SSLSocketDataProvider> ssl_provider(
6703 new SSLSocketDataProvider(ASYNC, OK));
6704 // Set to TLS_RSA_WITH_NULL_MD5
6705 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status);
6706
6707 RunTLSUsageCheckTest(ssl_provider.Pass());
6708 }
6709
6582 } // namespace net 6710 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socket_test_util.cc ('k') | net/spdy/spdy_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698