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 <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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 typedef SpdyNetworkTransactionTest SpdyNetworkTransactionNoTLSUsageCheckTest; | |
| 6602 | |
| 6603 //----------------------------------------------------------------------------- | |
| 6604 // All tests are run with three different connection types: SPDY after NPN | |
| 6605 // negotiation, SPDY without SSL, and SPDY with SSL. | |
| 6606 // | |
| 6607 // TODO(akalin): Use ::testing::Combine() when we are able to use | |
| 6608 // <tr1/tuple>. | |
| 6609 INSTANTIATE_TEST_CASE_P( | |
| 6610 Spdy, | |
| 6611 SpdyNetworkTransactionNoTLSUsageCheckTest, | |
| 6612 ::testing::Values(SpdyNetworkTransactionTestParams(kProtoDeprecatedSPDY2, | |
| 6613 SPDYNPN), | |
| 6614 SpdyNetworkTransactionTestParams(kProtoSPDY3, SPDYNPN), | |
| 6615 SpdyNetworkTransactionTestParams(kProtoSPDY31, SPDYNPN))); | |
| 6616 | |
| 6617 TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest, TLSVersionTooOld) { | |
| 6618 scoped_ptr<SSLSocketDataProvider> ssl_provider( | |
| 6619 new SSLSocketDataProvider(ASYNC, OK)); | |
|
Johnny
2014/05/21 16:27:04
What about factoring the duplicated test bodies ou
willchan no longer on Chromium
2014/05/21 17:47:15
Done.
| |
| 6620 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, | |
| 6621 &ssl_provider->connection_status); | |
| 6622 | |
| 6623 // Construct the request. | |
| 6624 scoped_ptr<SpdyFrame> req( | |
| 6625 spdy_util_.ConstructSpdyGet("https://www.google.com/", false, 1, LOWEST)); | |
| 6626 MockWrite writes[] = {CreateMockWrite(*req)}; | |
| 6627 | |
| 6628 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | |
| 6629 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 6630 MockRead reads[] = { | |
| 6631 CreateMockRead(*resp), CreateMockRead(*body), | |
| 6632 MockRead(ASYNC, 0, 0) // EOF | |
| 6633 }; | |
| 6634 | |
| 6635 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); | |
| 6636 HttpRequestInfo request; | |
| 6637 request.method = "GET"; | |
| 6638 request.url = GURL("https://www.google.com/"); | |
| 6639 NormalSpdyTransactionHelper helper( | |
| 6640 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); | |
| 6641 helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass()); | |
| 6642 TransactionHelperResult out = helper.output(); | |
| 6643 EXPECT_EQ(OK, out.rv); | |
| 6644 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | |
| 6645 EXPECT_EQ("hello!", out.response_data); | |
| 6646 } | |
| 6647 | |
| 6648 TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest, TLSCipherSuiteSucky) { | |
| 6649 scoped_ptr<SSLSocketDataProvider> ssl_provider( | |
| 6650 new SSLSocketDataProvider(ASYNC, OK)); | |
| 6651 // Set to TLS_RSA_WITH_NULL_MD5 | |
| 6652 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); | |
| 6653 | |
| 6654 // Construct the request. | |
| 6655 scoped_ptr<SpdyFrame> req( | |
| 6656 spdy_util_.ConstructSpdyGet("https://www.google.com/", false, 1, LOWEST)); | |
| 6657 MockWrite writes[] = {CreateMockWrite(*req)}; | |
| 6658 | |
| 6659 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | |
| 6660 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 6661 MockRead reads[] = { | |
| 6662 CreateMockRead(*resp), CreateMockRead(*body), | |
| 6663 MockRead(ASYNC, 0, 0) // EOF | |
| 6664 }; | |
| 6665 | |
| 6666 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); | |
| 6667 HttpRequestInfo request; | |
| 6668 request.method = "GET"; | |
| 6669 request.url = GURL("https://www.google.com/"); | |
| 6670 NormalSpdyTransactionHelper helper( | |
| 6671 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); | |
| 6672 helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass()); | |
| 6673 TransactionHelperResult out = helper.output(); | |
| 6674 EXPECT_EQ(OK, out.rv); | |
| 6675 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | |
| 6676 EXPECT_EQ("hello!", out.response_data); | |
| 6677 } | |
| 6678 | |
| 6679 typedef SpdyNetworkTransactionTest SpdyNetworkTransactionTLSUsageCheckTest; | |
| 6680 | |
| 6681 INSTANTIATE_TEST_CASE_P( | |
| 6682 Spdy, | |
| 6683 SpdyNetworkTransactionTLSUsageCheckTest, | |
| 6684 ::testing::Values(SpdyNetworkTransactionTestParams(kProtoSPDY4, SPDYNPN))); | |
| 6685 | |
| 6686 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSVersionTooOld) { | |
| 6687 scoped_ptr<SSLSocketDataProvider> ssl_provider( | |
| 6688 new SSLSocketDataProvider(ASYNC, OK)); | |
| 6689 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, | |
| 6690 &ssl_provider->connection_status); | |
| 6691 | |
| 6692 // TODO(willchan): Fix crbug.com/375033 to send GOAWAYs. | |
| 6693 // scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway()); | |
| 6694 // MockWrite writes[] = { | |
| 6695 // CreateMockWrite(*goaway) | |
| 6696 // }; | |
| 6697 | |
| 6698 // DelayedSocketData data(1, NULL, 0, writes, arraysize(writes)); | |
| 6699 DelayedSocketData data(1, NULL, 0, NULL, 0); | |
| 6700 HttpRequestInfo request; | |
| 6701 request.method = "GET"; | |
| 6702 request.url = GURL("https://www.google.com/"); | |
| 6703 NormalSpdyTransactionHelper helper( | |
| 6704 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); | |
| 6705 helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass()); | |
| 6706 TransactionHelperResult out = helper.output(); | |
| 6707 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | |
| 6708 } | |
| 6709 | |
| 6710 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { | |
| 6711 scoped_ptr<SSLSocketDataProvider> ssl_provider( | |
| 6712 new SSLSocketDataProvider(ASYNC, OK)); | |
| 6713 // Set to TLS_RSA_WITH_NULL_MD5 | |
| 6714 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); | |
| 6715 | |
| 6716 // TODO(willchan): Fix crbug.com/375033 to send GOAWAYs. | |
| 6717 // scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway()); | |
| 6718 // MockWrite writes[] = { | |
| 6719 // CreateMockWrite(*goaway) | |
| 6720 // }; | |
| 6721 | |
| 6722 // DelayedSocketData data(1, NULL, 0, writes, arraysize(writes)); | |
| 6723 DelayedSocketData data(1, NULL, 0, NULL, 0); | |
| 6724 HttpRequestInfo request; | |
| 6725 request.method = "GET"; | |
| 6726 request.url = GURL("https://www.google.com/"); | |
| 6727 NormalSpdyTransactionHelper helper( | |
| 6728 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); | |
| 6729 helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass()); | |
| 6730 TransactionHelperResult out = helper.output(); | |
| 6731 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | |
| 6732 } | |
| 6733 | |
| 6582 } // namespace net | 6734 } // namespace net |
| OLD | NEW |