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

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

Issue 9476035: Make CertVerifier a pure virtual interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win shared fix Created 8 years, 9 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
« no previous file with comments | « net/socket/ssl_host_info.h ('k') | net/spdy/spdy_test_util_spdy2.cc » ('j') | 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 // 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 238
239 read = callback.WaitForResult(); 239 read = callback.WaitForResult();
240 EXPECT_GT(read, 0); 240 EXPECT_GT(read, 0);
241 EXPECT_LE(read, written); 241 EXPECT_LE(read, written);
242 EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), read)); 242 EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), read));
243 } 243 }
244 244
245 class SSLServerSocketTest : public PlatformTest { 245 class SSLServerSocketTest : public PlatformTest {
246 public: 246 public:
247 SSLServerSocketTest() 247 SSLServerSocketTest()
248 : socket_factory_(net::ClientSocketFactory::GetDefaultFactory()) { 248 : socket_factory_(net::ClientSocketFactory::GetDefaultFactory()),
249 cert_verifier_(net::CertVerifier::CreateDefault()) {
249 } 250 }
250 251
251 protected: 252 protected:
252 void Initialize() { 253 void Initialize() {
253 FakeSocket* fake_client_socket = new FakeSocket(&channel_1_, &channel_2_); 254 FakeSocket* fake_client_socket = new FakeSocket(&channel_1_, &channel_2_);
254 FakeSocket* fake_server_socket = new FakeSocket(&channel_2_, &channel_1_); 255 FakeSocket* fake_server_socket = new FakeSocket(&channel_2_, &channel_1_);
255 256
256 FilePath certs_dir; 257 FilePath certs_dir;
257 PathService::Get(base::DIR_SOURCE_ROOT, &certs_dir); 258 PathService::Get(base::DIR_SOURCE_ROOT, &certs_dir);
258 certs_dir = certs_dir.AppendASCII("net"); 259 certs_dir = certs_dir.AppendASCII("net");
(...skipping 27 matching lines...) Expand all
286 ssl_config.tls1_enabled = true; 287 ssl_config.tls1_enabled = true;
287 288
288 // Certificate provided by the host doesn't need authority. 289 // Certificate provided by the host doesn't need authority.
289 net::SSLConfig::CertAndStatus cert_and_status; 290 net::SSLConfig::CertAndStatus cert_and_status;
290 cert_and_status.cert_status = CERT_STATUS_AUTHORITY_INVALID; 291 cert_and_status.cert_status = CERT_STATUS_AUTHORITY_INVALID;
291 cert_and_status.der_cert = cert_der; 292 cert_and_status.der_cert = cert_der;
292 ssl_config.allowed_bad_certs.push_back(cert_and_status); 293 ssl_config.allowed_bad_certs.push_back(cert_and_status);
293 294
294 net::HostPortPair host_and_pair("unittest", 0); 295 net::HostPortPair host_and_pair("unittest", 0);
295 net::SSLClientSocketContext context; 296 net::SSLClientSocketContext context;
296 context.cert_verifier = &cert_verifier_; 297 context.cert_verifier = cert_verifier_.get();
297 client_socket_.reset( 298 client_socket_.reset(
298 socket_factory_->CreateSSLClientSocket( 299 socket_factory_->CreateSSLClientSocket(
299 fake_client_socket, host_and_pair, ssl_config, NULL, context)); 300 fake_client_socket, host_and_pair, ssl_config, NULL, context));
300 server_socket_.reset(net::CreateSSLServerSocket(fake_server_socket, 301 server_socket_.reset(net::CreateSSLServerSocket(fake_server_socket,
301 cert, private_key.get(), 302 cert, private_key.get(),
302 net::SSLConfig())); 303 net::SSLConfig()));
303 } 304 }
304 305
305 FakeDataChannel channel_1_; 306 FakeDataChannel channel_1_;
306 FakeDataChannel channel_2_; 307 FakeDataChannel channel_2_;
307 scoped_ptr<net::SSLClientSocket> client_socket_; 308 scoped_ptr<net::SSLClientSocket> client_socket_;
308 scoped_ptr<net::SSLServerSocket> server_socket_; 309 scoped_ptr<net::SSLServerSocket> server_socket_;
309 net::ClientSocketFactory* socket_factory_; 310 net::ClientSocketFactory* socket_factory_;
310 net::CertVerifier cert_verifier_; 311 scoped_ptr<net::CertVerifier> cert_verifier_;
311 }; 312 };
312 313
313 // SSLServerSocket is only implemented using NSS. 314 // SSLServerSocket is only implemented using NSS.
314 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 315 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
315 316
316 // This test only executes creation of client and server sockets. This is to 317 // This test only executes creation of client and server sockets. This is to
317 // test that creation of sockets doesn't crash and have minimal code to run 318 // test that creation of sockets doesn't crash and have minimal code to run
318 // under valgrind in order to help debugging memory problems. 319 // under valgrind in order to help debugging memory problems.
319 TEST_F(SSLServerSocketTest, Initialize) { 320 TEST_F(SSLServerSocketTest, Initialize) {
320 Initialize(); 321 Initialize();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 unsigned char client_bad[kKeyingMaterialSize]; 472 unsigned char client_bad[kKeyingMaterialSize];
472 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad, 473 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad,
473 false, kKeyingContext, 474 false, kKeyingContext,
474 client_bad, sizeof(client_bad)); 475 client_bad, sizeof(client_bad));
475 ASSERT_EQ(rv, net::OK); 476 ASSERT_EQ(rv, net::OK);
476 EXPECT_TRUE(memcmp(server_out, client_bad, sizeof(server_out)) != 0); 477 EXPECT_TRUE(memcmp(server_out, client_bad, sizeof(server_out)) != 0);
477 } 478 }
478 #endif 479 #endif
479 480
480 } // namespace net 481 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_host_info.h ('k') | net/spdy/spdy_test_util_spdy2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698