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

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

Issue 280853002: Preserve transport errors for OpenSSL sockets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable TCP reset tests on Android. Created 6 years, 6 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 | Annotate | Revision Log
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 "net/base/address_list.h" 10 #include "net/base/address_list.h"
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 1129
1130 if (rv == ERR_IO_PENDING) 1130 if (rv == ERR_IO_PENDING)
1131 rv = callback.WaitForResult(); 1131 rv = callback.WaitForResult();
1132 1132
1133 EXPECT_GE(rv, 0); 1133 EXPECT_GE(rv, 0);
1134 if (rv <= 0) 1134 if (rv <= 0)
1135 break; 1135 break;
1136 } 1136 }
1137 } 1137 }
1138 1138
1139 // Tests that SSLClientSocket properly handle when the underlying transport
1140 // synchronously returns an error code on read failure. The error code should be
1141 // echoed back so SSLv3 fallback logic can condition on it.
1142 TEST_F(SSLClientSocketTest, Connect_WithSynchronousError) {
1143 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS,
1144 SpawnedTestServer::kLocalhost,
1145 base::FilePath());
1146 ASSERT_TRUE(test_server.Start());
1147
1148 AddressList addr;
1149 ASSERT_TRUE(test_server.GetAddressList(&addr));
1150
1151 TestCompletionCallback callback;
1152 scoped_ptr<StreamSocket> real_transport(
1153 new TCPClientSocket(addr, NULL, NetLog::Source()));
1154 scoped_ptr<SynchronousErrorStreamSocket> transport(
1155 new SynchronousErrorStreamSocket(real_transport.Pass()));
1156 int rv = callback.GetResult(transport->Connect(callback.callback()));
1157 EXPECT_EQ(OK, rv);
1158
1159 // Disable TLS False Start to avoid handshake non-determinism.
1160 SSLConfig ssl_config;
1161 ssl_config.false_start_enabled = false;
1162
1163 SynchronousErrorStreamSocket* raw_transport = transport.get();
1164 scoped_ptr<SSLClientSocket> sock(
1165 CreateSSLClientSocket(transport.PassAs<StreamSocket>(),
1166 test_server.host_port_pair(),
1167 ssl_config));
1168
1169 raw_transport->SetNextWriteError(ERR_CONNECTION_RESET);
1170
1171 rv = callback.GetResult(sock->Connect(callback.callback()));
1172 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
1173 EXPECT_FALSE(sock->IsConnected());
1174 }
1175
1139 // Tests that the SSLClientSocket properly handles when the underlying transport 1176 // Tests that the SSLClientSocket properly handles when the underlying transport
1140 // synchronously returns an error code - such as if an intermediary terminates 1177 // synchronously returns an error code - such as if an intermediary terminates
1141 // the socket connection uncleanly. 1178 // the socket connection uncleanly.
1142 // This is a regression test for http://crbug.com/238536 1179 // This is a regression test for http://crbug.com/238536
1143 TEST_F(SSLClientSocketTest, Read_WithSynchronousError) { 1180 TEST_F(SSLClientSocketTest, Read_WithSynchronousError) {
1144 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, 1181 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS,
1145 SpawnedTestServer::kLocalhost, 1182 SpawnedTestServer::kLocalhost,
1146 base::FilePath()); 1183 base::FilePath());
1147 ASSERT_TRUE(test_server.Start()); 1184 ASSERT_TRUE(test_server.Start());
1148 1185
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 // Simulate an unclean/forcible shutdown. 1221 // Simulate an unclean/forcible shutdown.
1185 raw_transport->SetNextReadError(ERR_CONNECTION_RESET); 1222 raw_transport->SetNextReadError(ERR_CONNECTION_RESET);
1186 1223
1187 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); 1224 scoped_refptr<IOBuffer> buf(new IOBuffer(4096));
1188 1225
1189 // Note: This test will hang if this bug has regressed. Simply checking that 1226 // Note: This test will hang if this bug has regressed. Simply checking that
1190 // rv != ERR_IO_PENDING is insufficient, as ERR_IO_PENDING is a legitimate 1227 // rv != ERR_IO_PENDING is insufficient, as ERR_IO_PENDING is a legitimate
1191 // result when using a dedicated task runner for NSS. 1228 // result when using a dedicated task runner for NSS.
1192 rv = callback.GetResult(sock->Read(buf.get(), 4096, callback.callback())); 1229 rv = callback.GetResult(sock->Read(buf.get(), 4096, callback.callback()));
1193 1230
1194 #if !defined(USE_OPENSSL)
1195 // SSLClientSocketNSS records the error exactly
1196 EXPECT_EQ(ERR_CONNECTION_RESET, rv); 1231 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
1197 #else
1198 // SSLClientSocketOpenSSL treats any errors as a simple EOF.
1199 EXPECT_EQ(0, rv);
1200 #endif
1201 } 1232 }
1202 1233
1203 // Tests that the SSLClientSocket properly handles when the underlying transport 1234 // Tests that the SSLClientSocket properly handles when the underlying transport
1204 // asynchronously returns an error code while writing data - such as if an 1235 // asynchronously returns an error code while writing data - such as if an
1205 // intermediary terminates the socket connection uncleanly. 1236 // intermediary terminates the socket connection uncleanly.
1206 // This is a regression test for http://crbug.com/249848 1237 // This is a regression test for http://crbug.com/249848
1207 TEST_F(SSLClientSocketTest, Write_WithSynchronousError) { 1238 TEST_F(SSLClientSocketTest, Write_WithSynchronousError) {
1208 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, 1239 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS,
1209 SpawnedTestServer::kLocalhost, 1240 SpawnedTestServer::kLocalhost,
1210 base::FilePath()); 1241 base::FilePath());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 1296
1266 // Now unblock the outgoing request, having it fail with the connection 1297 // Now unblock the outgoing request, having it fail with the connection
1267 // being reset. 1298 // being reset.
1268 raw_transport->UnblockWrite(); 1299 raw_transport->UnblockWrite();
1269 1300
1270 // Note: This will cause an inifite loop if this bug has regressed. Simply 1301 // Note: This will cause an inifite loop if this bug has regressed. Simply
1271 // checking that rv != ERR_IO_PENDING is insufficient, as ERR_IO_PENDING 1302 // checking that rv != ERR_IO_PENDING is insufficient, as ERR_IO_PENDING
1272 // is a legitimate result when using a dedicated task runner for NSS. 1303 // is a legitimate result when using a dedicated task runner for NSS.
1273 rv = callback.GetResult(rv); 1304 rv = callback.GetResult(rv);
1274 1305
1275 #if !defined(USE_OPENSSL)
1276 // SSLClientSocketNSS records the error exactly
1277 EXPECT_EQ(ERR_CONNECTION_RESET, rv); 1306 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
1278 #else
1279 // SSLClientSocketOpenSSL treats any errors as a simple EOF.
1280 EXPECT_EQ(0, rv);
1281 #endif
1282 } 1307 }
1283 1308
1284 // Test the full duplex mode, with Read and Write pending at the same time. 1309 // Test the full duplex mode, with Read and Write pending at the same time.
1285 // This test also serves as a regression test for http://crbug.com/29815. 1310 // This test also serves as a regression test for http://crbug.com/29815.
1286 TEST_F(SSLClientSocketTest, Read_FullDuplex) { 1311 TEST_F(SSLClientSocketTest, Read_FullDuplex) {
1287 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, 1312 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS,
1288 SpawnedTestServer::kLocalhost, 1313 SpawnedTestServer::kLocalhost,
1289 base::FilePath()); 1314 base::FilePath());
1290 ASSERT_TRUE(test_server.Start()); 1315 ASSERT_TRUE(test_server.Start());
1291 1316
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 ASSERT_EQ(ERR_IO_PENDING, rv); 1471 ASSERT_EQ(ERR_IO_PENDING, rv);
1447 ASSERT_FALSE(callback.have_result()); 1472 ASSERT_FALSE(callback.have_result());
1448 1473
1449 // Now unblock Write(), which will invoke OnSendComplete and (eventually) 1474 // Now unblock Write(), which will invoke OnSendComplete and (eventually)
1450 // call the Read() callback, deleting the socket and thus aborting calling 1475 // call the Read() callback, deleting the socket and thus aborting calling
1451 // the Write() callback. 1476 // the Write() callback.
1452 raw_transport->UnblockWrite(); 1477 raw_transport->UnblockWrite();
1453 1478
1454 rv = read_callback.WaitForResult(); 1479 rv = read_callback.WaitForResult();
1455 1480
1456 #if !defined(USE_OPENSSL)
1457 // NSS records the error exactly.
1458 EXPECT_EQ(ERR_CONNECTION_RESET, rv); 1481 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
1459 #else
1460 // OpenSSL treats any errors as a simple EOF.
1461 EXPECT_EQ(0, rv);
1462 #endif
1463 1482
1464 // The Write callback should not have been called. 1483 // The Write callback should not have been called.
1465 EXPECT_FALSE(callback.have_result()); 1484 EXPECT_FALSE(callback.have_result());
1466 } 1485 }
1467 1486
1468 // Tests that the SSLClientSocket does not crash if data is received on the 1487 // Tests that the SSLClientSocket does not crash if data is received on the
1469 // transport socket after a failing write. This can occur if we have a Write 1488 // transport socket after a failing write. This can occur if we have a Write
1470 // error in a SPDY socket. 1489 // error in a SPDY socket.
1471 // Regression test for http://crbug.com/335557 1490 // Regression test for http://crbug.com/335557
1472 TEST_F(SSLClientSocketTest, Read_WithWriteError) { 1491 TEST_F(SSLClientSocketTest, Read_WithWriteError) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 rv = callback.GetResult(sock->Write(long_request_buffer.get(), 1566 rv = callback.GetResult(sock->Write(long_request_buffer.get(),
1548 long_request_buffer->BytesRemaining(), 1567 long_request_buffer->BytesRemaining(),
1549 callback.callback())); 1568 callback.callback()));
1550 if (rv > 0) { 1569 if (rv > 0) {
1551 long_request_buffer->DidConsume(rv); 1570 long_request_buffer->DidConsume(rv);
1552 // Abort if the entire buffer is ever consumed. 1571 // Abort if the entire buffer is ever consumed.
1553 ASSERT_LT(0, long_request_buffer->BytesRemaining()); 1572 ASSERT_LT(0, long_request_buffer->BytesRemaining());
1554 } 1573 }
1555 } while (rv > 0); 1574 } while (rv > 0);
1556 1575
1557 #if !defined(USE_OPENSSL)
1558 // NSS records the error exactly.
1559 EXPECT_EQ(ERR_CONNECTION_RESET, rv); 1576 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
1560 #else
1561 // OpenSSL treats the reset as a generic protocol error.
1562 EXPECT_EQ(ERR_SSL_PROTOCOL_ERROR, rv);
1563 #endif
1564 1577
1565 // Release the read. Some bytes should go through. 1578 // Release the read.
1566 raw_transport->UnblockReadResult(); 1579 raw_transport->UnblockReadResult();
1567 rv = read_callback.WaitForResult(); 1580 rv = read_callback.WaitForResult();
1568 1581
1569 // Per the fix for http://crbug.com/249848, write failures currently break 1582 #if defined(USE_OPENSSL)
1570 // reads. Change this assertion if they're changed to not collide. 1583 // Should still read bytes despite the write error.
1584 EXPECT_LT(0, rv);
1585 #else
1586 // NSS attempts to flush the write buffer in PR_Read on an SSL socket before
1587 // pumping the read state machine, unless configured with SSL_ENABLE_FDX, so
1588 // the write error bleeds into the read.
1571 EXPECT_EQ(ERR_CONNECTION_RESET, rv); 1589 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
1590 #endif
1572 } 1591 }
1573 1592
1574 TEST_F(SSLClientSocketTest, Read_SmallChunks) { 1593 TEST_F(SSLClientSocketTest, Read_SmallChunks) {
1575 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, 1594 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS,
1576 SpawnedTestServer::kLocalhost, 1595 SpawnedTestServer::kLocalhost,
1577 base::FilePath()); 1596 base::FilePath());
1578 ASSERT_TRUE(test_server.Start()); 1597 ASSERT_TRUE(test_server.Start());
1579 1598
1580 AddressList addr; 1599 AddressList addr;
1581 ASSERT_TRUE(test_server.GetAddressList(&addr)); 1600 ASSERT_TRUE(test_server.GetAddressList(&addr));
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
2519 2538
2520 // TODO(haavardm@opera.com): Due to differences in threading, Linux returns 2539 // TODO(haavardm@opera.com): Due to differences in threading, Linux returns
2521 // ERR_UNEXPECTED while Mac and Windows return ERR_PROTOCOL_ERROR. Accept all 2540 // ERR_UNEXPECTED while Mac and Windows return ERR_PROTOCOL_ERROR. Accept all
2522 // error codes for now. 2541 // error codes for now.
2523 // http://crbug.com/373670 2542 // http://crbug.com/373670
2524 EXPECT_NE(OK, rv); 2543 EXPECT_NE(OK, rv);
2525 EXPECT_FALSE(sock_->IsConnected()); 2544 EXPECT_FALSE(sock_->IsConnected());
2526 } 2545 }
2527 2546
2528 } // namespace net 2547 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698