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

Side by Side Diff: chrome/browser/chromeos/cros/onc_network_parser_unittest.cc

Issue 10916094: Move the NSS functions out of CertDatabase into a new NSSCertDatabase class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 3 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) 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 "chrome/browser/chromeos/cros/onc_network_parser.h" 5 #include "chrome/browser/chromeos/cros/onc_network_parser.h"
6 6
7 #include <cert.h> 7 #include <cert.h>
8 #include <keyhi.h> 8 #include <keyhi.h>
9 #include <pk11pub.h> 9 #include <pk11pub.h>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/chromeos/cros/network_library.h" 21 #include "chrome/browser/chromeos/cros/network_library.h"
22 #include "chrome/browser/chromeos/login/mock_user_manager.h" 22 #include "chrome/browser/chromeos/login/mock_user_manager.h"
23 #include "chrome/browser/net/pref_proxy_config_tracker_impl.h" 23 #include "chrome/browser/net/pref_proxy_config_tracker_impl.h"
24 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/net/x509_certificate_model.h" 25 #include "chrome/common/net/x509_certificate_model.h"
26 #include "chrome/test/base/testing_browser_process.h" 26 #include "chrome/test/base/testing_browser_process.h"
27 #include "chrome/test/base/testing_pref_service.h" 27 #include "chrome/test/base/testing_pref_service.h"
28 #include "chromeos/dbus/dbus_thread_manager.h" 28 #include "chromeos/dbus/dbus_thread_manager.h"
29 #include "content/public/test/test_browser_thread.h" 29 #include "content/public/test/test_browser_thread.h"
30 #include "crypto/nss_util.h" 30 #include "crypto/nss_util.h"
31 #include "net/base/cert_database.h"
32 #include "net/base/cert_type.h" 31 #include "net/base/cert_type.h"
33 #include "net/base/crypto_module.h" 32 #include "net/base/crypto_module.h"
33 #include "net/base/nss_cert_database.h"
34 #include "net/base/x509_certificate.h" 34 #include "net/base/x509_certificate.h"
35 #include "net/proxy/proxy_config.h" 35 #include "net/proxy/proxy_config.h"
36 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
37 #include "third_party/cros_system_api/dbus/service_constants.h" 37 #include "third_party/cros_system_api/dbus/service_constants.h"
38 38
39 using ::testing::AnyNumber; 39 using ::testing::AnyNumber;
40 using ::testing::Return; 40 using ::testing::Return;
41 41
42 namespace chromeos { 42 namespace chromeos {
43 43
(...skipping 16 matching lines...) Expand all
60 // bug in NSS that prevents this from working, so we just open 60 // bug in NSS that prevents this from working, so we just open
61 // it once, and empty it for each test case. Here's the bug: 61 // it once, and empty it for each test case. Here's the bug:
62 // https://bugzilla.mozilla.org/show_bug.cgi?id=588269 62 // https://bugzilla.mozilla.org/show_bug.cgi?id=588269
63 ASSERT_TRUE(crypto::OpenTestNSSDB()); 63 ASSERT_TRUE(crypto::OpenTestNSSDB());
64 // There is no matching TearDownTestCase call to close the test NSS DB 64 // There is no matching TearDownTestCase call to close the test NSS DB
65 // because that would leave NSS in a potentially broken state for further 65 // because that would leave NSS in a potentially broken state for further
66 // tests, due to https://bugzilla.mozilla.org/show_bug.cgi?id=588269 66 // tests, due to https://bugzilla.mozilla.org/show_bug.cgi?id=588269
67 } 67 }
68 68
69 virtual void SetUp() { 69 virtual void SetUp() {
70 slot_ = cert_db_.GetPublicModule(); 70 slot_ = net::NSSCertDatabase::GetInstance()->GetPublicModule();
71 71
72 // Don't run the test if the setup failed. 72 // Don't run the test if the setup failed.
73 ASSERT_TRUE(slot_->os_module_handle()); 73 ASSERT_TRUE(slot_->os_module_handle());
74 74
75 // Test db should be empty at start of test. 75 // Test db should be empty at start of test.
76 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); 76 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size());
77 } 77 }
78 78
79 virtual void TearDown() { 79 virtual void TearDown() {
80 EXPECT_TRUE(CleanupSlotContents(slot_->os_module_handle())); 80 EXPECT_TRUE(CleanupSlotContents(slot_->os_module_handle()));
(...skipping 20 matching lines...) Expand all
101 const char* expected); 101 const char* expected);
102 void CheckBooleanProperty(const Network* network, 102 void CheckBooleanProperty(const Network* network,
103 PropertyIndex index, 103 PropertyIndex index,
104 bool expected); 104 bool expected);
105 105
106 void TestProxySettings(const std::string proxy_settings_blob, 106 void TestProxySettings(const std::string proxy_settings_blob,
107 net::ProxyConfig* net_config); 107 net::ProxyConfig* net_config);
108 108
109 protected: 109 protected:
110 scoped_refptr<net::CryptoModule> slot_; 110 scoped_refptr<net::CryptoModule> slot_;
111 net::CertDatabase cert_db_;
112 111
113 private: 112 private:
114 net::CertificateList ListCertsInSlot(PK11SlotInfo* slot) { 113 net::CertificateList ListCertsInSlot(PK11SlotInfo* slot) {
115 net::CertificateList result; 114 net::CertificateList result;
116 CERTCertList* cert_list = PK11_ListCertsInSlot(slot); 115 CERTCertList* cert_list = PK11_ListCertsInSlot(slot);
117 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); 116 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list);
118 !CERT_LIST_END(node, cert_list); 117 !CERT_LIST_END(node, cert_list);
119 node = CERT_LIST_NEXT(node)) { 118 node = CERT_LIST_NEXT(node)) {
120 result.push_back(net::X509Certificate::CreateFromHandle( 119 result.push_back(net::X509Certificate::CreateFromHandle(
121 node->cert, net::X509Certificate::OSCertHandles())); 120 node->cert, net::X509Certificate::OSCertHandles()));
122 } 121 }
123 CERT_DestroyCertList(cert_list); 122 CERT_DestroyCertList(cert_list);
124 123
125 // Sort the result so that test comparisons can be deterministic. 124 // Sort the result so that test comparisons can be deterministic.
126 std::sort(result.begin(), result.end(), net::X509Certificate::LessThan()); 125 std::sort(result.begin(), result.end(), net::X509Certificate::LessThan());
127 return result; 126 return result;
128 } 127 }
129 128
130 bool CleanupSlotContents(PK11SlotInfo* slot) { 129 bool CleanupSlotContents(PK11SlotInfo* slot) {
131 bool ok = true; 130 bool ok = true;
132 net::CertificateList certs = ListCertsInSlot(slot); 131 net::CertificateList certs = ListCertsInSlot(slot);
133 for (size_t i = 0; i < certs.size(); ++i) { 132 for (size_t i = 0; i < certs.size(); ++i) {
134 if (!cert_db_.DeleteCertAndKey(certs[i])) 133 if (!net::NSSCertDatabase::GetInstance()->DeleteCertAndKey(certs[i]))
135 ok = false; 134 ok = false;
136 } 135 }
137 return ok; 136 return ok;
138 } 137 }
139 138
140 ScopedStubCrosEnabler stub_cros_enabler_; 139 ScopedStubCrosEnabler stub_cros_enabler_;
141 }; 140 };
142 141
143 const base::Value* OncNetworkParserTest::GetExpectedProperty( 142 const base::Value* OncNetworkParserTest::GetExpectedProperty(
144 const Network* network, 143 const Network* network,
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 EXPECT_EQ(1, parser.GetNetworkConfigsSize()); 947 EXPECT_EQ(1, parser.GetNetworkConfigsSize());
949 EXPECT_EQ(0, parser.GetCertificatesSize()); 948 EXPECT_EQ(0, parser.GetCertificatesSize());
950 bool marked_for_removal = false; 949 bool marked_for_removal = false;
951 scoped_ptr<Network> network(parser.ParseNetwork(0, &marked_for_removal)); 950 scoped_ptr<Network> network(parser.ParseNetwork(0, &marked_for_removal));
952 951
953 EXPECT_TRUE(marked_for_removal); 952 EXPECT_TRUE(marked_for_removal);
954 EXPECT_EQ("{485d6076-dd44-6b6d-69787465725f5045}", network->unique_id()); 953 EXPECT_EQ("{485d6076-dd44-6b6d-69787465725f5045}", network->unique_id());
955 } 954 }
956 955
957 } // namespace chromeos 956 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698