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 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // NetworkLibraryStubImpl. | 131 // NetworkLibraryStubImpl. |
132 // NOTE: It would be of little value to test stub functions that simply return | 132 // NOTE: It would be of little value to test stub functions that simply return |
133 // predefined values, e.g. ethernet_available(). However, many other functions | 133 // predefined values, e.g. ethernet_available(). However, many other functions |
134 // such as connected_network() return values which are set indirectly and thus | 134 // such as connected_network() return values which are set indirectly and thus |
135 // we can test the logic of those setters. | 135 // we can test the logic of those setters. |
136 | 136 |
137 class NetworkLibraryStubTest : public testing::Test { | 137 class NetworkLibraryStubTest : public testing::Test { |
138 public: | 138 public: |
139 NetworkLibraryStubTest() : cros_(NULL) {} | 139 NetworkLibraryStubTest() : cros_(NULL) {} |
140 | 140 |
| 141 static void SetUpTestCase() { |
| 142 // Ideally, we'd open a test DB for each test case, and close it |
| 143 // again, removing the temp dir, but unfortunately, there's a |
| 144 // bug in NSS that prevents this from working, so we just open |
| 145 // it once, and empty it for each test case. Here's the bug: |
| 146 // https://bugzilla.mozilla.org/show_bug.cgi?id=588269 |
| 147 ASSERT_TRUE(crypto::OpenTestNSSDB()); |
| 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 |
| 150 // tests, due to https://bugzilla.mozilla.org/show_bug.cgi?id=588269 |
| 151 } |
| 152 |
141 protected: | 153 protected: |
142 virtual void SetUp() { | 154 virtual void SetUp() { |
143 ASSERT_TRUE(test_nssdb_.is_open()); | |
144 | |
145 slot_ = net::NSSCertDatabase::GetInstance()->GetPublicModule(); | 155 slot_ = net::NSSCertDatabase::GetInstance()->GetPublicModule(); |
146 cros_ = CrosLibrary::Get()->GetNetworkLibrary(); | 156 cros_ = CrosLibrary::Get()->GetNetworkLibrary(); |
147 ASSERT_TRUE(cros_) << "GetNetworkLibrary() Failed!"; | 157 ASSERT_TRUE(cros_) << "GetNetworkLibrary() Failed!"; |
148 | 158 |
149 // Test db should be empty at start of test. | 159 // Test db should be empty at start of test. |
150 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); | 160 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); |
151 } | 161 } |
152 virtual void TearDown() { | 162 virtual void TearDown() { |
153 cros_ = NULL; | 163 cros_ = NULL; |
154 EXPECT_TRUE(CleanupSlotContents(slot_->os_module_handle())); | 164 EXPECT_TRUE(CleanupSlotContents(slot_->os_module_handle())); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 bool ok = true; | 200 bool ok = true; |
191 net::CertificateList certs = ListCertsInSlot(slot); | 201 net::CertificateList certs = ListCertsInSlot(slot); |
192 for (size_t i = 0; i < certs.size(); ++i) { | 202 for (size_t i = 0; i < certs.size(); ++i) { |
193 if (!net::NSSCertDatabase::GetInstance()->DeleteCertAndKey(certs[i])) | 203 if (!net::NSSCertDatabase::GetInstance()->DeleteCertAndKey(certs[i])) |
194 ok = false; | 204 ok = false; |
195 } | 205 } |
196 return ok; | 206 return ok; |
197 } | 207 } |
198 | 208 |
199 scoped_refptr<net::CryptoModule> slot_; | 209 scoped_refptr<net::CryptoModule> slot_; |
200 crypto::ScopedTestNSSDB test_nssdb_; | |
201 }; | 210 }; |
202 | 211 |
203 // Default stub state: | 212 // Default stub state: |
204 // vpn1: disconnected, L2TP/IPsec + PSK | 213 // vpn1: disconnected, L2TP/IPsec + PSK |
205 // vpn2: disconnected, L2TP/IPsec + user cert | 214 // vpn2: disconnected, L2TP/IPsec + user cert |
206 // vpn3: disconnected, OpenVpn | 215 // vpn3: disconnected, OpenVpn |
207 // eth1: connected (active network) | 216 // eth1: connected (active network) |
208 // wifi1: connected | 217 // wifi1: connected |
209 // wifi2: disconnected | 218 // wifi2: disconnected |
210 // wifi3: disconnected, WEP | 219 // wifi3: disconnected, WEP |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 370 |
362 // TODO(stevenjb): Test network profiles. | 371 // TODO(stevenjb): Test network profiles. |
363 | 372 |
364 // TODO(stevenjb): Test network devices. | 373 // TODO(stevenjb): Test network devices. |
365 | 374 |
366 // TODO(stevenjb): Test data plans. | 375 // TODO(stevenjb): Test data plans. |
367 | 376 |
368 // TODO(stevenjb): Test monitor network / device. | 377 // TODO(stevenjb): Test monitor network / device. |
369 | 378 |
370 } // namespace chromeos | 379 } // namespace chromeos |
OLD | NEW |