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

Side by Side Diff: net/test/cert_test_util.cc

Issue 2670643008: Move CertVerifyProcMac unit-tests to their own file. (Closed)
Patch Set: Rebase + add missing include Created 3 years, 10 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
« no previous file with comments | « net/test/cert_test_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "net/test/cert_test_util.h" 5 #include "net/test/cert_test_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "net/cert/ev_root_ca_metadata.h" 9 #include "net/cert/ev_root_ca_metadata.h"
10 #include "net/cert/x509_certificate.h" 10 #include "net/cert/x509_certificate.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "net/test/test_data_directory.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 CertificateList CreateCertificateListFromFile( 15 CertificateList CreateCertificateListFromFile(
16 const base::FilePath& certs_dir, 16 const base::FilePath& certs_dir,
17 const std::string& cert_file, 17 const std::string& cert_file,
18 int format) { 18 int format) {
19 base::FilePath cert_path = certs_dir.AppendASCII(cert_file); 19 base::FilePath cert_path = certs_dir.AppendASCII(cert_file);
20 std::string cert_data; 20 std::string cert_data;
21 if (!base::ReadFileToString(cert_path, &cert_data)) 21 if (!base::ReadFileToString(cert_path, &cert_data))
22 return CertificateList(); 22 return CertificateList();
23 return X509Certificate::CreateCertificateListFromBytes(cert_data.data(), 23 return X509Certificate::CreateCertificateListFromBytes(cert_data.data(),
24 cert_data.size(), 24 cert_data.size(),
25 format); 25 format);
26 } 26 }
27 27
28 ::testing::AssertionResult LoadCertificateFiles(
29 const std::vector<std::string>& cert_filenames,
30 CertificateList* certs) {
31 certs->clear();
32 for (const std::string& filename : cert_filenames) {
33 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile(
34 GetTestCertsDirectory(), filename, X509Certificate::FORMAT_AUTO);
35 if (!cert)
36 return ::testing::AssertionFailure()
37 << "Failed loading certificate from file: " << filename
38 << " (in directory: " << GetTestCertsDirectory().value() << ")";
39 certs->push_back(cert);
40 }
41
42 return ::testing::AssertionSuccess();
43 }
44
28 scoped_refptr<X509Certificate> CreateCertificateChainFromFile( 45 scoped_refptr<X509Certificate> CreateCertificateChainFromFile(
29 const base::FilePath& certs_dir, 46 const base::FilePath& certs_dir,
30 const std::string& cert_file, 47 const std::string& cert_file,
31 int format) { 48 int format) {
32 CertificateList certs = CreateCertificateListFromFile( 49 CertificateList certs = CreateCertificateListFromFile(
33 certs_dir, cert_file, format); 50 certs_dir, cert_file, format);
34 if (certs.empty()) 51 if (certs.empty())
35 return NULL; 52 return NULL;
36 53
37 X509Certificate::OSCertHandles intermediates; 54 X509Certificate::OSCertHandles intermediates;
(...skipping 27 matching lines...) Expand all
65 : fingerprint_(fingerprint), 82 : fingerprint_(fingerprint),
66 ev_root_ca_metadata_(ev_root_ca_metadata) { 83 ev_root_ca_metadata_(ev_root_ca_metadata) {
67 EXPECT_TRUE(ev_root_ca_metadata->AddEVCA(fingerprint, policy)); 84 EXPECT_TRUE(ev_root_ca_metadata->AddEVCA(fingerprint, policy));
68 } 85 }
69 86
70 ScopedTestEVPolicy::~ScopedTestEVPolicy() { 87 ScopedTestEVPolicy::~ScopedTestEVPolicy() {
71 EXPECT_TRUE(ev_root_ca_metadata_->RemoveEVCA(fingerprint_)); 88 EXPECT_TRUE(ev_root_ca_metadata_->RemoveEVCA(fingerprint_));
72 } 89 }
73 90
74 } // namespace net 91 } // namespace net
OLDNEW
« no previous file with comments | « net/test/cert_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698