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

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

Issue 655813003: Close SSLClientSocketOpenSSL cleanly if the transport was closed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 int buf_len, 269 int buf_len,
270 const CompletionCallback& callback) override; 270 const CompletionCallback& callback) override;
271 virtual int Write(IOBuffer* buf, 271 virtual int Write(IOBuffer* buf,
272 int buf_len, 272 int buf_len,
273 const CompletionCallback& callback) override; 273 const CompletionCallback& callback) override;
274 274
275 // Sets the next Read() call and all future calls to return |error|. 275 // Sets the next Read() call and all future calls to return |error|.
276 // If there is already a pending asynchronous read, the configured error 276 // If there is already a pending asynchronous read, the configured error
277 // will not be returned until that asynchronous read has completed and Read() 277 // will not be returned until that asynchronous read has completed and Read()
278 // is called again. 278 // is called again.
279 void SetNextReadError(Error error) { 279 void SetNextReadError(int error) {
280 DCHECK_GE(0, error); 280 DCHECK_GE(0, error);
281 have_read_error_ = true; 281 have_read_error_ = true;
282 pending_read_error_ = error; 282 pending_read_error_ = error;
283 } 283 }
284 284
285 // Sets the next Write() call and all future calls to return |error|. 285 // Sets the next Write() call and all future calls to return |error|.
286 // If there is already a pending asynchronous write, the configured error 286 // If there is already a pending asynchronous write, the configured error
287 // will not be returned until that asynchronous write has completed and 287 // will not be returned until that asynchronous write has completed and
288 // Write() is called again. 288 // Write() is called again.
289 void SetNextWriteError(Error error) { 289 void SetNextWriteError(int error) {
290 DCHECK_GE(0, error); 290 DCHECK_GE(0, error);
291 have_write_error_ = true; 291 have_write_error_ = true;
292 pending_write_error_ = error; 292 pending_write_error_ = error;
293 } 293 }
294 294
295 private: 295 private:
296 bool have_read_error_; 296 bool have_read_error_;
297 int pending_read_error_; 297 int pending_read_error_;
298 298
299 bool have_write_error_; 299 bool have_write_error_;
(...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 // Should still read bytes despite the write error. 1820 // Should still read bytes despite the write error.
1821 EXPECT_LT(0, rv); 1821 EXPECT_LT(0, rv);
1822 #else 1822 #else
1823 // NSS attempts to flush the write buffer in PR_Read on an SSL socket before 1823 // NSS attempts to flush the write buffer in PR_Read on an SSL socket before
1824 // pumping the read state machine, unless configured with SSL_ENABLE_FDX, so 1824 // pumping the read state machine, unless configured with SSL_ENABLE_FDX, so
1825 // the write error stops future reads. 1825 // the write error stops future reads.
1826 EXPECT_EQ(ERR_CONNECTION_RESET, rv); 1826 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
1827 #endif 1827 #endif
1828 } 1828 }
1829 1829
1830 // Tests that SSLClientSocket fails the handshake if the underlying
1831 // transport is cleanly closed.
1832 TEST_F(SSLClientSocketTest, Connect_WithZeroReturn) {
1833 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS,
1834 SpawnedTestServer::kLocalhost,
1835 base::FilePath());
1836 ASSERT_TRUE(test_server.Start());
1837
1838 AddressList addr;
1839 ASSERT_TRUE(test_server.GetAddressList(&addr));
1840
1841 TestCompletionCallback callback;
1842 scoped_ptr<StreamSocket> real_transport(
1843 new TCPClientSocket(addr, NULL, NetLog::Source()));
1844 scoped_ptr<SynchronousErrorStreamSocket> transport(
1845 new SynchronousErrorStreamSocket(real_transport.Pass()));
1846 int rv = callback.GetResult(transport->Connect(callback.callback()));
1847 EXPECT_EQ(OK, rv);
1848
1849 SynchronousErrorStreamSocket* raw_transport = transport.get();
1850 scoped_ptr<SSLClientSocket> sock(
1851 CreateSSLClientSocket(transport.PassAs<StreamSocket>(),
1852 test_server.host_port_pair(),
1853 kDefaultSSLConfig));
1854
1855 raw_transport->SetNextReadError(0);
1856
1857 rv = callback.GetResult(sock->Connect(callback.callback()));
1858 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv);
1859 EXPECT_FALSE(sock->IsConnected());
1860 }
1861
1862 // Tests that SSLClientSocket cleanly returns a Read of size 0 if the
1863 // underlying socket is cleanly closed.
1864 // This is a regression test for https://crbug.com/422246
1865 TEST_F(SSLClientSocketTest, Read_WithZeroReturn) {
1866 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS,
1867 SpawnedTestServer::kLocalhost,
1868 base::FilePath());
1869 ASSERT_TRUE(test_server.Start());
1870
1871 AddressList addr;
1872 ASSERT_TRUE(test_server.GetAddressList(&addr));
1873
1874 TestCompletionCallback callback;
1875 scoped_ptr<StreamSocket> real_transport(
1876 new TCPClientSocket(addr, NULL, NetLog::Source()));
1877 scoped_ptr<SynchronousErrorStreamSocket> transport(
1878 new SynchronousErrorStreamSocket(real_transport.Pass()));
1879 int rv = callback.GetResult(transport->Connect(callback.callback()));
1880 EXPECT_EQ(OK, rv);
1881
1882 // Disable TLS False Start to ensure the handshake has completed.
1883 SSLConfig ssl_config;
1884 ssl_config.false_start_enabled = false;
1885
1886 SynchronousErrorStreamSocket* raw_transport = transport.get();
1887 scoped_ptr<SSLClientSocket> sock(
1888 CreateSSLClientSocket(transport.PassAs<StreamSocket>(),
1889 test_server.host_port_pair(),
1890 ssl_config));
1891
1892 rv = callback.GetResult(sock->Connect(callback.callback()));
1893 EXPECT_EQ(OK, rv);
1894 EXPECT_TRUE(sock->IsConnected());
1895
1896 raw_transport->SetNextReadError(0);
1897 scoped_refptr<IOBuffer> buf(new IOBuffer(4096));
1898 rv = callback.GetResult(sock->Read(buf.get(), 4096, callback.callback()));
1899 EXPECT_EQ(0, rv);
1900 }
1901
1830 TEST_F(SSLClientSocketTest, Read_SmallChunks) { 1902 TEST_F(SSLClientSocketTest, Read_SmallChunks) {
1831 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, 1903 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS,
1832 SpawnedTestServer::kLocalhost, 1904 SpawnedTestServer::kLocalhost,
1833 base::FilePath()); 1905 base::FilePath());
1834 ASSERT_TRUE(test_server.Start()); 1906 ASSERT_TRUE(test_server.Start());
1835 1907
1836 AddressList addr; 1908 AddressList addr;
1837 ASSERT_TRUE(test_server.GetAddressList(&addr)); 1909 ASSERT_TRUE(test_server.GetAddressList(&addr));
1838 1910
1839 TestCompletionCallback callback; 1911 TestCompletionCallback callback;
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2983 ssl_config.channel_id_enabled = true; 3055 ssl_config.channel_id_enabled = true;
2984 3056
2985 int rv; 3057 int rv;
2986 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); 3058 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv));
2987 3059
2988 EXPECT_EQ(ERR_UNEXPECTED, rv); 3060 EXPECT_EQ(ERR_UNEXPECTED, rv);
2989 EXPECT_FALSE(sock_->IsConnected()); 3061 EXPECT_FALSE(sock_->IsConnected());
2990 } 3062 }
2991 3063
2992 } // namespace net 3064 } // namespace net
OLDNEW
« net/socket/ssl_client_socket_openssl.cc ('K') | « net/socket/ssl_client_socket_openssl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698