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

randombit / botan / 19012754211

02 Nov 2025 01:10PM UTC coverage: 90.677% (+0.006%) from 90.671%
19012754211

push

github

web-flow
Merge pull request #5137 from randombit/jack/clang-tidy-includes

Remove various unused includes flagged by clang-tidy misc-include-cleaner

100457 of 110786 relevant lines covered (90.68%)

12189873.8 hits per line

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

83.94
/src/tests/test_certstor_flatfile.cpp
1
/*
2
* (C) 1999-2019 Jack Lloyd
3
* (C) 2019      René Meusel
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include "tests.h"
9

10
#if defined(BOTAN_HAS_CERTSTOR_FLATFILE)
11

12
   #include "test_certstor_utils.h"
13
   #include <botan/certstor_flatfile.h>
14

15
namespace Botan_Tests {
16

17
namespace {
18

19
std::string get_valid_ca_bundle_path() {
10✔
20
   return Test::data_file("x509/misc/certstor/valid_ca_bundle.pem");
20✔
21
}
22

23
std::string get_ca_bundle_containing_user_cert() {
1✔
24
   return Test::data_file("x509/misc/certstor/ca_bundle_containing_non_ca.pem");
2✔
25
}
26

27
Test::Result open_certificate_store() {
1✔
28
   Test::Result result("Flatfile Certificate Store - Open Store");
1✔
29

30
   try {
1✔
31
      result.start_timer();
1✔
32
      Botan::Flatfile_Certificate_Store unused(get_valid_ca_bundle_path());
1✔
33
      result.end_timer();
1✔
34
      result.test_gt("found some certificates", unused.all_subjects().size(), 0);
2✔
35
   } catch(std::exception& e) {
1✔
36
      result.test_failure(e.what());
×
37
   }
×
38

39
   result.test_success();
1✔
40

41
   return result;
1✔
42
}
×
43

44
Test::Result find_certificate_by_pubkey_sha1() {
1✔
45
   Test::Result result("Flatfile Certificate Store - Find Certificate by SHA1(pubkey)");
1✔
46

47
   try {
1✔
48
      result.start_timer();
1✔
49
      Botan::Flatfile_Certificate_Store certstore(get_valid_ca_bundle_path());
1✔
50
      auto cert = certstore.find_cert_by_pubkey_sha1(get_key_id());
1✔
51
      result.end_timer();
1✔
52

53
      if(result.test_not_nullopt("found certificate", cert)) {
1✔
54
         auto cns = cert->subject_dn().get_attribute("CN");
1✔
55
         result.test_int_eq("exactly one CN", cns.size(), 1);
2✔
56
         result.test_eq("CN", cns.front(), get_subject_cn());
2✔
57
      }
1✔
58
   } catch(std::exception& e) {
1✔
59
      result.test_failure(e.what());
×
60
   }
×
61

62
   result.test_throws("on invalid SHA1 hash data", [&] {
2✔
63
      Botan::Flatfile_Certificate_Store certstore(get_valid_ca_bundle_path());
1✔
64
      certstore.find_cert_by_pubkey_sha1({});
2✔
65
   });
1✔
66

67
   return result;
1✔
68
}
×
69

70
Test::Result find_cert_by_subject_dn() {
1✔
71
   Test::Result result("Flatfile Certificate Store - Find Certificate by subject DN");
1✔
72

73
   try {
1✔
74
      auto dn = get_dn();
1✔
75

76
      result.start_timer();
1✔
77
      Botan::Flatfile_Certificate_Store certstore(get_valid_ca_bundle_path());
1✔
78
      auto cert = certstore.find_cert(dn, std::vector<uint8_t>());
1✔
79
      result.end_timer();
1✔
80

81
      if(result.test_not_nullopt("found certificate", cert)) {
1✔
82
         auto cns = cert->subject_dn().get_attribute("CN");
1✔
83
         result.test_int_eq("exactly one CN", cns.size(), 1);
2✔
84
         result.test_eq("CN", cns.front(), get_subject_cn());
2✔
85
      }
1✔
86
   } catch(std::exception& e) {
1✔
87
      result.test_failure(e.what());
×
88
   }
×
89

90
   return result;
1✔
91
}
×
92

93
Test::Result find_cert_by_utf8_subject_dn() {
1✔
94
   Test::Result result("Flatfile Certificate Store - Find Certificate by UTF8 subject DN");
1✔
95

96
   try {
1✔
97
      auto dn = get_utf8_dn();
1✔
98

99
      result.start_timer();
1✔
100
      Botan::Flatfile_Certificate_Store certstore(get_valid_ca_bundle_path());
1✔
101
      auto cert = certstore.find_cert(dn, std::vector<uint8_t>());
1✔
102

103
      result.end_timer();
1✔
104

105
      if(result.test_not_nullopt("found certificate", cert)) {
1✔
106
         auto cns = cert->subject_dn().get_attribute("CN");
1✔
107
         result.test_is_eq("exactly one CN", cns.size(), size_t(1));
1✔
108
         result.test_eq("CN", cns.front(), "D-TRUST Root Class 3 CA 2 EV 2009");
2✔
109
      }
1✔
110
   } catch(std::exception& e) {
1✔
111
      result.test_failure(e.what());
×
112
   }
×
113

114
   return result;
1✔
115
}
×
116

117
Test::Result find_cert_by_subject_dn_and_key_id() {
1✔
118
   Test::Result result("Flatfile Certificate Store - Find Certificate by subject DN and key ID");
1✔
119

120
   try {
1✔
121
      auto dn = get_dn();
1✔
122

123
      result.start_timer();
1✔
124
      Botan::Flatfile_Certificate_Store certstore(get_valid_ca_bundle_path());
1✔
125
      auto cert = certstore.find_cert(dn, get_key_id());
1✔
126
      result.end_timer();
1✔
127

128
      if(result.test_not_nullopt("found certificate", cert)) {
1✔
129
         auto cns = cert->subject_dn().get_attribute("CN");
1✔
130
         result.test_int_eq("exactly one CN", cns.size(), 1);
2✔
131
         result.test_eq("CN", cns.front(), get_subject_cn());
2✔
132
      }
1✔
133
   } catch(std::exception& e) {
1✔
134
      result.test_failure(e.what());
×
135
   }
×
136

137
   return result;
1✔
138
}
×
139

140
Test::Result find_certs_by_subject_dn_and_key_id() {
1✔
141
   Test::Result result("Flatfile Certificate Store - Find Certificates by subject DN and key ID");
1✔
142

143
   try {
1✔
144
      auto dn = get_dn();
1✔
145

146
      result.start_timer();
1✔
147
      Botan::Flatfile_Certificate_Store certstore(get_valid_ca_bundle_path());
1✔
148
      auto certs = certstore.find_all_certs(dn, get_key_id());
1✔
149
      result.end_timer();
1✔
150

151
      if(result.confirm("result not empty", !certs.empty()) &&
2✔
152
         result.test_eq("exactly one certificate", certs.size(), 1)) {
2✔
153
         auto cns = certs.front().subject_dn().get_attribute("CN");
1✔
154
         result.test_int_eq("exactly one CN", cns.size(), 1);
2✔
155
         result.test_eq("CN", cns.front(), get_subject_cn());
2✔
156
      }
1✔
157
   } catch(std::exception& e) {
1✔
158
      result.test_failure(e.what());
×
159
   }
×
160

161
   return result;
1✔
162
}
×
163

164
Test::Result find_all_subjects() {
1✔
165
   Test::Result result("Flatfile Certificate Store - Find all Certificate Subjects");
1✔
166

167
   try {
1✔
168
      result.start_timer();
1✔
169
      Botan::Flatfile_Certificate_Store certstore(get_valid_ca_bundle_path());
1✔
170
      auto subjects = certstore.all_subjects();
1✔
171
      result.end_timer();
1✔
172

173
      if(result.confirm("result not empty", !subjects.empty())) {
2✔
174
         auto dn = get_dn();
1✔
175
         auto needle = std::find_if(
1✔
176
            subjects.cbegin(), subjects.cend(), [=](const Botan::X509_DN& subject) { return subject == dn; });
9✔
177

178
         if(result.confirm("found expected certificate", needle != subjects.end())) {
2✔
179
            result.confirm("expected certificate", *needle == dn);
2✔
180
         }
181
      }
1✔
182
   } catch(std::exception& e) {
1✔
183
      result.test_failure(e.what());
×
184
   }
×
185

186
   return result;
1✔
187
}
×
188

189
Test::Result no_certificate_matches() {
1✔
190
   Test::Result result("Flatfile Certificate Store - can deal with no matches (regression test)");
1✔
191

192
   try {
1✔
193
      auto dn = get_unknown_dn();
1✔
194
      auto kid = get_unknown_key_id();
1✔
195

196
      result.start_timer();
1✔
197
      Botan::Flatfile_Certificate_Store certstore(get_valid_ca_bundle_path());
1✔
198

199
      auto certs = certstore.find_all_certs(dn, kid);
1✔
200
      auto cert = certstore.find_cert(dn, kid);
1✔
201
      auto pubk_cert = certstore.find_cert_by_pubkey_sha1(kid);
1✔
202
      result.end_timer();
1✔
203

204
      result.confirm("find_all_certs did not find the dummy", certs.empty());
2✔
205
      result.confirm("find_cert did not find the dummy", !cert);
2✔
206
      result.confirm("find_cert_by_pubkey_sha1 did not find the dummy", !pubk_cert);
2✔
207
   } catch(std::exception& e) {
2✔
208
      result.test_failure(e.what());
×
209
   }
×
210

211
   return result;
1✔
212
}
×
213

214
Test::Result certstore_contains_user_certificate() {
1✔
215
   Test::Result result("Flatfile Certificate Store - rejects bundles with non-CA certs");
1✔
216

217
   try {
1✔
218
      result.start_timer();
1✔
219
      Botan::Flatfile_Certificate_Store certstore(get_ca_bundle_containing_user_cert());
2✔
220
      result.test_failure("CA bundle with non-CA certs should be rejected");
×
221
   } catch(Botan::Invalid_Argument&) {
1✔
222
      result.test_success();
1✔
223
   }
1✔
224

225
   return result;
1✔
226
}
×
227

228
Test::Result find_cert_by_issuer_dn_and_serial_number() {
1✔
229
   Test::Result result("Flatfile Certificate Store - Find Certificate by issuer DN and serial number");
1✔
230

231
   try {
1✔
232
      result.start_timer();
1✔
233
      Botan::Flatfile_Certificate_Store certstore(get_valid_ca_bundle_path());
1✔
234
      auto cert = certstore.find_cert_by_issuer_dn_and_serial_number(get_dn(), get_serial_number());
1✔
235
      result.end_timer();
1✔
236

237
      if(result.test_not_nullopt("found certificate", cert)) {
1✔
238
         auto cns = cert->subject_dn().get_attribute("CN");
1✔
239
         result.test_int_eq("exactly one CN", cns.size(), 1);
2✔
240
         result.test_eq("CN", cns.front(), get_subject_cn());
2✔
241
         result.test_eq("serial number", cert->serial_number(), get_serial_number());
2✔
242
      }
1✔
243
   } catch(std::exception& e) {
1✔
244
      result.test_failure(e.what());
×
245
   }
×
246

247
   return result;
1✔
248
}
×
249

250
class Certstor_Flatfile_Tests final : public Test {
×
251
   public:
252
      std::vector<Test::Result> run() override {
1✔
253
         std::vector<Test::Result> results;
1✔
254

255
         results.push_back(open_certificate_store());
2✔
256
         results.push_back(find_certificate_by_pubkey_sha1());
2✔
257
         results.push_back(find_cert_by_subject_dn());
2✔
258
         results.push_back(find_cert_by_utf8_subject_dn());
2✔
259
         results.push_back(find_cert_by_subject_dn_and_key_id());
2✔
260
         results.push_back(find_certs_by_subject_dn_and_key_id());
2✔
261
         results.push_back(find_all_subjects());
2✔
262
         results.push_back(no_certificate_matches());
2✔
263
         results.push_back(certstore_contains_user_certificate());
2✔
264
         results.push_back(find_cert_by_issuer_dn_and_serial_number());
2✔
265

266
         return results;
1✔
267
      }
×
268
};
269

270
BOTAN_REGISTER_TEST("x509", "certstor_flatfile", Certstor_Flatfile_Tests);
271

272
}  // namespace
273

274
}  // namespace Botan_Tests
275

276
#endif
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

© 2026 Coveralls, Inc