Commit 00dba514 authored by eroman's avatar eroman Committed by Commit bot

Introduce CertErrors::ToDebugString().

This removes some duplicated code.

BUG=634443

Review-Url: https://codereview.chromium.org/2326923002
Cr-Commit-Position: refs/heads/master@{#417498}
parent 7255c311
...@@ -54,6 +54,16 @@ void CertErrors::AddWith2DerParams(CertErrorType type, ...@@ -54,6 +54,16 @@ void CertErrors::AddWith2DerParams(CertErrorType type,
AddWithParam(type, base::MakeUnique<CertErrorParamsDer2>(der1, der2)); AddWithParam(type, base::MakeUnique<CertErrorParamsDer2>(der1, der2));
} }
std::string CertErrors::ToDebugString() const {
std::string str;
for (const auto& error : errors_) {
if (!str.empty())
str += "\n";
str += error.type;
}
return str;
}
ScopedCertErrorsCertContext::ScopedCertErrorsCertContext( ScopedCertErrorsCertContext::ScopedCertErrorsCertContext(
CertErrors* parent, CertErrors* parent,
const ParsedCertificate* cert, const ParsedCertificate* cert,
......
...@@ -115,6 +115,9 @@ class NET_EXPORT CertErrors { ...@@ -115,6 +115,9 @@ class NET_EXPORT CertErrors {
const std::vector<CertError>& errors() const { return errors_; } const std::vector<CertError>& errors() const { return errors_; }
// Dumps a textual representation of the errors for debugging purposes.
std::string ToDebugString() const;
private: private:
std::vector<CertError> errors_; std::vector<CertError> errors_;
......
...@@ -12,22 +12,6 @@ namespace net { ...@@ -12,22 +12,6 @@ namespace net {
namespace { namespace {
// Builds a string representation of all the errors/warnings, that matches the
// format used in the test files. The format is described in
// net/data/verify_certificate_chain_unittest/README.
//
// TODO(crbug.com/634443): Use a richer string format that includes the error
// parameters and context.
std::string MakeErrorsString(const CertErrors& errors) {
std::string str;
for (const auto& error : errors.errors()) {
if (!str.empty())
str += "\n";
str += error.type;
}
return str;
}
class VerifyCertificateChainDelegate { class VerifyCertificateChainDelegate {
public: public:
static void Verify(const ParsedCertificateList& chain, static void Verify(const ParsedCertificateList& chain,
...@@ -43,7 +27,7 @@ class VerifyCertificateChainDelegate { ...@@ -43,7 +27,7 @@ class VerifyCertificateChainDelegate {
bool result = VerifyCertificateChain(chain, trust_anchor.get(), bool result = VerifyCertificateChain(chain, trust_anchor.get(),
&signature_policy, time, &errors); &signature_policy, time, &errors);
EXPECT_EQ(expected_result, result); EXPECT_EQ(expected_result, result);
EXPECT_EQ(expected_errors, MakeErrorsString(errors)); EXPECT_EQ(expected_errors, errors.ToDebugString());
} }
}; };
......
...@@ -66,6 +66,5 @@ This PEM block describes the expected result from verifying the path. ...@@ -66,6 +66,5 @@ This PEM block describes the expected result from verifying the path.
ERRORS: ERRORS:
This PEM block is a newline separated list of errors that are expected to occur This PEM block is a pretty-printed textual dump of all the errors, as given by
when validating this path. The error string should correspond with a CertErrors::ToDebugString().
CertErrorType.
...@@ -453,6 +453,7 @@ def write_test_file(description, chain, trust_anchor, utc_time, verify_result, ...@@ -453,6 +453,7 @@ def write_test_file(description, chain, trust_anchor, utc_time, verify_result,
verify_result_string = 'SUCCESS' if verify_result else 'FAIL' verify_result_string = 'SUCCESS' if verify_result else 'FAIL'
test_data += '\n' + text_data_to_pem('VERIFY_RESULT', verify_result_string) test_data += '\n' + text_data_to_pem('VERIFY_RESULT', verify_result_string)
# TODO(eroman): Make the consumer pass errors as a string.
if errors is not None: if errors is not None:
test_data += '\n' + text_data_to_pem('ERRORS', '\n'.join(errors)) test_data += '\n' + text_data_to_pem('ERRORS', '\n'.join(errors))
......
...@@ -119,15 +119,6 @@ std::string SubjectFromTrustAnchor(const net::TrustAnchor* trust_anchor) { ...@@ -119,15 +119,6 @@ std::string SubjectFromTrustAnchor(const net::TrustAnchor* trust_anchor) {
return SubjectToString(parsed_subject); return SubjectToString(parsed_subject);
} }
void PrintCertErrors(const net::CertErrors& errors) {
// TODO(crbug.com/634443): Include more detailed error information. Also this
// should likely be extracted to a common location and used by unit-tests and
// other debugging needs.
for (const auto& error : errors.errors()) {
std::cout << " " << error.type << "\n";
}
}
// Dumps a ResultPath to std::cout. // Dumps a ResultPath to std::cout.
void PrintResultPath(const net::CertPathBuilder::ResultPath* result_path, void PrintResultPath(const net::CertPathBuilder::ResultPath* result_path,
size_t index, size_t index,
...@@ -157,7 +148,7 @@ void PrintResultPath(const net::CertPathBuilder::ResultPath* result_path, ...@@ -157,7 +148,7 @@ void PrintResultPath(const net::CertPathBuilder::ResultPath* result_path,
// Print the errors. // Print the errors.
if (!result_path->errors.errors().empty()) { if (!result_path->errors.errors().empty()) {
std::cout << "Errors:\n"; std::cout << "Errors:\n";
PrintCertErrors(result_path->errors); std::cout << result_path->errors.ToDebugString() << "\n";
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment