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

Unified Diff: net/cert/internal/verify_certificate_chain_typed_unittest.h

Issue 2126803004: WIP: NSS trust store integration for path builder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert-command-line-path-builder-add_certpathbuilder
Patch Set: . Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: net/cert/internal/verify_certificate_chain_typed_unittest.h
diff --git a/net/cert/internal/verify_certificate_chain_typed_unittest.h b/net/cert/internal/verify_certificate_chain_typed_unittest.h
index b4990a3a751d8f021f7a70c783f5d5ee92b0d4b3..41cb77e4ff6cf7d9786b0b22099a5704d60271f8 100644
--- a/net/cert/internal/verify_certificate_chain_typed_unittest.h
+++ b/net/cert/internal/verify_certificate_chain_typed_unittest.h
@@ -5,12 +5,8 @@
#ifndef NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_TYPED_UNITTEST_H_
#define NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_TYPED_UNITTEST_H_
-#include "base/base_paths.h"
-#include "base/files/file_util.h"
-#include "base/path_service.h"
#include "net/cert/internal/parsed_certificate.h"
#include "net/cert/internal/test_helpers.h"
-#include "net/cert/pem_tokenizer.h"
#include "net/der/input.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -25,89 +21,12 @@ class VerifyCertificateChainTest : public ::testing::Test {
der::GeneralizedTime time;
bool expected_result;
- ReadTestFromFile(file_name, &chain, &roots, &time, &expected_result);
+ ReadCertChainTestFromFile(
+ std::string("net/data/verify_certificate_chain_unittest/") + file_name,
+ &chain, &roots, &time, &expected_result);
TestDelegate::Verify(chain, roots, time, expected_result);
}
-
- private:
- // Reads a data file from the unit-test data.
- std::string ReadTestFileToString(const std::string& file_name) {
- // Compute the full path, relative to the src/ directory.
- base::FilePath src_root;
- PathService::Get(base::DIR_SOURCE_ROOT, &src_root);
- base::FilePath filepath = src_root.AppendASCII(
- std::string("net/data/verify_certificate_chain_unittest/") + file_name);
-
- // Read the full contents of the file.
- std::string file_data;
- if (!base::ReadFileToString(filepath, &file_data)) {
- ADD_FAILURE() << "Couldn't read file: " << filepath.value();
- return std::string();
- }
-
- return file_data;
- }
-
- // Reads a test case from |file_name|. Test cases are comprised of a
- // certificate chain, trust store, a timestamp to validate at, and the
- // expected result of verification.
- void ReadTestFromFile(const std::string& file_name,
- ParsedCertificateList* chain,
- ParsedCertificateList* roots,
- der::GeneralizedTime* time,
- bool* verify_result) {
- chain->clear();
- roots->clear();
-
- std::string file_data = ReadTestFileToString(file_name);
-
- std::vector<std::string> pem_headers;
-
- const char kCertificateHeader[] = "CERTIFICATE";
- const char kTrustedCertificateHeader[] = "TRUSTED_CERTIFICATE";
- const char kTimeHeader[] = "TIME";
- const char kResultHeader[] = "VERIFY_RESULT";
-
- pem_headers.push_back(kCertificateHeader);
- pem_headers.push_back(kTrustedCertificateHeader);
- pem_headers.push_back(kTimeHeader);
- pem_headers.push_back(kResultHeader);
-
- bool has_time = false;
- bool has_result = false;
-
- PEMTokenizer pem_tokenizer(file_data, pem_headers);
- while (pem_tokenizer.GetNext()) {
- const std::string& block_type = pem_tokenizer.block_type();
- const std::string& block_data = pem_tokenizer.data();
-
- if (block_type == kCertificateHeader) {
- ASSERT_TRUE(net::ParsedCertificate::CreateAndAddToVector(
- reinterpret_cast<const uint8_t*>(block_data.data()),
- block_data.size(),
- net::ParsedCertificate::DataSource::INTERNAL_COPY, {}, chain));
- } else if (block_type == kTrustedCertificateHeader) {
- ASSERT_TRUE(net::ParsedCertificate::CreateAndAddToVector(
- reinterpret_cast<const uint8_t*>(block_data.data()),
- block_data.size(),
- net::ParsedCertificate::DataSource::INTERNAL_COPY, {}, roots));
- } else if (block_type == kTimeHeader) {
- ASSERT_FALSE(has_time) << "Duplicate " << kTimeHeader;
- has_time = true;
- ASSERT_TRUE(der::ParseUTCTime(der::Input(&block_data), time));
- } else if (block_type == kResultHeader) {
- ASSERT_FALSE(has_result) << "Duplicate " << kResultHeader;
- ASSERT_TRUE(block_data == "SUCCESS" || block_data == "FAIL")
- << "Unrecognized result: " << block_data;
- has_result = true;
- *verify_result = block_data == "SUCCESS";
- }
- }
-
- ASSERT_TRUE(has_time);
- ASSERT_TRUE(has_result);
- }
};
// Tests that have only one root. These can be tested without requiring any
« no previous file with comments | « net/cert/internal/verify_certificate_chain_pkits_unittest.cc ('k') | net/cert/internal/verify_certificate_chain_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698