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 "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 2676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2687 rv = callback.GetResult(sock->Connect(callback.callback())); | 2687 rv = callback.GetResult(sock->Connect(callback.callback())); |
2688 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | 2688 EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
2689 EXPECT_FALSE(sock->IsConnected()); | 2689 EXPECT_FALSE(sock->IsConnected()); |
2690 | 2690 |
2691 EXPECT_TRUE(ran_handshake_completion_callback_); | 2691 EXPECT_TRUE(ran_handshake_completion_callback_); |
2692 } | 2692 } |
2693 | 2693 |
2694 // Tests that the completion callback is run when an SSL connection | 2694 // Tests that the completion callback is run when an SSL connection |
2695 // completes successfully. | 2695 // completes successfully. |
2696 TEST_F(SSLClientSocketTest, HandshakeCallbackIsRun_WithSuccess) { | 2696 TEST_F(SSLClientSocketTest, HandshakeCallbackIsRun_WithSuccess) { |
2697 SpawnedTestServer::SSLOptions ssl_options; | 2697 SpawnedTestServer::SSLOptions ssl_options; |
wtc
2014/08/07 20:04:04
Delete this line. The |ssl_options| local variable
| |
2698 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, | 2698 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, |
2699 SpawnedTestServer::kLocalhost, | 2699 SpawnedTestServer::kLocalhost, |
2700 base::FilePath()); | 2700 base::FilePath()); |
2701 ASSERT_TRUE(test_server.Start()); | 2701 ASSERT_TRUE(test_server.Start()); |
2702 | 2702 |
2703 AddressList addr; | 2703 AddressList addr; |
2704 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 2704 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
2705 | 2705 |
2706 scoped_ptr<StreamSocket> transport( | 2706 scoped_ptr<StreamSocket> transport( |
2707 new TCPClientSocket(addr, NULL, NetLog::Source())); | 2707 new TCPClientSocket(addr, NULL, NetLog::Source())); |
2708 | 2708 |
2709 TestCompletionCallback callback; | 2709 TestCompletionCallback callback; |
2710 int rv = transport->Connect(callback.callback()); | 2710 int rv = transport->Connect(callback.callback()); |
2711 if (rv == ERR_IO_PENDING) | 2711 if (rv == ERR_IO_PENDING) |
2712 rv = callback.WaitForResult(); | 2712 rv = callback.WaitForResult(); |
2713 EXPECT_EQ(OK, rv); | 2713 EXPECT_EQ(OK, rv); |
2714 | 2714 |
2715 SSLConfig ssl_config = kDefaultSSLConfig; | 2715 SSLConfig ssl_config = kDefaultSSLConfig; |
2716 ssl_config.false_start_enabled = false; | 2716 ssl_config.false_start_enabled = false; |
2717 | 2717 |
2718 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 2718 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
2719 transport.Pass(), test_server.host_port_pair(), ssl_config)); | 2719 transport.Pass(), test_server.host_port_pair(), ssl_config)); |
2720 | 2720 |
2721 sock->SetHandshakeCompletionCallback(base::Bind( | 2721 sock->SetHandshakeCompletionCallback(base::Bind( |
2722 &SSLClientSocketTest::RecordCompletedHandshake, base::Unretained(this))); | 2722 &SSLClientSocketTest::RecordCompletedHandshake, base::Unretained(this))); |
2723 | 2723 |
2724 if (sock->IsConnected()) | |
2725 LOG(ERROR) << "SSL Socket prematurely connected"; | |
wtc
2014/08/07 20:04:04
Did you mean to delete this? (I agree it's not use
| |
2726 | |
2727 rv = callback.GetResult(sock->Connect(callback.callback())); | 2724 rv = callback.GetResult(sock->Connect(callback.callback())); |
2728 | 2725 |
2729 EXPECT_EQ(OK, rv); | 2726 EXPECT_EQ(OK, rv); |
2730 EXPECT_TRUE(sock->IsConnected()); | 2727 EXPECT_TRUE(sock->IsConnected()); |
2731 EXPECT_TRUE(ran_handshake_completion_callback_); | 2728 EXPECT_TRUE(ran_handshake_completion_callback_); |
2732 } | 2729 } |
2733 | 2730 |
2731 // Tests that the completion callback is run with connections | |
2732 // that do not cache their session. | |
wtc
2014/08/07 20:04:04
Nit: this should point out it is the server that d
| |
2733 TEST_F(SSLClientSocketTest, HandshakeCallbackIsRun_WithDisabledSessionCache) { | |
2734 SpawnedTestServer::SSLOptions ssl_options; | |
2735 ssl_options.disable_session_cache = true; | |
2736 SpawnedTestServer test_server( | |
2737 SpawnedTestServer::TYPE_HTTPS, ssl_options, base::FilePath()); | |
2738 ASSERT_TRUE(test_server.Start()); | |
2739 | |
2740 AddressList addr; | |
2741 ASSERT_TRUE(test_server.GetAddressList(&addr)); | |
2742 | |
2743 scoped_ptr<StreamSocket> transport( | |
2744 new TCPClientSocket(addr, NULL, NetLog::Source())); | |
2745 | |
2746 TestCompletionCallback callback; | |
2747 int rv = transport->Connect(callback.callback()); | |
2748 if (rv == ERR_IO_PENDING) | |
2749 rv = callback.WaitForResult(); | |
2750 EXPECT_EQ(OK, rv); | |
2751 | |
2752 SSLConfig ssl_config = kDefaultSSLConfig; | |
2753 ssl_config.false_start_enabled = false; | |
2754 | |
2755 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | |
2756 transport.Pass(), test_server.host_port_pair(), ssl_config)); | |
2757 | |
2758 sock->SetHandshakeCompletionCallback(base::Bind( | |
2759 &SSLClientSocketTest::RecordCompletedHandshake, base::Unretained(this))); | |
2760 | |
2761 rv = callback.GetResult(sock->Connect(callback.callback())); | |
2762 | |
2763 EXPECT_EQ(OK, rv); | |
2764 EXPECT_TRUE(sock->IsConnected()); | |
2765 EXPECT_TRUE(ran_handshake_completion_callback_); | |
2766 } | |
2734 #endif // defined(USE_OPENSSL) | 2767 #endif // defined(USE_OPENSSL) |
2735 | 2768 |
2736 TEST_F(SSLClientSocketFalseStartTest, FalseStartEnabled) { | 2769 TEST_F(SSLClientSocketFalseStartTest, FalseStartEnabled) { |
2737 // False Start requires NPN and a forward-secret cipher suite. | 2770 // False Start requires NPN and a forward-secret cipher suite. |
2738 SpawnedTestServer::SSLOptions server_options; | 2771 SpawnedTestServer::SSLOptions server_options; |
2739 server_options.key_exchanges = | 2772 server_options.key_exchanges = |
2740 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; | 2773 SpawnedTestServer::SSLOptions::KEY_EXCHANGE_DHE_RSA; |
2741 server_options.enable_npn = true; | 2774 server_options.enable_npn = true; |
2742 SSLConfig client_config; | 2775 SSLConfig client_config; |
2743 client_config.next_protos.push_back("http/1.1"); | 2776 client_config.next_protos.push_back("http/1.1"); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2895 ssl_config.channel_id_enabled = true; | 2928 ssl_config.channel_id_enabled = true; |
2896 | 2929 |
2897 int rv; | 2930 int rv; |
2898 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | 2931 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); |
2899 | 2932 |
2900 EXPECT_EQ(ERR_UNEXPECTED, rv); | 2933 EXPECT_EQ(ERR_UNEXPECTED, rv); |
2901 EXPECT_FALSE(sock_->IsConnected()); | 2934 EXPECT_FALSE(sock_->IsConnected()); |
2902 } | 2935 } |
2903 | 2936 |
2904 } // namespace net | 2937 } // namespace net |
OLD | NEW |