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

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

Issue 1921563003: Renaming _openssl files to _impl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 // the ERR_IO_PENDING caused by SetReadShouldBlock() and thus return. 1494 // the ERR_IO_PENDING caused by SetReadShouldBlock() and thus return.
1495 SSLClientSocket* raw_sock = sock.get(); 1495 SSLClientSocket* raw_sock = sock.get();
1496 DeleteSocketCallback read_callback(sock.release()); 1496 DeleteSocketCallback read_callback(sock.release());
1497 scoped_refptr<IOBuffer> read_buf(new IOBuffer(4096)); 1497 scoped_refptr<IOBuffer> read_buf(new IOBuffer(4096));
1498 rv = raw_sock->Read(read_buf.get(), 4096, read_callback.callback()); 1498 rv = raw_sock->Read(read_buf.get(), 4096, read_callback.callback());
1499 1499
1500 // Ensure things didn't complete synchronously, otherwise |sock| is invalid. 1500 // Ensure things didn't complete synchronously, otherwise |sock| is invalid.
1501 ASSERT_EQ(ERR_IO_PENDING, rv); 1501 ASSERT_EQ(ERR_IO_PENDING, rv);
1502 ASSERT_FALSE(read_callback.have_result()); 1502 ASSERT_FALSE(read_callback.have_result());
1503 1503
1504 // Attempt to write the remaining data. NSS will not be able to consume the 1504 // Attempt to write the remaining data. OpenSSL will return that its blocked
1505 // application data because the internal buffers are full, while OpenSSL will 1505 // because the underlying transport is blocked.
1506 // return that its blocked because the underlying transport is blocked.
1507 rv = raw_sock->Write(request_buffer.get(), 1506 rv = raw_sock->Write(request_buffer.get(),
1508 request_buffer->BytesRemaining(), 1507 request_buffer->BytesRemaining(),
1509 callback.callback()); 1508 callback.callback());
1510 ASSERT_EQ(ERR_IO_PENDING, rv); 1509 ASSERT_EQ(ERR_IO_PENDING, rv);
1511 ASSERT_FALSE(callback.have_result()); 1510 ASSERT_FALSE(callback.have_result());
1512 1511
1513 // Now unblock Write(), which will invoke OnSendComplete and (eventually) 1512 // Now unblock Write(), which will invoke OnSendComplete and (eventually)
1514 // call the Read() callback, deleting the socket and thus aborting calling 1513 // call the Read() callback, deleting the socket and thus aborting calling
1515 // the Write() callback. 1514 // the Write() callback.
1516 raw_transport->UnblockWrite(); 1515 raw_transport->UnblockWrite();
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 TestCompletionCallback callback; 2450 TestCompletionCallback callback;
2452 rv = callback.GetResult( 2451 rv = callback.GetResult(
2453 sock_->Write(request_buffer.get(), kRequestLen, callback.callback())); 2452 sock_->Write(request_buffer.get(), kRequestLen, callback.callback()));
2454 EXPECT_EQ(static_cast<int>(kRequestLen), rv); 2453 EXPECT_EQ(static_cast<int>(kRequestLen), rv);
2455 2454
2456 // The socket has now been used. 2455 // The socket has now been used.
2457 EXPECT_TRUE(sock_->WasEverUsed()); 2456 EXPECT_TRUE(sock_->WasEverUsed());
2458 2457
2459 // TODO(davidben): Read one byte to ensure the test server has responded and 2458 // TODO(davidben): Read one byte to ensure the test server has responded and
2460 // then assert IsConnectedAndIdle is false. This currently doesn't work 2459 // then assert IsConnectedAndIdle is false. This currently doesn't work
2461 // because neither SSLClientSocketNSS nor SSLClientSocketOpenSSL check their 2460 // because SSLClientSocketImpl doesn't check the implementation's internal
2462 // SSL implementation's internal buffers. Either call PR_Available and 2461 // buffer. Either call PR_Available and SSL_pending, although the former
davidben 2016/04/25 16:14:19 Replace this last sentence with just "Call SSL_pen
svaldez 2016/04/25 20:26:35 Done.
2463 // SSL_pending, although the former isn't actually implemented or perhaps 2462 // isn't actually implemented or perhaps attempt to read one byte extra.
2464 // attempt to read one byte extra.
2465 } 2463 }
2466 2464
2467 // Tests that IsConnectedAndIdle treats a socket as idle even if a Write hasn't 2465 // Tests that IsConnectedAndIdle treats a socket as idle even if a Write hasn't
2468 // been flushed completely out of SSLClientSocket's internal buffers. This is a 2466 // been flushed completely out of SSLClientSocket's internal buffers. This is a
2469 // regression test for https://crbug.com/466147. 2467 // regression test for https://crbug.com/466147.
2470 TEST_F(SSLClientSocketTest, ReusableAfterWrite) { 2468 TEST_F(SSLClientSocketTest, ReusableAfterWrite) {
2471 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); 2469 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
2472 2470
2473 TestCompletionCallback callback; 2471 TestCompletionCallback callback;
2474 std::unique_ptr<StreamSocket> real_transport( 2472 std::unique_ptr<StreamSocket> real_transport(
(...skipping 10 matching lines...) Expand all
2485 2483
2486 // Block any application data from reaching the network. 2484 // Block any application data from reaching the network.
2487 raw_transport->BlockWrite(); 2485 raw_transport->BlockWrite();
2488 2486
2489 // Write a partial HTTP request. 2487 // Write a partial HTTP request.
2490 const char kRequestText[] = "GET / HTTP/1.0"; 2488 const char kRequestText[] = "GET / HTTP/1.0";
2491 const size_t kRequestLen = arraysize(kRequestText) - 1; 2489 const size_t kRequestLen = arraysize(kRequestText) - 1;
2492 scoped_refptr<IOBuffer> request_buffer(new IOBuffer(kRequestLen)); 2490 scoped_refptr<IOBuffer> request_buffer(new IOBuffer(kRequestLen));
2493 memcpy(request_buffer->data(), kRequestText, kRequestLen); 2491 memcpy(request_buffer->data(), kRequestText, kRequestLen);
2494 2492
2495 // Although transport writes are blocked, both SSLClientSocketOpenSSL and 2493 // Although transport writes are blocked, SSLClientSocketImpl completes the
2496 // SSLClientSocketNSS complete the outer Write operation. 2494 // outer Write operation.
2497 EXPECT_EQ(static_cast<int>(kRequestLen), 2495 EXPECT_EQ(static_cast<int>(kRequestLen),
2498 callback.GetResult(sock->Write(request_buffer.get(), kRequestLen, 2496 callback.GetResult(sock->Write(request_buffer.get(), kRequestLen,
2499 callback.callback()))); 2497 callback.callback())));
2500 2498
2501 // The Write operation is complete, so the socket should be treated as 2499 // The Write operation is complete, so the socket should be treated as
2502 // reusable, in case the server returns an HTTP response before completely 2500 // reusable, in case the server returns an HTTP response before completely
2503 // consuming the request body. In this case, we assume the server will 2501 // consuming the request body. In this case, we assume the server will
2504 // properly drain the request body before trying to read the next request. 2502 // properly drain the request body before trying to read the next request.
2505 EXPECT_TRUE(sock->IsConnectedAndIdle()); 2503 EXPECT_TRUE(sock->IsConnectedAndIdle());
2506 } 2504 }
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
3285 3283
3286 SSLInfo ssl_info; 3284 SSLInfo ssl_info;
3287 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); 3285 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info));
3288 EXPECT_TRUE(ssl_info.client_cert_sent); 3286 EXPECT_TRUE(ssl_info.client_cert_sent);
3289 3287
3290 sock_->Disconnect(); 3288 sock_->Disconnect();
3291 EXPECT_FALSE(sock_->IsConnected()); 3289 EXPECT_FALSE(sock_->IsConnected());
3292 } 3290 }
3293 3291
3294 } // namespace net 3292 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698