OLD | NEW |
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 "chromeos/network/network_connection_handler.h" | 5 #include "chromeos/network/network_connection_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 223 |
224 std::string pkcs12_data; | 224 std::string pkcs12_data; |
225 base::FilePath pkcs12_path = | 225 base::FilePath pkcs12_path = |
226 net::GetTestCertsDirectory().Append("websocket_client_cert.p12"); | 226 net::GetTestCertsDirectory().Append("websocket_client_cert.p12"); |
227 if (!base::ReadFileToString(pkcs12_path, &pkcs12_data)) | 227 if (!base::ReadFileToString(pkcs12_path, &pkcs12_data)) |
228 return NULL; | 228 return NULL; |
229 | 229 |
230 net::CertificateList loaded_certs; | 230 net::CertificateList loaded_certs; |
231 scoped_refptr<net::CryptoModule> module(net::CryptoModule::CreateFromHandle( | 231 scoped_refptr<net::CryptoModule> module(net::CryptoModule::CreateFromHandle( |
232 test_nssdb_->GetPrivateSlot().get())); | 232 test_nssdb_->GetPrivateSlot().get())); |
233 if (test_nssdb_->ImportFromPKCS12( | 233 if (test_nssdb_->ImportFromPKCS12(module.get(), |
234 module, pkcs12_data, base::string16(), false, &loaded_certs) != | 234 pkcs12_data, |
235 net::OK) { | 235 base::string16(), |
| 236 false, |
| 237 &loaded_certs) != net::OK) { |
236 LOG(ERROR) << "Error while importing to NSSDB."; | 238 LOG(ERROR) << "Error while importing to NSSDB."; |
237 return NULL; | 239 return NULL; |
238 } | 240 } |
239 | 241 |
240 // File contains two certs, the client cert first and the CA cert second. | 242 // File contains two certs, the client cert first and the CA cert second. |
241 if (loaded_certs.size() != 2U) { | 243 if (loaded_certs.size() != 2U) { |
242 LOG(ERROR) << "Expected two certs in file, found " << loaded_certs.size(); | 244 LOG(ERROR) << "Expected two certs in file, found " << loaded_certs.size(); |
243 return NULL; | 245 return NULL; |
244 } | 246 } |
245 return loaded_certs[0]; | 247 return loaded_certs[0]; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 true); // load as user policy | 366 true); // load as user policy |
365 | 367 |
366 Connect("wifi4"); | 368 Connect("wifi4"); |
367 EXPECT_EQ(NetworkConnectionHandler::kErrorCertificateRequired, | 369 EXPECT_EQ(NetworkConnectionHandler::kErrorCertificateRequired, |
368 GetResultAndReset()); | 370 GetResultAndReset()); |
369 } | 371 } |
370 | 372 |
371 TEST_F(NetworkConnectionHandlerTest, ConnectWithCertificateSuccess) { | 373 TEST_F(NetworkConnectionHandlerTest, ConnectWithCertificateSuccess) { |
372 StartCertLoader(); | 374 StartCertLoader(); |
373 scoped_refptr<net::X509Certificate> cert = ImportTestClientCert(); | 375 scoped_refptr<net::X509Certificate> cert = ImportTestClientCert(); |
374 ASSERT_TRUE(cert); | 376 ASSERT_TRUE(cert.get()); |
375 | 377 |
376 SetupPolicy(base::StringPrintf(kPolicyWithCertPatternTemplate, | 378 SetupPolicy(base::StringPrintf(kPolicyWithCertPatternTemplate, |
377 cert->subject().common_name.c_str()), | 379 cert->subject().common_name.c_str()), |
378 base::DictionaryValue(), // no global config | 380 base::DictionaryValue(), // no global config |
379 true); // load as user policy | 381 true); // load as user policy |
380 | 382 |
381 Connect("wifi4"); | 383 Connect("wifi4"); |
382 EXPECT_EQ(kSuccessResult, GetResultAndReset()); | 384 EXPECT_EQ(kSuccessResult, GetResultAndReset()); |
383 } | 385 } |
384 | 386 |
385 // Disabled, see http://crbug.com/396729. | 387 // Disabled, see http://crbug.com/396729. |
386 TEST_F(NetworkConnectionHandlerTest, | 388 TEST_F(NetworkConnectionHandlerTest, |
387 DISABLED_ConnectWithCertificateRequestedBeforeCertsAreLoaded) { | 389 DISABLED_ConnectWithCertificateRequestedBeforeCertsAreLoaded) { |
388 scoped_refptr<net::X509Certificate> cert = ImportTestClientCert(); | 390 scoped_refptr<net::X509Certificate> cert = ImportTestClientCert(); |
389 ASSERT_TRUE(cert); | 391 ASSERT_TRUE(cert.get()); |
390 | 392 |
391 SetupPolicy(base::StringPrintf(kPolicyWithCertPatternTemplate, | 393 SetupPolicy(base::StringPrintf(kPolicyWithCertPatternTemplate, |
392 cert->subject().common_name.c_str()), | 394 cert->subject().common_name.c_str()), |
393 base::DictionaryValue(), // no global config | 395 base::DictionaryValue(), // no global config |
394 true); // load as user policy | 396 true); // load as user policy |
395 | 397 |
396 Connect("wifi4"); | 398 Connect("wifi4"); |
397 | 399 |
398 // Connect request came before the cert loader loaded certificates, so the | 400 // Connect request came before the cert loader loaded certificates, so the |
399 // connect request should have been throttled until the certificates are | 401 // connect request should have been throttled until the certificates are |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 true); | 504 true); |
503 | 505 |
504 SetupPolicy(kPolicy, global_config, false /* load as device policy */); | 506 SetupPolicy(kPolicy, global_config, false /* load as device policy */); |
505 EXPECT_EQ(shill::kStateIdle, | 507 EXPECT_EQ(shill::kStateIdle, |
506 GetServiceStringProperty("wifi0", shill::kStateProperty)); | 508 GetServiceStringProperty("wifi0", shill::kStateProperty)); |
507 EXPECT_EQ(shill::kStateOnline, | 509 EXPECT_EQ(shill::kStateOnline, |
508 GetServiceStringProperty("wifi1", shill::kStateProperty)); | 510 GetServiceStringProperty("wifi1", shill::kStateProperty)); |
509 } | 511 } |
510 | 512 |
511 } // namespace chromeos | 513 } // namespace chromeos |
OLD | NEW |