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

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

Issue 7054010: Update SSLServerSocket to provide the net::StreamSocket interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reinstate SSLServerSocket type, and address comments. Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This test suite uses SSLClientSocket to test the implementation of 5 // This test suite uses SSLClientSocket to test the implementation of
6 // SSLServerSocket. In order to establish connections between the sockets 6 // SSLServerSocket. In order to establish connections between the sockets
7 // we need two additional classes: 7 // we need two additional classes:
8 // 1. FakeSocket 8 // 1. FakeSocket
9 // Connects SSL socket to FakeDataChannel. This class is just a stub. 9 // Connects SSL socket to FakeDataChannel. This class is just a stub.
10 // 10 //
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 fake_client_socket, host_and_pair, ssl_config, NULL, 262 fake_client_socket, host_and_pair, ssl_config, NULL,
263 &cert_verifier_)); 263 &cert_verifier_));
264 server_socket_.reset(net::CreateSSLServerSocket(fake_server_socket, 264 server_socket_.reset(net::CreateSSLServerSocket(fake_server_socket,
265 cert, private_key.get(), 265 cert, private_key.get(),
266 net::SSLConfig())); 266 net::SSLConfig()));
267 } 267 }
268 268
269 FakeDataChannel channel_1_; 269 FakeDataChannel channel_1_;
270 FakeDataChannel channel_2_; 270 FakeDataChannel channel_2_;
271 scoped_ptr<net::SSLClientSocket> client_socket_; 271 scoped_ptr<net::SSLClientSocket> client_socket_;
272 scoped_ptr<net::SSLServerSocket> server_socket_; 272 scoped_ptr<net::StreamSocket> server_socket_;
wtc 2011/06/02 23:12:58 Change this back to SSLServerSocket.
Wez 2011/06/03 17:47:07 Done.
273 net::ClientSocketFactory* socket_factory_; 273 net::ClientSocketFactory* socket_factory_;
274 net::CertVerifier cert_verifier_; 274 net::CertVerifier cert_verifier_;
275 }; 275 };
276 276
277 // SSLServerSocket is only implemented using NSS. 277 // SSLServerSocket is only implemented using NSS.
278 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 278 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
279 279
280 // This test only executes creation of client and server sockets. This is to 280 // This test only executes creation of client and server sockets. This is to
281 // test that creation of sockets doesn't crash and have minimal code to run 281 // test that creation of sockets doesn't crash and have minimal code to run
282 // under valgrind in order to help debugging memory problems. 282 // under valgrind in order to help debugging memory problems.
283 TEST_F(SSLServerSocketTest, Initialize) { 283 TEST_F(SSLServerSocketTest, Initialize) {
284 Initialize(); 284 Initialize();
285 } 285 }
286 286
287 // This test executes Connect() of SSLClientSocket and Accept() of 287 // This test executes Connect() of SSLClientSocket and Accept() of
288 // SSLServerSocket to make sure handshaking between the two sockets are 288 // SSLServerSocket to make sure handshaking between the two sockets are
289 // completed successfully. 289 // completed successfully.
290 TEST_F(SSLServerSocketTest, Handshake) { 290 TEST_F(SSLServerSocketTest, Handshake) {
291 Initialize(); 291 Initialize();
292 292
293 TestCompletionCallback connect_callback; 293 TestCompletionCallback connect_callback;
294 TestCompletionCallback accept_callback; 294 TestCompletionCallback accept_callback;
295 295
296 int server_ret = server_socket_->Accept(&accept_callback); 296 int server_ret = server_socket_->Connect(&accept_callback);
297 EXPECT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING); 297 EXPECT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING);
298 298
299 int client_ret = client_socket_->Connect(&connect_callback); 299 int client_ret = client_socket_->Connect(&connect_callback);
300 EXPECT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); 300 EXPECT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING);
301 301
302 if (client_ret == net::ERR_IO_PENDING) { 302 if (client_ret == net::ERR_IO_PENDING) {
303 EXPECT_EQ(net::OK, connect_callback.WaitForResult()); 303 EXPECT_EQ(net::OK, connect_callback.WaitForResult());
304 } 304 }
305 if (server_ret == net::ERR_IO_PENDING) { 305 if (server_ret == net::ERR_IO_PENDING) {
306 EXPECT_EQ(net::OK, accept_callback.WaitForResult()); 306 EXPECT_EQ(net::OK, accept_callback.WaitForResult());
307 } 307 }
308 308
309 // Make sure the cert status is expected. 309 // Make sure the cert status is expected.
310 SSLInfo ssl_info; 310 SSLInfo ssl_info;
311 client_socket_->GetSSLInfo(&ssl_info); 311 client_socket_->GetSSLInfo(&ssl_info);
312 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, ssl_info.cert_status); 312 EXPECT_EQ(CERT_STATUS_AUTHORITY_INVALID, ssl_info.cert_status);
313 } 313 }
314 314
315 TEST_F(SSLServerSocketTest, DataTransfer) { 315 TEST_F(SSLServerSocketTest, DataTransfer) {
316 Initialize(); 316 Initialize();
317 317
318 TestCompletionCallback connect_callback; 318 TestCompletionCallback connect_callback;
319 TestCompletionCallback accept_callback; 319 TestCompletionCallback accept_callback;
320 320
321 // Establish connection. 321 // Establish connection.
322 int client_ret = client_socket_->Connect(&connect_callback); 322 int client_ret = client_socket_->Connect(&connect_callback);
323 ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING); 323 ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING);
324 324
325 int server_ret = server_socket_->Accept(&accept_callback); 325 int server_ret = server_socket_->Connect(&accept_callback);
326 ASSERT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING); 326 ASSERT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING);
327 327
328 if (client_ret == net::ERR_IO_PENDING) { 328 if (client_ret == net::ERR_IO_PENDING) {
329 ASSERT_EQ(net::OK, connect_callback.WaitForResult()); 329 ASSERT_EQ(net::OK, connect_callback.WaitForResult());
330 } 330 }
331 if (server_ret == net::ERR_IO_PENDING) { 331 if (server_ret == net::ERR_IO_PENDING) {
332 ASSERT_EQ(net::OK, accept_callback.WaitForResult()); 332 ASSERT_EQ(net::OK, accept_callback.WaitForResult());
333 } 333 }
334 334
335 const int kReadBufSize = 1024; 335 const int kReadBufSize = 1024;
(...skipping 30 matching lines...) Expand all
366 EXPECT_GT(read_callback.WaitForResult(), 0); 366 EXPECT_GT(read_callback.WaitForResult(), 0);
367 } 367 }
368 if (client_ret == net::ERR_IO_PENDING) { 368 if (client_ret == net::ERR_IO_PENDING) {
369 EXPECT_GT(write_callback.WaitForResult(), 0); 369 EXPECT_GT(write_callback.WaitForResult(), 0);
370 } 370 }
371 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size())); 371 EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size()));
372 } 372 }
373 #endif 373 #endif
374 374
375 } // namespace net 375 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698