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

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

Issue 2000503002: Remove the fingerprint and ca_fingerprint from X509Certificate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_cache
Patch Set: iOS fix Created 4 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_impl.h" 5 #include "chromeos/network/onc/onc_certificate_importer_impl.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>
11 #include <string> 11 #include <string>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/test/test_simple_task_runner.h" 16 #include "base/test/test_simple_task_runner.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chromeos/network/onc/onc_test_utils.h" 19 #include "chromeos/network/onc/onc_test_utils.h"
20 #include "components/onc/onc_constants.h" 20 #include "components/onc/onc_constants.h"
21 #include "crypto/scoped_test_nss_db.h" 21 #include "crypto/scoped_test_nss_db.h"
22 #include "net/base/crypto_module.h" 22 #include "net/base/crypto_module.h"
23 #include "net/base/hash_value.h"
23 #include "net/cert/cert_type.h" 24 #include "net/cert/cert_type.h"
24 #include "net/cert/nss_cert_database_chromeos.h" 25 #include "net/cert/nss_cert_database_chromeos.h"
25 #include "net/cert/x509_certificate.h" 26 #include "net/cert/x509_certificate.h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 28
28 namespace chromeos { 29 namespace chromeos {
29 namespace onc { 30 namespace onc {
30 31
31 namespace { 32 namespace {
32 33
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 net::CertificateList result; 176 net::CertificateList result;
176 CERTCertList* cert_list = PK11_ListCertsInSlot(slot); 177 CERTCertList* cert_list = PK11_ListCertsInSlot(slot);
177 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); 178 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list);
178 !CERT_LIST_END(node, cert_list); 179 !CERT_LIST_END(node, cert_list);
179 node = CERT_LIST_NEXT(node)) { 180 node = CERT_LIST_NEXT(node)) {
180 result.push_back(net::X509Certificate::CreateFromHandle( 181 result.push_back(net::X509Certificate::CreateFromHandle(
181 node->cert, net::X509Certificate::OSCertHandles())); 182 node->cert, net::X509Certificate::OSCertHandles()));
182 } 183 }
183 CERT_DestroyCertList(cert_list); 184 CERT_DestroyCertList(cert_list);
184 185
185 // Sort the result so that test comparisons can be deterministic. 186 std::sort(result.begin(), result.end(),
186 std::sort(result.begin(), result.end(), net::X509Certificate::LessThan()); 187 [](const scoped_refptr<net::X509Certificate>& lhs,
188 const scoped_refptr<net::X509Certificate>& rhs) {
189 return net::SHA256HashValueLessThan()(
190 net::X509Certificate::CalculateFingerprint256(
191 lhs->os_cert_handle()),
192 net::X509Certificate::CalculateFingerprint256(
193 rhs->os_cert_handle()));
194 });
stevenjb 2016/06/16 16:39:23 This seems potentially expensive since we recalcul
Ryan Sleevi 2016/06/16 21:16:45 Right. If it was outside unittests, memoizing the
187 return result; 195 return result;
188 } 196 }
189 }; 197 };
190 198
191 TEST_F(ONCCertificateImporterImplTest, MultipleCertificates) { 199 TEST_F(ONCCertificateImporterImplTest, MultipleCertificates) {
192 AddCertificatesFromFile("managed_toplevel2.onc", true); 200 AddCertificatesFromFile("managed_toplevel2.onc", true);
193 EXPECT_EQ(onc_certificates_->GetSize(), public_list_.size()); 201 EXPECT_EQ(onc_certificates_->GetSize(), public_list_.size());
194 EXPECT_TRUE(private_list_.empty()); 202 EXPECT_TRUE(private_list_.empty());
195 EXPECT_EQ(2ul, public_list_.size()); 203 EXPECT_EQ(2ul, public_list_.size());
196 } 204 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 "certificate-client-update.onc"), 350 "certificate-client-update.onc"),
343 CertParam(net::SERVER_CERT, 351 CertParam(net::SERVER_CERT,
344 "certificate-server.onc", 352 "certificate-server.onc",
345 "certificate-server-update.onc"), 353 "certificate-server-update.onc"),
346 CertParam(net::CA_CERT, 354 CertParam(net::CA_CERT,
347 "certificate-web-authority.onc", 355 "certificate-web-authority.onc",
348 "certificate-web-authority-update.onc"))); 356 "certificate-web-authority-update.onc")));
349 357
350 } // namespace onc 358 } // namespace onc
351 } // namespace chromeos 359 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698