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

Side by Side Diff: chromeos/network/onc/onc_certificate_importer_unittest.cc

Issue 13473003: Rename ONC field Trust to TrustBits. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated test. Created 7 years, 8 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 "chromeos/network/onc/onc_certificate_importer.h" 5 #include "chromeos/network/onc/onc_certificate_importer.h"
6 6
7 #include <cert.h> 7 #include <cert.h>
8 #include <certdb.h> 8 #include <certdb.h>
9 #include <keyhi.h> 9 #include <keyhi.h>
10 #include <pk11pub.h> 10 #include <pk11pub.h>
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 187
188 SECKEYPrivateKeyList* privkey_list = 188 SECKEYPrivateKeyList* privkey_list =
189 PK11_ListPrivKeysInSlot(slot_->os_module_handle(), NULL, NULL); 189 PK11_ListPrivKeysInSlot(slot_->os_module_handle(), NULL, NULL);
190 EXPECT_FALSE(privkey_list); 190 EXPECT_FALSE(privkey_list);
191 191
192 SECKEYPublicKeyList* pubkey_list = 192 SECKEYPublicKeyList* pubkey_list =
193 PK11_ListPublicKeysInSlot(slot_->os_module_handle(), NULL); 193 PK11_ListPublicKeysInSlot(slot_->os_module_handle(), NULL);
194 EXPECT_FALSE(pubkey_list); 194 EXPECT_FALSE(pubkey_list);
195 } 195 }
196 196
197 struct CertParam {
198 CertParam(net::CertType certificate_type,
199 const char* original_filename,
200 const char* update_filename)
201 : cert_type(certificate_type),
202 original_file(original_filename),
203 update_file(update_filename) {}
204
205 net::CertType cert_type;
206 const char* original_file;
207 const char* update_file;
208 };
209
197 class ONCCertificateImporterTestWithParam : 210 class ONCCertificateImporterTestWithParam :
198 public ONCCertificateImporterTest, 211 public ONCCertificateImporterTest,
199 public testing::WithParamInterface< 212 public testing::WithParamInterface<CertParam> {
200 std::pair<net::CertType, std::pair<const char*, const char*> > > {
201 protected:
202 net::CertType GetCertTypeParam() {
203 return GetParam().first;
204 }
205
206 std::string GetOriginalFilename() {
207 return GetParam().second.first;
208 }
209
210 std::string GetUpdatedFilename() {
211 return GetParam().second.second;
212 }
213 }; 213 };
214 214
215 TEST_P(ONCCertificateImporterTestWithParam, UpdateCertificate) { 215 TEST_P(ONCCertificateImporterTestWithParam, UpdateCertificate) {
216 // First we import a certificate. 216 // First we import a certificate.
217 { 217 {
218 SCOPED_TRACE("Import original certificate"); 218 SCOPED_TRACE("Import original certificate");
219 std::string guid_original; 219 std::string guid_original;
220 AddCertificateFromFile(GetOriginalFilename(), GetCertTypeParam(), 220 AddCertificateFromFile(GetParam().original_file, GetParam().cert_type,
221 &guid_original); 221 &guid_original);
222 } 222 }
223 223
224 // Now we import the same certificate with a different GUID. The cert should 224 // Now we import the same certificate with a different GUID. The cert should
225 // be retrievable via the new GUID. 225 // be retrievable via the new GUID.
226 { 226 {
227 SCOPED_TRACE("Import updated certificate"); 227 SCOPED_TRACE("Import updated certificate");
228 std::string guid_updated; 228 std::string guid_updated;
229 AddCertificateFromFile(GetUpdatedFilename(), GetCertTypeParam(), 229 AddCertificateFromFile(GetParam().update_file, GetParam().cert_type,
230 &guid_updated); 230 &guid_updated);
231 } 231 }
232 } 232 }
233 233
234 TEST_P(ONCCertificateImporterTestWithParam, ReimportCertificate) { 234 TEST_P(ONCCertificateImporterTestWithParam, ReimportCertificate) {
235 // Verify that reimporting a client certificate works. 235 // Verify that reimporting a client certificate works.
236 for (int i = 0; i < 2; ++i) { 236 for (int i = 0; i < 2; ++i) {
237 SCOPED_TRACE("Import certificate, iteration " + base::IntToString(i)); 237 SCOPED_TRACE("Import certificate, iteration " + base::IntToString(i));
238 238
239 std::string guid_original; 239 std::string guid_original;
240 AddCertificateFromFile(GetOriginalFilename(), GetCertTypeParam(), 240 AddCertificateFromFile(GetParam().original_file, GetParam().cert_type,
241 &guid_original); 241 &guid_original);
242 } 242 }
243 } 243 }
244 244
245 INSTANTIATE_TEST_CASE_P( 245 INSTANTIATE_TEST_CASE_P(
246 ONCCertificateImporterTestWithParam, 246 ONCCertificateImporterTestWithParam,
247 ONCCertificateImporterTestWithParam, 247 ONCCertificateImporterTestWithParam,
248 ::testing::Values( 248 ::testing::Values(
249 std::make_pair(net::USER_CERT, 249 CertParam(net::USER_CERT,
250 std::make_pair("certificate-client.onc", 250 "certificate-client.onc",
251 "certificate-client-update.onc")), 251 "certificate-client-update.onc"),
252 std::make_pair(net::SERVER_CERT, 252 CertParam(net::SERVER_CERT,
253 std::make_pair("certificate-server.onc", 253 "certificate-server.onc",
254 "certificate-server-update.onc")), 254 "certificate-server-update.onc"),
255 std::make_pair( 255 CertParam(net::CA_CERT,
256 net::CA_CERT, 256 "certificate-web-authority.onc",
257 std::make_pair("certificate-web-authority.onc", 257 "certificate-web-authority-update.onc")));
258 "certificate-web-authority-update.onc"))));
259 258
260 } // namespace onc 259 } // namespace onc
261 } // namespace chromeos 260 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698