| 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 <cert.h> | 5 #include <cert.h> |
| 6 #include <pk11pub.h> | 6 #include <pk11pub.h> |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/scoped_temp_dir.h" | 16 #include "base/scoped_temp_dir.h" |
| 17 #include "chrome/browser/chromeos/cros/cros_library.h" | 17 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 18 #include "chrome/browser/chromeos/cros/network_library.h" | 18 #include "chrome/browser/chromeos/cros/network_library.h" |
| 19 #include "chrome/browser/chromeos/cros/onc_network_parser.h" | 19 #include "chrome/browser/chromeos/cros/onc_network_parser.h" |
| 20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 21 #include "crypto/nss_util.h" | 21 #include "crypto/nss_util.h" |
| 22 #include "net/base/cert_database.h" | |
| 23 #include "net/base/crypto_module.h" | 22 #include "net/base/crypto_module.h" |
| 23 #include "net/base/nss_cert_database.h" |
| 24 #include "net/base/x509_certificate.h" | 24 #include "net/base/x509_certificate.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 27 |
| 28 using ::testing::Return; | 28 using ::testing::Return; |
| 29 | 29 |
| 30 namespace chromeos { | 30 namespace chromeos { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // it once, and empty it for each test case. Here's the bug: | 145 // it once, and empty it for each test case. Here's the bug: |
| 146 // https://bugzilla.mozilla.org/show_bug.cgi?id=588269 | 146 // https://bugzilla.mozilla.org/show_bug.cgi?id=588269 |
| 147 ASSERT_TRUE(crypto::OpenTestNSSDB()); | 147 ASSERT_TRUE(crypto::OpenTestNSSDB()); |
| 148 // There is no matching TearDownTestCase call to close the test NSS DB | 148 // There is no matching TearDownTestCase call to close the test NSS DB |
| 149 // because that would leave NSS in a potentially broken state for further | 149 // because that would leave NSS in a potentially broken state for further |
| 150 // tests, due to https://bugzilla.mozilla.org/show_bug.cgi?id=588269 | 150 // tests, due to https://bugzilla.mozilla.org/show_bug.cgi?id=588269 |
| 151 } | 151 } |
| 152 | 152 |
| 153 protected: | 153 protected: |
| 154 virtual void SetUp() { | 154 virtual void SetUp() { |
| 155 slot_ = cert_db_.GetPublicModule(); | 155 slot_ = net::NSSCertDatabase::GetInstance()->GetPublicModule(); |
| 156 cros_ = CrosLibrary::Get()->GetNetworkLibrary(); | 156 cros_ = CrosLibrary::Get()->GetNetworkLibrary(); |
| 157 ASSERT_TRUE(cros_) << "GetNetworkLibrary() Failed!"; | 157 ASSERT_TRUE(cros_) << "GetNetworkLibrary() Failed!"; |
| 158 | 158 |
| 159 // Test db should be empty at start of test. | 159 // Test db should be empty at start of test. |
| 160 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); | 160 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); |
| 161 } | 161 } |
| 162 virtual void TearDown() { | 162 virtual void TearDown() { |
| 163 cros_ = NULL; | 163 cros_ = NULL; |
| 164 EXPECT_TRUE(CleanupSlotContents(slot_->os_module_handle())); | 164 EXPECT_TRUE(CleanupSlotContents(slot_->os_module_handle())); |
| 165 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); | 165 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 193 | 193 |
| 194 // Sort the result so that test comparisons can be deterministic. | 194 // Sort the result so that test comparisons can be deterministic. |
| 195 std::sort(result.begin(), result.end(), net::X509Certificate::LessThan()); | 195 std::sort(result.begin(), result.end(), net::X509Certificate::LessThan()); |
| 196 return result; | 196 return result; |
| 197 } | 197 } |
| 198 | 198 |
| 199 bool CleanupSlotContents(PK11SlotInfo* slot) { | 199 bool CleanupSlotContents(PK11SlotInfo* slot) { |
| 200 bool ok = true; | 200 bool ok = true; |
| 201 net::CertificateList certs = ListCertsInSlot(slot); | 201 net::CertificateList certs = ListCertsInSlot(slot); |
| 202 for (size_t i = 0; i < certs.size(); ++i) { | 202 for (size_t i = 0; i < certs.size(); ++i) { |
| 203 if (!cert_db_.DeleteCertAndKey(certs[i])) | 203 if (!net::NSSCertDatabase::GetInstance()->DeleteCertAndKey(certs[i])) |
| 204 ok = false; | 204 ok = false; |
| 205 } | 205 } |
| 206 return ok; | 206 return ok; |
| 207 } | 207 } |
| 208 | 208 |
| 209 net::CertDatabase cert_db_; | |
| 210 scoped_refptr<net::CryptoModule> slot_; | 209 scoped_refptr<net::CryptoModule> slot_; |
| 211 }; | 210 }; |
| 212 | 211 |
| 213 // Default stub state: | 212 // Default stub state: |
| 214 // vpn1: disconnected, L2TP/IPsec + PSK | 213 // vpn1: disconnected, L2TP/IPsec + PSK |
| 215 // vpn2: disconnected, L2TP/IPsec + user cert | 214 // vpn2: disconnected, L2TP/IPsec + user cert |
| 216 // vpn3: disconnected, OpenVpn | 215 // vpn3: disconnected, OpenVpn |
| 217 // eth1: connected (active network) | 216 // eth1: connected (active network) |
| 218 // wifi1: connected | 217 // wifi1: connected |
| 219 // wifi2: disconnected | 218 // wifi2: disconnected |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 370 |
| 372 // TODO(stevenjb): Test network profiles. | 371 // TODO(stevenjb): Test network profiles. |
| 373 | 372 |
| 374 // TODO(stevenjb): Test network devices. | 373 // TODO(stevenjb): Test network devices. |
| 375 | 374 |
| 376 // TODO(stevenjb): Test data plans. | 375 // TODO(stevenjb): Test data plans. |
| 377 | 376 |
| 378 // TODO(stevenjb): Test monitor network / device. | 377 // TODO(stevenjb): Test monitor network / device. |
| 379 | 378 |
| 380 } // namespace chromeos | 379 } // namespace chromeos |
| OLD | NEW |