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

Side by Side Diff: net/cert/internal/test_helpers.cc

Issue 2346663002: Generalize rebase-errors.py so it works for other files. (Closed)
Patch Set: moar comment wording Created 4 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
« no previous file with comments | « net/cert/internal/test_helpers.h ('k') | net/cert/internal/trust_store_collection_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/cert/internal/test_helpers.h" 5 #include "net/cert/internal/test_helpers.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/base_paths.h" 8 #include "base/base_paths.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 for (const auto& mapping : mappings_copy) { 94 for (const auto& mapping : mappings_copy) {
95 if (mapping.value && !mapping.optional) { 95 if (mapping.value && !mapping.optional) {
96 return ::testing::AssertionFailure() << "PEM block missing: " 96 return ::testing::AssertionFailure() << "PEM block missing: "
97 << mapping.block_name; 97 << mapping.block_name;
98 } 98 }
99 } 99 }
100 100
101 return ::testing::AssertionSuccess(); 101 return ::testing::AssertionSuccess();
102 } 102 }
103 103
104 void ReadVerifyCertChainTestFromFile(const std::string& file_name, 104 void ReadVerifyCertChainTestFromFile(const std::string& file_path_ascii,
105 ParsedCertificateList* chain, 105 ParsedCertificateList* chain,
106 scoped_refptr<TrustAnchor>* trust_anchor, 106 scoped_refptr<TrustAnchor>* trust_anchor,
107 der::GeneralizedTime* time, 107 der::GeneralizedTime* time,
108 bool* verify_result, 108 bool* verify_result,
109 std::string* expected_errors) { 109 std::string* expected_errors) {
110 chain->clear(); 110 chain->clear();
111 *trust_anchor = nullptr; 111 *trust_anchor = nullptr;
112 expected_errors->clear(); 112 expected_errors->clear();
113 113
114 std::string file_data = ReadTestFileToString( 114 std::string file_data = ReadTestFileToString(file_path_ascii);
115 std::string("net/data/verify_certificate_chain_unittest/") + file_name);
116 115
117 std::vector<std::string> pem_headers; 116 std::vector<std::string> pem_headers;
118 117
119 // For details on the file format refer to: 118 // For details on the file format refer to:
120 // net/data/verify_certificate_chain_unittest/README. 119 // net/data/verify_certificate_chain_unittest/README.
121 const char kCertificateHeader[] = "CERTIFICATE"; 120 const char kCertificateHeader[] = "CERTIFICATE";
122 const char kTrustAnchorUnconstrained[] = "TRUST_ANCHOR_UNCONSTRAINED"; 121 const char kTrustAnchorUnconstrained[] = "TRUST_ANCHOR_UNCONSTRAINED";
123 const char kTrustAnchorConstrained[] = "TRUST_ANCHOR_CONSTRAINED"; 122 const char kTrustAnchorConstrained[] = "TRUST_ANCHOR_CONSTRAINED";
124 const char kTimeHeader[] = "TIME"; 123 const char kTimeHeader[] = "TIME";
125 const char kResultHeader[] = "VERIFY_RESULT"; 124 const char kResultHeader[] = "VERIFY_RESULT";
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 has_errors = true; 172 has_errors = true;
174 *expected_errors = block_data; 173 *expected_errors = block_data;
175 } 174 }
176 } 175 }
177 176
178 ASSERT_TRUE(has_time); 177 ASSERT_TRUE(has_time);
179 ASSERT_TRUE(has_result); 178 ASSERT_TRUE(has_result);
180 ASSERT_TRUE(*trust_anchor); 179 ASSERT_TRUE(*trust_anchor);
181 } 180 }
182 181
183 std::string ReadTestFileToString(const std::string& file_name) { 182 std::string ReadTestFileToString(const std::string& file_path_ascii) {
184 // Compute the full path, relative to the src/ directory. 183 // Compute the full path, relative to the src/ directory.
185 base::FilePath src_root; 184 base::FilePath src_root;
186 PathService::Get(base::DIR_SOURCE_ROOT, &src_root); 185 PathService::Get(base::DIR_SOURCE_ROOT, &src_root);
187 base::FilePath filepath = src_root.AppendASCII(file_name); 186 base::FilePath filepath = src_root.AppendASCII(file_path_ascii);
188 187
189 // Read the full contents of the file. 188 // Read the full contents of the file.
190 std::string file_data; 189 std::string file_data;
191 if (!base::ReadFileToString(filepath, &file_data)) { 190 if (!base::ReadFileToString(filepath, &file_data)) {
192 ADD_FAILURE() << "Couldn't read file: " << filepath.value(); 191 ADD_FAILURE() << "Couldn't read file: " << filepath.value();
193 return std::string(); 192 return std::string();
194 } 193 }
195 194
196 return file_data; 195 return file_data;
197 } 196 }
198 197
199 } // namespace net 198 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/internal/test_helpers.h ('k') | net/cert/internal/trust_store_collection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698