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

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: rsleevi comment 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
« no previous file with comments | « net/socket/ssl_client_socket_openssl.cc ('k') | 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 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 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 // Should still read bytes despite the write error. 1806 // Should still read bytes despite the write error.
1807 EXPECT_LT(0, rv); 1807 EXPECT_LT(0, rv);
1808 #else 1808 #else
1809 // NSS attempts to flush the write buffer in PR_Read on an SSL socket before 1809 // NSS attempts to flush the write buffer in PR_Read on an SSL socket before
1810 // pumping the read state machine, unless configured with SSL_ENABLE_FDX, so 1810 // pumping the read state machine, unless configured with SSL_ENABLE_FDX, so
1811 // the write error stops future reads. 1811 // the write error stops future reads.
1812 EXPECT_EQ(ERR_CONNECTION_RESET, rv); 1812 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
1813 #endif 1813 #endif
1814 } 1814 }
1815 1815
1816 // Tests that SSLClientSocket fails the handshake if the underlying
1817 // transport is cleanly closed.
1818 TEST_F(SSLClientSocketTest, Connect_WithZeroReturn) {
1819 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS,
1820 SpawnedTestServer::kLocalhost,
1821 base::FilePath());
1822 ASSERT_TRUE(test_server.Start());
1823
1824 AddressList addr;
1825 ASSERT_TRUE(test_server.GetAddressList(&addr));
1826
1827 TestCompletionCallback callback;
1828 scoped_ptr<StreamSocket> real_transport(
1829 new TCPClientSocket(addr, NULL, NetLog::Source()));
1830 scoped_ptr<SynchronousErrorStreamSocket> transport(
1831 new SynchronousErrorStreamSocket(real_transport.Pass()));
1832 int rv = callback.GetResult(transport->Connect(callback.callback()));
1833 EXPECT_EQ(OK, rv);
1834
1835 SynchronousErrorStreamSocket* raw_transport = transport.get();
1836 scoped_ptr<SSLClientSocket> sock(
1837 CreateSSLClientSocket(transport.PassAs<StreamSocket>(),
1838 test_server.host_port_pair(),
1839 kDefaultSSLConfig));
1840
1841 raw_transport->SetNextReadError(0);
1842
1843 rv = callback.GetResult(sock->Connect(callback.callback()));
1844 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv);
1845 EXPECT_FALSE(sock->IsConnected());
1846 }
1847
1848 // Tests that SSLClientSocket cleanly returns a Read of size 0 if the
1849 // underlying socket is cleanly closed.
1850 // This is a regression test for https://crbug.com/422246
1851 TEST_F(SSLClientSocketTest, Read_WithZeroReturn) {
1852 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS,
1853 SpawnedTestServer::kLocalhost,
1854 base::FilePath());
1855 ASSERT_TRUE(test_server.Start());
1856
1857 AddressList addr;
1858 ASSERT_TRUE(test_server.GetAddressList(&addr));
1859
1860 TestCompletionCallback callback;
1861 scoped_ptr<StreamSocket> real_transport(
1862 new TCPClientSocket(addr, NULL, NetLog::Source()));
1863 scoped_ptr<SynchronousErrorStreamSocket> transport(
1864 new SynchronousErrorStreamSocket(real_transport.Pass()));
1865 int rv = callback.GetResult(transport->Connect(callback.callback()));
1866 EXPECT_EQ(OK, rv);
1867
1868 // Disable TLS False Start to ensure the handshake has completed.
1869 SSLConfig ssl_config;
1870 ssl_config.false_start_enabled = false;
1871
1872 SynchronousErrorStreamSocket* raw_transport = transport.get();
1873 scoped_ptr<SSLClientSocket> sock(
1874 CreateSSLClientSocket(transport.PassAs<StreamSocket>(),
1875 test_server.host_port_pair(),
1876 ssl_config));
1877
1878 rv = callback.GetResult(sock->Connect(callback.callback()));
1879 EXPECT_EQ(OK, rv);
1880 EXPECT_TRUE(sock->IsConnected());
1881
1882 raw_transport->SetNextReadError(0);
1883 scoped_refptr<IOBuffer> buf(new IOBuffer(4096));
1884 rv = callback.GetResult(sock->Read(buf.get(), 4096, callback.callback()));
1885 EXPECT_EQ(0, rv);
1886 }
1887
1816 TEST_F(SSLClientSocketTest, Read_SmallChunks) { 1888 TEST_F(SSLClientSocketTest, Read_SmallChunks) {
1817 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, 1889 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS,
1818 SpawnedTestServer::kLocalhost, 1890 SpawnedTestServer::kLocalhost,
1819 base::FilePath()); 1891 base::FilePath());
1820 ASSERT_TRUE(test_server.Start()); 1892 ASSERT_TRUE(test_server.Start());
1821 1893
1822 AddressList addr; 1894 AddressList addr;
1823 ASSERT_TRUE(test_server.GetAddressList(&addr)); 1895 ASSERT_TRUE(test_server.GetAddressList(&addr));
1824 1896
1825 TestCompletionCallback callback; 1897 TestCompletionCallback callback;
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after
2965 ssl_config.channel_id_enabled = true; 3037 ssl_config.channel_id_enabled = true;
2966 3038
2967 int rv; 3039 int rv;
2968 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); 3040 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv));
2969 3041
2970 EXPECT_EQ(ERR_UNEXPECTED, rv); 3042 EXPECT_EQ(ERR_UNEXPECTED, rv);
2971 EXPECT_FALSE(sock_->IsConnected()); 3043 EXPECT_FALSE(sock_->IsConnected());
2972 } 3044 }
2973 3045
2974 } // namespace net 3046 } // namespace net
OLDNEW
« no previous file with comments | « 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