| 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> | 8 #include <set> |
| 9 | 9 |
| 10 #include "net/cert/internal/test_helpers.h" | 10 #include "net/cert/internal/test_helpers.h" |
| 11 #include "net/der/parse_values.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace net { | 14 namespace net { |
| 14 | 15 |
| 15 // Describes additional inputs to verification in the PKITS tests | 16 // Describes the inputs and outputs (other than the certificates) for |
| 16 // (which are referred to as "settings" in that document). | 17 // the PKITS tests. |
| 17 struct PkitsTestSettings { | 18 struct PkitsTestInfo { |
| 18 // Default construction results in the "default settings". | 19 // Default construction results in the "default settings". |
| 19 PkitsTestSettings(); | 20 PkitsTestInfo(); |
| 20 ~PkitsTestSettings(); | 21 ~PkitsTestInfo(); |
| 21 | 22 |
| 22 // Sets |initial_policy_set| to the specified policies. The | 23 // Sets |initial_policy_set| to the specified policies. The |
| 23 // policies are described as comma-separated symbolic strings like | 24 // policies are described as comma-separated symbolic strings like |
| 24 // "anyPolicy" and "NIST-test-policy-1". | 25 // "anyPolicy" and "NIST-test-policy-1". |
| 25 void SetInitialPolicySet(const char* const policy_names); | 26 void SetInitialPolicySet(const char* const policy_names); |
| 26 | 27 |
| 28 // Sets |user_constrained_policy_set| to the specified policies. The |
| 29 // policies are described as comma-separated symbolic strings like |
| 30 // "anyPolicy" and "NIST-test-policy-1". |
| 31 void SetUserConstrainedPolicySet(const char* const policy_names); |
| 32 |
| 33 void SetInitialExplicitPolicy(bool b); |
| 34 void SetInitialPolicyMappingInhibit(bool b); |
| 35 void SetInitialInhibitAnyPolicy(bool b); |
| 36 |
| 37 // ---------------- |
| 38 // Inputs |
| 39 // ---------------- |
| 40 |
| 27 // A set of policy OIDs to use for "initial-policy-set". | 41 // A set of policy OIDs to use for "initial-policy-set". |
| 28 std::set<der::Input> initial_policy_set; | 42 std::set<der::Input> initial_policy_set; |
| 29 | 43 |
| 30 // The value of "initial-explicit-policy". | 44 // The value of "initial-explicit-policy". |
| 31 bool initial_explicit_policy = false; | 45 bool initial_explicit_policy = false; |
| 32 | 46 |
| 33 // The value of "initial-policy-mapping-inhibit". | 47 // The value of "initial-policy-mapping-inhibit". |
| 34 bool initial_policy_mapping_inhibit = false; | 48 bool initial_policy_mapping_inhibit = false; |
| 35 | 49 |
| 36 // The value of "initial-inhibit-any-policy". | 50 // The value of "initial-inhibit-any-policy". |
| 37 bool initial_inhibit_any_policy = false; | 51 bool initial_inhibit_any_policy = false; |
| 52 |
| 53 // This is the time when PKITS was published. |
| 54 der::GeneralizedTime time = {2011, 4, 15, 0, 0, 0}; |
| 55 |
| 56 // ---------------- |
| 57 // Expected outputs |
| 58 // ---------------- |
| 59 |
| 60 // Whether path validation should succeed. |
| 61 bool should_validate = false; |
| 62 |
| 63 std::set<der::Input> user_constrained_policy_set; |
| 38 }; | 64 }; |
| 39 | 65 |
| 40 // Parameterized test class for PKITS tests. | 66 // Parameterized test class for PKITS tests. |
| 41 // The instantiating code should define a PkitsTestDelegate with an appropriate | 67 // The instantiating code should define a PkitsTestDelegate with an appropriate |
| 42 // static Verify method, and then INSTANTIATE_TYPED_TEST_CASE_P for each | 68 // static RunTest method, and then INSTANTIATE_TYPED_TEST_CASE_P for each |
| 43 // testcase (each TYPED_TEST_CASE_P in pkits_testcases-inl.h). | 69 // testcase (each TYPED_TEST_CASE_P in pkits_testcases-inl.h). |
| 44 template <typename PkitsTestDelegate> | 70 template <typename PkitsTestDelegate> |
| 45 class PkitsTest : public ::testing::Test { | 71 class PkitsTest : public ::testing::Test { |
| 46 public: | 72 public: |
| 47 template <size_t num_certs, size_t num_crls> | 73 template <size_t num_certs, size_t num_crls> |
| 48 bool Verify(const char* const (&cert_names)[num_certs], | 74 void RunTest(const char* const (&cert_names)[num_certs], |
| 49 const char* const (&crl_names)[num_crls], | 75 const char* const (&crl_names)[num_crls], |
| 50 const PkitsTestSettings& settings) { | 76 const PkitsTestInfo& info) { |
| 51 std::vector<std::string> cert_ders; | 77 std::vector<std::string> cert_ders; |
| 52 for (const std::string& s : cert_names) | 78 for (const std::string& s : cert_names) |
| 53 cert_ders.push_back(net::ReadTestFileToString( | 79 cert_ders.push_back(net::ReadTestFileToString( |
| 54 "net/third_party/nist-pkits/certs/" + s + ".crt")); | 80 "net/third_party/nist-pkits/certs/" + s + ".crt")); |
| 55 std::vector<std::string> crl_ders; | 81 std::vector<std::string> crl_ders; |
| 56 for (const std::string& s : crl_names) | 82 for (const std::string& s : crl_names) |
| 57 crl_ders.push_back(net::ReadTestFileToString( | 83 crl_ders.push_back(net::ReadTestFileToString( |
| 58 "net/third_party/nist-pkits/crls/" + s + ".crl")); | 84 "net/third_party/nist-pkits/crls/" + s + ".crl")); |
| 59 return PkitsTestDelegate::Verify(cert_ders, crl_ders, settings); | 85 PkitsTestDelegate::RunTest(cert_ders, crl_ders, info); |
| 60 } | 86 } |
| 61 }; | 87 }; |
| 62 | 88 |
| 63 // Inline the generated test code: | 89 // Inline the generated test code: |
| 64 #include "net/third_party/nist-pkits/pkits_testcases-inl.h" | 90 #include "net/third_party/nist-pkits/pkits_testcases-inl.h" |
| 65 | 91 |
| 66 } // namespace net | 92 } // namespace net |
| 67 | 93 |
| 68 #endif // NET_CERT_INTERNAL_NIST_PKITS_UNITTEST_H_ | 94 #endif // NET_CERT_INTERNAL_NIST_PKITS_UNITTEST_H_ |
| OLD | NEW |