• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.1
/src/tests/test_name_constraint.cpp
1
/*
2
* (C) 2015,2016 Kai Michaelis
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "tests.h"
8

9
#if defined(BOTAN_HAS_X509_CERTIFICATES)
10
   #include <botan/x509path.h>
11
   #include <botan/internal/calendar.h>
12
#endif
13

14
#include <utility>
15

16
namespace Botan_Tests {
17

18
namespace {
19

20
#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_HAS_RSA) && defined(BOTAN_HAS_EMSA_PKCS1) && \
21
   defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
22

23
class Name_Constraint_Tests final : public Test {
×
24
   public:
25
      std::vector<Test::Result> run() override {
1✔
26
         const std::vector<std::tuple<std::string, std::string, std::string, std::string>> test_cases = {
1✔
27
            std::make_tuple("Root_Email_Name_Constraint.crt",
1✔
28
                            "Invalid_Email_Name_Constraint.crt",
29
                            "Invalid Email Name Constraint",
30
                            "Certificate does not pass name constraint"),
31
            std::make_tuple("Root_DN_Name_Constraint.crt",
1✔
32
                            "Invalid_DN_Name_Constraint.crt",
33
                            "Invalid DN Name Constraint",
34
                            "Certificate does not pass name constraint"),
35
            std::make_tuple(
1✔
36
               "Root_DN_Name_Constraint.crt", "Valid_DN_Name_Constraint.crt", "Valid DN Name Constraint", "Verified"),
37
            std::make_tuple(
1✔
38
               "Root_DNS_Name_Constraint.crt", "Valid_DNS_Name_Constraint.crt", "aexample.com", "Verified"),
39
            std::make_tuple(
1✔
40
               "Root_IP_Name_Constraint.crt", "Valid_IP_Name_Constraint.crt", "Valid IP Name Constraint", "Verified"),
41
            std::make_tuple("Root_IP_Name_Constraint.crt",
1✔
42
                            "Invalid_IP_Name_Constraint.crt",
43
                            "Invalid IP Name Constraint",
44
                            "Certificate does not pass name constraint"),
45
         };
7✔
46
         std::vector<Test::Result> results;
1✔
47
         const Botan::Path_Validation_Restrictions restrictions(false, 80);
2✔
48

49
         std::chrono::system_clock::time_point validation_time =
1✔
50
            Botan::calendar_point(2016, 10, 21, 4, 20, 0).to_std_timepoint();
1✔
51

52
         for(const auto& t : test_cases) {
7✔
53
            Botan::X509_Certificate root(Test::data_file("x509/name_constraint/" + std::get<0>(t)));
12✔
54
            Botan::X509_Certificate sub(Test::data_file("x509/name_constraint/" + std::get<1>(t)));
12✔
55
            Botan::Certificate_Store_In_Memory trusted;
6✔
56
            Test::Result result("X509v3 Name Constraints: " + std::get<1>(t));
6✔
57

58
            trusted.add_certificate(root);
6✔
59
            Botan::Path_Validation_Result path_result = Botan::x509_path_validate(
6✔
60
               sub, restrictions, trusted, std::get<2>(t), Botan::Usage_Type::TLS_SERVER_AUTH, validation_time);
6✔
61

62
            if(path_result.successful_validation() && path_result.trust_root() != root) {
6✔
63
               path_result = Botan::Path_Validation_Result(Botan::Certificate_Status_Code::CANNOT_ESTABLISH_TRUST);
×
64
            }
65

66
            result.test_eq("validation result", path_result.result_string(), std::get<3>(t));
12✔
67
            results.emplace_back(result);
6✔
68
         }
6✔
69

70
         return results;
1✔
71
      }
1✔
72
};
73

74
BOTAN_REGISTER_TEST("x509", "x509_path_name_constraint", Name_Constraint_Tests);
75

76
#endif
77

78
}
79

80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc