22 #include <gmock/gmock.h>
23 #include <gtest/gtest.h>
35 #define CA_CERT_PATH "src/core/tsi/test_creds/ca.pem"
36 #define SERVER_CERT_PATH "src/core/tsi/test_creds/server1.pem"
37 #define SERVER_KEY_PATH "src/core/tsi/test_creds/server1.key"
38 #define CA_CERT_PATH_2 "src/core/tsi/test_creds/multi-domain.pem"
39 #define SERVER_CERT_PATH_2 "src/core/tsi/test_creds/server0.pem"
40 #define SERVER_KEY_PATH_2 "src/core/tsi/test_creds/server0.key"
41 #define INVALID_PATH "invalid/path"
48 constexpr
const char*
kRootError =
"Unable to get latest root certificates.";
50 "Unable to get latest identity certificates.";
108 TlsCertificatesWatcherInterface {
128 updated_identity =
std::move(*key_cert_pairs);
148 &identity_error_str));
181 absl::make_unique<TlsCertificatesTestWatcher>(&
watchers_.back());
212 WatcherState* watcher_state_1 =
217 cert_chain_.c_str()))));
218 CancelWatch(watcher_state_1);
220 WatcherState* watcher_state_2 =
224 CancelWatch(watcher_state_2);
226 WatcherState* watcher_state_3 =
229 watcher_state_3->GetCredentialQueue(),
232 CancelWatch(watcher_state_3);
236 FileWatcherCertificateProviderWithGoodPaths) {
240 WatcherState* watcher_state_1 =
245 cert_chain_.c_str()))));
246 CancelWatch(watcher_state_1);
248 WatcherState* watcher_state_2 =
252 CancelWatch(watcher_state_2);
254 WatcherState* watcher_state_3 =
257 watcher_state_3->GetCredentialQueue(),
260 CancelWatch(watcher_state_3);
264 FileWatcherCertificateProviderWithBadPaths) {
268 WatcherState* watcher_state_1 =
273 CancelWatch(watcher_state_1);
275 WatcherState* watcher_state_2 =
280 CancelWatch(watcher_state_2);
282 WatcherState* watcher_state_3 =
287 CancelWatch(watcher_state_3);
293 FileWatcherCertificateProviderOnBothCertsRefreshed) {
296 TmpFile tmp_identity_key(private_key_);
297 TmpFile tmp_identity_cert(cert_chain_);
300 tmp_identity_cert.
name(),
301 tmp_root_cert.
name(), 1);
302 WatcherState* watcher_state_1 =
308 cert_chain_.c_str()))));
322 cert_chain_2_.c_str()))));
324 CancelWatch(watcher_state_1);
328 FileWatcherCertificateProviderOnRootCertsRefreshed) {
331 TmpFile tmp_identity_key(private_key_);
332 TmpFile tmp_identity_cert(cert_chain_);
335 tmp_identity_cert.
name(),
336 tmp_root_cert.
name(), 1);
337 WatcherState* watcher_state_1 =
343 cert_chain_.c_str()))));
355 cert_chain_.c_str()))));
357 CancelWatch(watcher_state_1);
361 FileWatcherCertificateProviderOnIdentityCertsRefreshed) {
364 TmpFile tmp_identity_key(private_key_);
365 TmpFile tmp_identity_cert(cert_chain_);
368 tmp_identity_cert.
name(),
369 tmp_root_cert.
name(), 1);
370 WatcherState* watcher_state_1 =
376 cert_chain_.c_str()))));
389 cert_chain_2_.c_str()))));
391 CancelWatch(watcher_state_1);
395 FileWatcherCertificateProviderWithGoodAtFirstThenDeletedBothCerts) {
397 auto tmp_root_cert = absl::make_unique<TmpFile>(
root_cert_);
398 auto tmp_identity_key = absl::make_unique<TmpFile>(private_key_);
399 auto tmp_identity_cert = absl::make_unique<TmpFile>(cert_chain_);
402 tmp_identity_cert->name(),
403 tmp_root_cert->name(), 1);
404 WatcherState* watcher_state_1 =
411 cert_chain_.c_str()))));
413 tmp_root_cert.reset();
414 tmp_identity_key.reset();
415 tmp_identity_cert.reset();
425 CancelWatch(watcher_state_1);
429 FileWatcherCertificateProviderWithGoodAtFirstThenDeletedRootCerts) {
431 auto tmp_root_cert = absl::make_unique<TmpFile>(
root_cert_);
432 TmpFile tmp_identity_key(private_key_);
433 TmpFile tmp_identity_cert(cert_chain_);
436 tmp_identity_cert.
name(),
437 tmp_root_cert->name(), 1);
438 WatcherState* watcher_state_1 =
445 cert_chain_.c_str()))));
447 tmp_root_cert.reset();
457 CancelWatch(watcher_state_1);
461 FileWatcherCertificateProviderWithGoodAtFirstThenDeletedIdentityCerts) {
464 auto tmp_identity_key = absl::make_unique<TmpFile>(private_key_);
465 auto tmp_identity_cert = absl::make_unique<TmpFile>(cert_chain_);
468 tmp_identity_cert->name(),
469 tmp_root_cert.
name(), 1);
470 WatcherState* watcher_state_1 =
477 cert_chain_.c_str()))));
479 tmp_identity_key.reset();
480 tmp_identity_cert.reset();
490 CancelWatch(watcher_state_1);
515 "Conversion from PEM string to X509 failed.");
519 FailedKeyCertMatchOnInvalidPrivateKeyFormat) {
524 "Conversion from PEM string to EVP_PKEY failed.");
544 int main(
int argc,
char** argv) {