OLD | NEW |
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 <set> |
| 9 |
8 #include "net/cert/internal/test_helpers.h" | 10 #include "net/cert/internal/test_helpers.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 | 12 |
| 13 namespace net { |
| 14 |
| 15 // Describes additional inputs to verification in the PKITS tests |
| 16 // (which are referred to as "settings" in that document). |
| 17 struct PkitsTestSettings { |
| 18 // Default construction results in the "default settings". |
| 19 PkitsTestSettings(); |
| 20 ~PkitsTestSettings(); |
| 21 |
| 22 // Sets |initial_policy_set| to the specified policies. The |
| 23 // policies are described as comma-separated symbolic strings like |
| 24 // "anyPolicy" and "NIST-test-policy-1". |
| 25 void SetInitialPolicySet(const char* const policy_names); |
| 26 |
| 27 // A set of policy OIDs to use for "initial-policy-set". |
| 28 std::set<der::Input> initial_policy_set; |
| 29 |
| 30 // The value of "initial-explicit-policy". |
| 31 bool initial_explicit_policy = false; |
| 32 |
| 33 // The value of "initial-policy-mapping-inhibit". |
| 34 bool initial_policy_mapping_inhibit = false; |
| 35 |
| 36 // The value of "initial-inhibit-any-policy". |
| 37 bool initial_inhibit_any_policy = false; |
| 38 }; |
| 39 |
11 // Parameterized test class for PKITS tests. | 40 // Parameterized test class for PKITS tests. |
12 // The instantiating code should define a PkitsTestDelegate with an appropriate | 41 // The instantiating code should define a PkitsTestDelegate with an appropriate |
13 // static Verify method, and then INSTANTIATE_TYPED_TEST_CASE_P for each | 42 // static Verify method, and then INSTANTIATE_TYPED_TEST_CASE_P for each |
14 // testcase (each TYPED_TEST_CASE_P in pkits_testcases-inl.h). | 43 // testcase (each TYPED_TEST_CASE_P in pkits_testcases-inl.h). |
15 template <typename PkitsTestDelegate> | 44 template <typename PkitsTestDelegate> |
16 class PkitsTest : public ::testing::Test { | 45 class PkitsTest : public ::testing::Test { |
17 public: | 46 public: |
18 template <size_t num_certs, size_t num_crls> | 47 template <size_t num_certs, size_t num_crls> |
19 bool Verify(const char* const (&cert_names)[num_certs], | 48 bool Verify(const char* const (&cert_names)[num_certs], |
20 const char* const (&crl_names)[num_crls]) { | 49 const char* const (&crl_names)[num_crls], |
| 50 const PkitsTestSettings& settings) { |
21 std::vector<std::string> cert_ders; | 51 std::vector<std::string> cert_ders; |
22 for (const std::string& s : cert_names) | 52 for (const std::string& s : cert_names) |
23 cert_ders.push_back(net::ReadTestFileToString( | 53 cert_ders.push_back(net::ReadTestFileToString( |
24 "net/third_party/nist-pkits/certs/" + s + ".crt")); | 54 "net/third_party/nist-pkits/certs/" + s + ".crt")); |
25 std::vector<std::string> crl_ders; | 55 std::vector<std::string> crl_ders; |
26 for (const std::string& s : crl_names) | 56 for (const std::string& s : crl_names) |
27 crl_ders.push_back(net::ReadTestFileToString( | 57 crl_ders.push_back(net::ReadTestFileToString( |
28 "net/third_party/nist-pkits/crls/" + s + ".crl")); | 58 "net/third_party/nist-pkits/crls/" + s + ".crl")); |
29 return PkitsTestDelegate::Verify(cert_ders, crl_ders); | 59 return PkitsTestDelegate::Verify(cert_ders, crl_ders, settings); |
30 } | 60 } |
31 }; | 61 }; |
32 | 62 |
33 // Inline the generated test code: | 63 // Inline the generated test code: |
34 #include "net/third_party/nist-pkits/pkits_testcases-inl.h" | 64 #include "net/third_party/nist-pkits/pkits_testcases-inl.h" |
35 | 65 |
| 66 } // namespace net |
| 67 |
36 #endif // NET_CERT_INTERNAL_NIST_PKITS_UNITTEST_H_ | 68 #endif // NET_CERT_INTERNAL_NIST_PKITS_UNITTEST_H_ |
OLD | NEW |