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

Side by Side Diff: net/cert/internal/nist_pkits_unittest.h

Issue 2233233002: Refactor some certificate verification tests in preparation to adding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@trust_anchor
Patch Set: moar 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef NET_CERT_INTERNAL_NIST_PKITS_UNITTEST_H 5 #ifndef NET_CERT_INTERNAL_NIST_PKITS_UNITTEST_H
6 #define NET_CERT_INTERNAL_NIST_PKITS_UNITTEST_H 6 #define NET_CERT_INTERNAL_NIST_PKITS_UNITTEST_H
7 7
8 #include "base/base_paths.h" 8 #include "net/cert/internal/test_helpers.h"
9 #include "base/files/file_util.h"
10 #include "base/path_service.h"
11 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
12 10
13 // Parameterized test class for PKITS tests. 11 // Parameterized test class for PKITS tests.
14 // The instantiating code should define a PkitsTestDelegate with an appropriate 12 // The instantiating code should define a PkitsTestDelegate with an appropriate
15 // static Verify method, and then INSTANTIATE_TYPED_TEST_CASE_P for each 13 // static Verify method, and then INSTANTIATE_TYPED_TEST_CASE_P for each
16 // testcase (each TYPED_TEST_CASE_P in pkits_testcases-inl.h). 14 // testcase (each TYPED_TEST_CASE_P in pkits_testcases-inl.h).
17 template <typename PkitsTestDelegate> 15 template <typename PkitsTestDelegate>
18 class PkitsTest : public ::testing::Test { 16 class PkitsTest : public ::testing::Test {
19 public: 17 public:
20 template <size_t num_certs, size_t num_crls> 18 template <size_t num_certs, size_t num_crls>
21 bool Verify(const char* const (&cert_names)[num_certs], 19 bool Verify(const char* const (&cert_names)[num_certs],
22 const char* const (&crl_names)[num_crls]) { 20 const char* const (&crl_names)[num_crls]) {
23 std::vector<std::string> cert_ders; 21 std::vector<std::string> cert_ders;
24 for (const std::string& s : cert_names) 22 for (const std::string& s : cert_names)
25 cert_ders.push_back(ReadTestFileToString("certs/" + s + ".crt")); 23 cert_ders.push_back(net::ReadTestFileToString(
24 "net/third_party/nist-pkits/certs/" + s + ".crt"));
26 std::vector<std::string> crl_ders; 25 std::vector<std::string> crl_ders;
27 for (const std::string& s : crl_names) 26 for (const std::string& s : crl_names)
28 crl_ders.push_back(ReadTestFileToString("crls/" + s + ".crl")); 27 crl_ders.push_back(net::ReadTestFileToString(
28 "net/third_party/nist-pkits/crls/" + s + ".crl"));
29 return PkitsTestDelegate::Verify(cert_ders, crl_ders); 29 return PkitsTestDelegate::Verify(cert_ders, crl_ders);
30 } 30 }
31
32 private:
33 std::string ReadTestFileToString(const std::string& file_name) {
34 // Compute the full path, relative to the src/ directory.
35 base::FilePath src_root;
36 PathService::Get(base::DIR_SOURCE_ROOT, &src_root);
37 base::FilePath filepath = src_root.AppendASCII(
38 std::string("net/third_party/nist-pkits/") + file_name);
39
40 // Read the full contents of the file.
41 std::string file_data;
42 if (!base::ReadFileToString(filepath, &file_data)) {
43 ADD_FAILURE() << "Couldn't read file: " << filepath.value();
44 return std::string();
45 }
46
47 return file_data;
48 }
49 }; 31 };
50 32
51 // Inline the generated test code: 33 // Inline the generated test code:
52 #include "net/third_party/nist-pkits/pkits_testcases-inl.h" 34 #include "net/third_party/nist-pkits/pkits_testcases-inl.h"
53 35
54 #endif // NET_CERT_INTERNAL_NIST_PKITS_UNITTEST_H 36 #endif // NET_CERT_INTERNAL_NIST_PKITS_UNITTEST_H
OLDNEW
« no previous file with comments | « no previous file | net/cert/internal/path_builder_unittest.cc » ('j') | net/cert/internal/test_helpers.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698