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