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

randombit / botan / 11844561993

14 Nov 2024 07:58PM UTC coverage: 91.178% (+0.1%) from 91.072%
11844561993

Pull #4435

github

web-flow
Merge 81dcb29da into e430f157a
Pull Request #4435: Test duration values ​​are now presented in seconds with six digits of precision. Tests without time measurements have been edited.

91856 of 100744 relevant lines covered (91.18%)

9311006.71 hits per line

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

93.55
/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
                            "",
30
                            "Certificate does not pass name constraint"),
31
            std::make_tuple("Root_DN_Name_Constraint.crt",
1✔
32
                            "Invalid_DN_Name_Constraint.crt",
33
                            "",
34
                            "Certificate does not pass name constraint"),
35
            std::make_tuple("Root_DN_Name_Constraint.crt", "Valid_DN_Name_Constraint.crt", "", "Verified"),
1✔
36
            std::make_tuple(
1✔
37
               "Root_DNS_Name_Constraint.crt", "Valid_DNS_Name_Constraint.crt", "aexample.com", "Verified"),
38
            std::make_tuple("Root_IP_Name_Constraint.crt", "Valid_IP_Name_Constraint.crt", "", "Verified"),
1✔
39
            std::make_tuple("Root_IP_Name_Constraint.crt",
1✔
40
                            "Invalid_IP_Name_Constraint.crt",
41
                            "",
42
                            "Certificate does not pass name constraint"),
43
         };
8✔
44
         std::vector<Test::Result> results;
1✔
45
         const Botan::Path_Validation_Restrictions restrictions(false, 80);
2✔
46

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

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

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

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

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

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

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

76
#endif
77

78
}  // namespace
79

80
}  // namespace Botan_Tests
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