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 2805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2816 EXPECT_TRUE(sock->WasEverUsed()); | 2816 EXPECT_TRUE(sock->WasEverUsed()); |
2817 | 2817 |
2818 // TODO(davidben): Read one byte to ensure the test server has responded and | 2818 // TODO(davidben): Read one byte to ensure the test server has responded and |
2819 // then assert IsConnectedAndIdle is false. This currently doesn't work | 2819 // then assert IsConnectedAndIdle is false. This currently doesn't work |
2820 // because neither SSLClientSocketNSS nor SSLClientSocketOpenSSL check their | 2820 // because neither SSLClientSocketNSS nor SSLClientSocketOpenSSL check their |
2821 // SSL implementation's internal buffers. Either call PR_Available and | 2821 // SSL implementation's internal buffers. Either call PR_Available and |
2822 // SSL_pending, although the former isn't actually implemented or perhaps | 2822 // SSL_pending, although the former isn't actually implemented or perhaps |
2823 // attempt to read one byte extra. | 2823 // attempt to read one byte extra. |
2824 } | 2824 } |
2825 | 2825 |
| 2826 // Tests that IsConnectedAndIdle treats a socket as idle even if a Write hasn't |
| 2827 // been flushed completely out of SSLClientSocket's internal buffers. This is a |
| 2828 // regression test for https://crbug.com/466147. |
| 2829 TEST_F(SSLClientSocketTest, ReusableAfterWrite) { |
| 2830 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, |
| 2831 SpawnedTestServer::kLocalhost, |
| 2832 base::FilePath()); |
| 2833 ASSERT_TRUE(test_server.Start()); |
| 2834 |
| 2835 AddressList addr; |
| 2836 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 2837 |
| 2838 TestCompletionCallback callback; |
| 2839 scoped_ptr<StreamSocket> real_transport( |
| 2840 new TCPClientSocket(addr, NULL, NetLog::Source())); |
| 2841 scoped_ptr<FakeBlockingStreamSocket> transport( |
| 2842 new FakeBlockingStreamSocket(real_transport.Pass())); |
| 2843 FakeBlockingStreamSocket* raw_transport = transport.get(); |
| 2844 ASSERT_EQ(OK, callback.GetResult(transport->Connect(callback.callback()))); |
| 2845 |
| 2846 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 2847 transport.Pass(), test_server.host_port_pair(), SSLConfig())); |
| 2848 ASSERT_EQ(OK, callback.GetResult(sock->Connect(callback.callback()))); |
| 2849 |
| 2850 // Block any application data from reaching the network. |
| 2851 raw_transport->BlockWrite(); |
| 2852 |
| 2853 // Write a partial HTTP request. |
| 2854 const char kRequestText[] = "GET / HTTP/1.0"; |
| 2855 const size_t kRequestLen = arraysize(kRequestText) - 1; |
| 2856 scoped_refptr<IOBuffer> request_buffer(new IOBuffer(kRequestLen)); |
| 2857 memcpy(request_buffer->data(), kRequestText, kRequestLen); |
| 2858 |
| 2859 // Although transport writes are blocked, both SSLClientSocketOpenSSL and |
| 2860 // SSLClientSocketNSS complete the outer Write operation. |
| 2861 EXPECT_EQ(static_cast<int>(kRequestLen), |
| 2862 callback.GetResult(sock->Write(request_buffer.get(), kRequestLen, |
| 2863 callback.callback()))); |
| 2864 |
| 2865 // The Write operation is complete, so the socket should be treated as |
| 2866 // reusable, in case the server returns an HTTP response before completely |
| 2867 // consuming the request body. In this case, we assume the server will |
| 2868 // properly drain the request body before trying to read the next request. |
| 2869 EXPECT_TRUE(sock->IsConnectedAndIdle()); |
| 2870 } |
| 2871 |
2826 // Tests that basic session resumption works. | 2872 // Tests that basic session resumption works. |
2827 TEST_F(SSLClientSocketTest, SessionResumption) { | 2873 TEST_F(SSLClientSocketTest, SessionResumption) { |
2828 SpawnedTestServer::SSLOptions ssl_options; | 2874 SpawnedTestServer::SSLOptions ssl_options; |
2829 ASSERT_TRUE(StartTestServer(ssl_options)); | 2875 ASSERT_TRUE(StartTestServer(ssl_options)); |
2830 | 2876 |
2831 // First, perform a full handshake. | 2877 // First, perform a full handshake. |
2832 SSLConfig ssl_config; | 2878 SSLConfig ssl_config; |
2833 TestCompletionCallback callback; | 2879 TestCompletionCallback callback; |
2834 scoped_ptr<StreamSocket> transport( | 2880 scoped_ptr<StreamSocket> transport( |
2835 new TCPClientSocket(addr(), &log_, NetLog::Source())); | 2881 new TCPClientSocket(addr(), &log_, NetLog::Source())); |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3385 ssl_config.channel_id_enabled = true; | 3431 ssl_config.channel_id_enabled = true; |
3386 | 3432 |
3387 int rv; | 3433 int rv; |
3388 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | 3434 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); |
3389 | 3435 |
3390 EXPECT_EQ(ERR_UNEXPECTED, rv); | 3436 EXPECT_EQ(ERR_UNEXPECTED, rv); |
3391 EXPECT_FALSE(sock_->IsConnected()); | 3437 EXPECT_FALSE(sock_->IsConnected()); |
3392 } | 3438 } |
3393 | 3439 |
3394 } // namespace net | 3440 } // namespace net |
OLD | NEW |