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

Side by Side Diff: net/socket/ssl_client_socket_unittest.cc

Issue 446623004: This CL adds unit tests for false start connections. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sslcallback
Patch Set: Created 6 years, 4 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 | « no previous file | 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/socket/ssl_client_socket.h" 5 #include "net/socket/ssl_client_socket.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 sock->Disconnect(); 789 sock->Disconnect();
790 EXPECT_FALSE(sock->IsConnected()); 790 EXPECT_FALSE(sock->IsConnected());
791 EXPECT_TRUE( 791 EXPECT_TRUE(
792 test_server.host_port_pair().Equals(request_info->host_and_port)); 792 test_server.host_port_pair().Equals(request_info->host_and_port));
793 793
794 return request_info; 794 return request_info;
795 } 795 }
796 }; 796 };
797 797
798 class SSLClientSocketFalseStartTest : public SSLClientSocketTest { 798 class SSLClientSocketFalseStartTest : public SSLClientSocketTest {
799 public:
800 SSLClientSocketFalseStartTest() : monitor_handshake_callback_(false) {}
801
799 protected: 802 protected:
800 // Creates an SSLClientSocket with |client_config| attached to a 803 // Creates an SSLClientSocket with |client_config| attached to a
801 // FakeBlockingStreamSocket, returning both in |*out_raw_transport| and 804 // FakeBlockingStreamSocket, returning both in |*out_raw_transport| and
802 // |*out_sock|. The FakeBlockingStreamSocket is owned by the SSLClientSocket, 805 // |*out_sock|. The FakeBlockingStreamSocket is owned by the SSLClientSocket,
803 // so |*out_raw_transport| is a raw pointer. 806 // so |*out_raw_transport| is a raw pointer.
804 // 807 //
805 // The client socket will begin a connect using |callback| but stop before the 808 // The client socket will begin a connect using |callback| but stop before the
806 // server's finished message is received. The finished message will be blocked 809 // server's finished message is received. The finished message will be blocked
807 // in |*out_raw_transport|. To complete the handshake and successfully read 810 // in |*out_raw_transport|. To complete the handshake and successfully read
808 // data, the caller must unblock reads on |*out_raw_transport|. (Note that, if 811 // data, the caller must unblock reads on |*out_raw_transport|. (Note that, if
(...skipping 14 matching lines...) Expand all
823 new FakeBlockingStreamSocket(real_transport.Pass())); 826 new FakeBlockingStreamSocket(real_transport.Pass()));
824 int rv = callback->GetResult(transport->Connect(callback->callback())); 827 int rv = callback->GetResult(transport->Connect(callback->callback()));
825 EXPECT_EQ(OK, rv); 828 EXPECT_EQ(OK, rv);
826 829
827 FakeBlockingStreamSocket* raw_transport = transport.get(); 830 FakeBlockingStreamSocket* raw_transport = transport.get();
828 scoped_ptr<SSLClientSocket> sock = 831 scoped_ptr<SSLClientSocket> sock =
829 CreateSSLClientSocket(transport.PassAs<StreamSocket>(), 832 CreateSSLClientSocket(transport.PassAs<StreamSocket>(),
830 test_server()->host_port_pair(), 833 test_server()->host_port_pair(),
831 client_config); 834 client_config);
832 835
836 if (monitor_handshake_callback_) {
837 sock->SetHandshakeCompletionCallback(
838 base::Bind(&SSLClientSocketTest::RecordCompletedHandshake,
839 base::Unretained(this)));
840 }
841
833 // Connect. Stop before the client processes the first server leg 842 // Connect. Stop before the client processes the first server leg
834 // (ServerHello, etc.) 843 // (ServerHello, etc.)
835 raw_transport->BlockReadResult(); 844 raw_transport->BlockReadResult();
836 rv = sock->Connect(callback->callback()); 845 rv = sock->Connect(callback->callback());
837 EXPECT_EQ(ERR_IO_PENDING, rv); 846 EXPECT_EQ(ERR_IO_PENDING, rv);
838 raw_transport->WaitForReadResult(); 847 raw_transport->WaitForReadResult();
839 848
840 // Release the ServerHello and wait for the client to write 849 // Release the ServerHello and wait for the client to write
841 // ClientKeyExchange, etc. (A proxy for waiting for the entirety of the 850 // ClientKeyExchange, etc. (A proxy for waiting for the entirety of the
842 // server's leg to complete, since it may span multiple reads.) 851 // server's leg to complete, since it may span multiple reads.)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 raw_transport->UnblockReadResult(); 906 raw_transport->UnblockReadResult();
898 rv = callback.GetResult(rv); 907 rv = callback.GetResult(rv);
899 EXPECT_LT(0, rv); 908 EXPECT_LT(0, rv);
900 } else { 909 } else {
901 // False Start is not enabled, so the handshake will not complete because 910 // False Start is not enabled, so the handshake will not complete because
902 // the server second leg is blocked. 911 // the server second leg is blocked.
903 base::RunLoop().RunUntilIdle(); 912 base::RunLoop().RunUntilIdle();
904 EXPECT_FALSE(callback.have_result()); 913 EXPECT_FALSE(callback.have_result());
905 } 914 }
906 } 915 }
916
917 // Indicates that the socket's handshake completion callback should
918 // be monitored.
919 bool monitor_handshake_callback_;
907 }; 920 };
908 921
909 class SSLClientSocketChannelIDTest : public SSLClientSocketTest { 922 class SSLClientSocketChannelIDTest : public SSLClientSocketTest {
910 protected: 923 protected:
911 void EnableChannelID() { 924 void EnableChannelID() {
912 channel_id_service_.reset( 925 channel_id_service_.reset(
913 new ChannelIDService(new DefaultChannelIDStore(NULL), 926 new ChannelIDService(new DefaultChannelIDStore(NULL),
914 base::MessageLoopProxy::current())); 927 base::MessageLoopProxy::current()));
915 context_.channel_id_service = channel_id_service_.get(); 928 context_.channel_id_service = channel_id_service_.get();
916 } 929 }
(...skipping 1846 matching lines...) Expand 10 before | Expand all | Expand 10 after
2763 2776
2764 if (sock->IsConnected()) 2777 if (sock->IsConnected())
2765 LOG(ERROR) << "SSL Socket prematurely connected"; 2778 LOG(ERROR) << "SSL Socket prematurely connected";
2766 2779
2767 rv = callback.GetResult(sock->Connect(callback.callback())); 2780 rv = callback.GetResult(sock->Connect(callback.callback()));
2768 2781
2769 EXPECT_EQ(OK, rv); 2782 EXPECT_EQ(OK, rv);
2770 EXPECT_TRUE(sock->IsConnected()); 2783 EXPECT_TRUE(sock->IsConnected());
2771 EXPECT_TRUE(ran_handshake_completion_callback_); 2784 EXPECT_TRUE(ran_handshake_completion_callback_);
2772 } 2785 }
2786
2787 TEST_F(SSLClientSocketTest, HandshakeCallbackIsRun_WithFalseStartFailure) {
davidben 2014/08/06 19:12:46 Hrm. I'm not sure this test actually does anything
2788 // False Start requires NPN and a forward-secret cipher suite.
2789 SpawnedTestServer::SSLOptions server_options;
2790 server_options.key_exchanges =
2791 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA;
2792 server_options.enable_npn = true;
2793 SSLConfig client_config;
2794 client_config.next_protos.push_back("http/1.1");
2795
2796 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS,
2797 server_options,
2798 base::FilePath());
2799 ASSERT_TRUE(test_server.Start());
2800
2801 AddressList addr;
2802 ASSERT_TRUE(test_server.GetAddressList(&addr));
2803
2804 TestCompletionCallback callback;
2805 scoped_ptr<StreamSocket> real_transport(
2806 new TCPClientSocket(addr, NULL, NetLog::Source()));
2807 scoped_ptr<SynchronousErrorStreamSocket> transport(
2808 new SynchronousErrorStreamSocket(real_transport.Pass()));
2809 int rv = callback.GetResult(transport->Connect(callback.callback()));
2810 EXPECT_EQ(OK, rv);
2811
2812 SynchronousErrorStreamSocket* raw_transport = transport.get();
2813 scoped_ptr<SSLClientSocket> sock(
2814 CreateSSLClientSocket(transport.PassAs<StreamSocket>(),
2815 test_server.host_port_pair(),
2816 client_config));
2817
2818 sock->SetHandshakeCompletionCallback(base::Bind(
2819 &SSLClientSocketTest::RecordCompletedHandshake, base::Unretained(this)));
2820
2821 raw_transport->SetNextWriteError(ERR_CONNECTION_RESET);
2822
2823 rv = callback.GetResult(sock->Connect(callback.callback()));
2824 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
2825 EXPECT_FALSE(sock->IsConnected());
2826
2827 EXPECT_TRUE(ran_handshake_completion_callback_);
2828 }
2829
2830 TEST_F(SSLClientSocketFalseStartTest,
2831 HandshakeCallbackIsRun_WithFalseStartSuccess) {
2832 // False Start requires NPN and a forward-secret cipher suite.
2833 SpawnedTestServer::SSLOptions server_options;
2834 server_options.key_exchanges =
2835 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA;
2836 server_options.enable_npn = true;
2837 SSLConfig client_config;
2838 client_config.next_protos.push_back("http/1.1");
2839 monitor_handshake_callback_ = true;
2840 ASSERT_NO_FATAL_FAILURE(TestFalseStart(server_options, client_config, true));
2841 ASSERT_TRUE(ran_handshake_completion_callback_);
2842 }
2843
2773 #endif // defined(USE_OPENSSL) 2844 #endif // defined(USE_OPENSSL)
2774 2845
2775 TEST_F(SSLClientSocketFalseStartTest, FalseStartEnabled) { 2846 TEST_F(SSLClientSocketFalseStartTest, FalseStartEnabled) {
2776 // False Start requires NPN and a forward-secret cipher suite. 2847 // False Start requires NPN and a forward-secret cipher suite.
2777 SpawnedTestServer::SSLOptions server_options; 2848 SpawnedTestServer::SSLOptions server_options;
2778 server_options.key_exchanges = 2849 server_options.key_exchanges =
2779 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; 2850 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA;
2780 server_options.enable_npn = true; 2851 server_options.enable_npn = true;
2781 SSLConfig client_config; 2852 SSLConfig client_config;
2782 client_config.next_protos.push_back("http/1.1"); 2853 client_config.next_protos.push_back("http/1.1");
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2934 ssl_config.channel_id_enabled = true; 3005 ssl_config.channel_id_enabled = true;
2935 3006
2936 int rv; 3007 int rv;
2937 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); 3008 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv));
2938 3009
2939 EXPECT_EQ(ERR_UNEXPECTED, rv); 3010 EXPECT_EQ(ERR_UNEXPECTED, rv);
2940 EXPECT_FALSE(sock_->IsConnected()); 3011 EXPECT_FALSE(sock_->IsConnected());
2941 } 3012 }
2942 3013
2943 } // namespace net 3014 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698