grpc_tls_certificate_provider_test.cc
Go to the documentation of this file.
1 //
2 // Copyright 2020 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
18 
19 #include <deque>
20 #include <list>
21 
22 #include <gmock/gmock.h>
23 #include <gtest/gtest.h>
24 
25 #include <grpc/support/alloc.h>
26 #include <grpc/support/log.h>
28 
34 
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"
42 
43 namespace grpc_core {
44 
45 namespace testing {
46 
47 constexpr const char* kCertName = "cert_name";
48 constexpr const char* kRootError = "Unable to get latest root certificates.";
49 constexpr const char* kIdentityError =
50  "Unable to get latest identity certificates.";
51 
53  protected:
54  // Forward declaration.
56 
57  // CredentialInfo contains the parameters when calling OnCertificatesChanged
58  // of a watcher. When OnCertificatesChanged is invoked, we will push a
59  // CredentialInfo to the cert_update_queue of state_, and check in each test
60  // if the status updates are correct.
61  struct CredentialInfo {
65  : root_certs(std::move(root)), key_cert_pairs(std::move(key_cert)) {}
66  bool operator==(const CredentialInfo& other) const {
67  return root_certs == other.root_certs &&
69  }
70  };
71 
72  // ErrorInfo contains the parameters when calling OnError of a watcher. When
73  // OnError is invoked, we will push a ErrorInfo to the error_queue of state_,
74  // and check in each test if the status updates are correct.
75  struct ErrorInfo {
80  identity_cert_str(std::move(identity)) {}
81  bool operator==(const ErrorInfo& other) const {
82  return root_cert_str == other.root_cert_str &&
84  }
85  };
86 
87  struct WatcherState {
89  std::deque<CredentialInfo> cert_update_queue;
90  std::deque<ErrorInfo> error_queue;
92 
93  std::deque<CredentialInfo> GetCredentialQueue() {
94  // We move the data member value so the data member will be re-initiated
95  // with size 0, and ready for the next check.
96  MutexLock lock(&mu);
98  }
99  std::deque<ErrorInfo> GetErrorQueue() {
100  // We move the data member value so the data member will be re-initiated
101  // with size 0, and ready for the next check.
102  MutexLock lock(&mu);
103  return std::move(error_queue);
104  }
105  };
106 
108  TlsCertificatesWatcherInterface {
109  public:
110  // ctor sets state->watcher to this.
112  state_->watcher = this;
113  }
114 
115  // dtor sets state->watcher to nullptr.
116  ~TlsCertificatesTestWatcher() override { state_->watcher = nullptr; }
117 
120  absl::optional<PemKeyCertPairList> key_cert_pairs) override {
121  MutexLock lock(&state_->mu);
122  std::string updated_root;
123  if (root_certs.has_value()) {
124  updated_root = std::string(*root_certs);
125  }
126  PemKeyCertPairList updated_identity;
127  if (key_cert_pairs.has_value()) {
128  updated_identity = std::move(*key_cert_pairs);
129  }
130  state_->cert_update_queue.emplace_back(std::move(updated_root),
131  std::move(updated_identity));
132  }
133 
134  void OnError(grpc_error_handle root_cert_error,
135  grpc_error_handle identity_cert_error) override {
136  MutexLock lock(&state_->mu);
137  GPR_ASSERT(!GRPC_ERROR_IS_NONE(root_cert_error) ||
138  !GRPC_ERROR_IS_NONE(identity_cert_error));
139  std::string root_error_str;
140  std::string identity_error_str;
141  if (!GRPC_ERROR_IS_NONE(root_cert_error)) {
143  root_cert_error, GRPC_ERROR_STR_DESCRIPTION, &root_error_str));
144  }
145  if (!GRPC_ERROR_IS_NONE(identity_cert_error)) {
146  GPR_ASSERT(grpc_error_get_str(identity_cert_error,
148  &identity_error_str));
149  }
150  state_->error_queue.emplace_back(std::move(root_error_str),
151  std::move(identity_error_str));
152  GRPC_ERROR_UNREF(root_cert_error);
153  GRPC_ERROR_UNREF(identity_cert_error);
154  }
155 
156  private:
158  };
159 
160  void SetUp() override {
167  }
168 
171  absl::optional<std::string> root_cert_name,
172  absl::optional<std::string> identity_cert_name) {
173  MutexLock lock(&mu_);
174  distributor_ = distributor;
175  watchers_.emplace_back();
176  // TlsCertificatesTestWatcher ctor takes a pointer to the WatcherState.
177  // It sets WatcherState::watcher to point to itself.
178  // The TlsCertificatesTestWatcher dtor will set WatcherState::watcher back
179  // to nullptr to indicate that it's been destroyed.
180  auto watcher =
181  absl::make_unique<TlsCertificatesTestWatcher>(&watchers_.back());
183  std::move(root_cert_name),
184  std::move(identity_cert_name));
185  return &watchers_.back();
186  }
187 
189  MutexLock lock(&mu_);
191  EXPECT_EQ(state->watcher, nullptr);
192  }
193 
201  // Use a std::list<> here to avoid the address invalidation caused by internal
202  // reallocation of std::vector<>.
203  std::list<WatcherState> watchers_;
204  // This is to make watchers_ thread-safe.
206 };
207 
208 TEST_F(GrpcTlsCertificateProviderTest, StaticDataCertificateProviderCreation) {
210  root_cert_, MakeCertKeyPairs(private_key_.c_str(), cert_chain_.c_str()));
211  // Watcher watching both root and identity certs.
212  WatcherState* watcher_state_1 =
213  MakeWatcher(provider.distributor(), kCertName, kCertName);
214  EXPECT_THAT(watcher_state_1->GetCredentialQueue(),
215  ::testing::ElementsAre(CredentialInfo(
216  root_cert_, MakeCertKeyPairs(private_key_.c_str(),
217  cert_chain_.c_str()))));
218  CancelWatch(watcher_state_1);
219  // Watcher watching only root certs.
220  WatcherState* watcher_state_2 =
221  MakeWatcher(provider.distributor(), kCertName, absl::nullopt);
222  EXPECT_THAT(watcher_state_2->GetCredentialQueue(),
223  ::testing::ElementsAre(CredentialInfo(root_cert_, {})));
224  CancelWatch(watcher_state_2);
225  // Watcher watching only identity certs.
226  WatcherState* watcher_state_3 =
227  MakeWatcher(provider.distributor(), absl::nullopt, kCertName);
228  EXPECT_THAT(
229  watcher_state_3->GetCredentialQueue(),
230  ::testing::ElementsAre(CredentialInfo(
231  "", MakeCertKeyPairs(private_key_.c_str(), cert_chain_.c_str()))));
232  CancelWatch(watcher_state_3);
233 }
234 
236  FileWatcherCertificateProviderWithGoodPaths) {
238  CA_CERT_PATH, 1);
239  // Watcher watching both root and identity certs.
240  WatcherState* watcher_state_1 =
241  MakeWatcher(provider.distributor(), kCertName, kCertName);
242  EXPECT_THAT(watcher_state_1->GetCredentialQueue(),
243  ::testing::ElementsAre(CredentialInfo(
244  root_cert_, MakeCertKeyPairs(private_key_.c_str(),
245  cert_chain_.c_str()))));
246  CancelWatch(watcher_state_1);
247  // Watcher watching only root certs.
248  WatcherState* watcher_state_2 =
249  MakeWatcher(provider.distributor(), kCertName, absl::nullopt);
250  EXPECT_THAT(watcher_state_2->GetCredentialQueue(),
251  ::testing::ElementsAre(CredentialInfo(root_cert_, {})));
252  CancelWatch(watcher_state_2);
253  // Watcher watching only identity certs.
254  WatcherState* watcher_state_3 =
255  MakeWatcher(provider.distributor(), absl::nullopt, kCertName);
256  EXPECT_THAT(
257  watcher_state_3->GetCredentialQueue(),
258  ::testing::ElementsAre(CredentialInfo(
259  "", MakeCertKeyPairs(private_key_.c_str(), cert_chain_.c_str()))));
260  CancelWatch(watcher_state_3);
261 }
262 
264  FileWatcherCertificateProviderWithBadPaths) {
266  INVALID_PATH, 1);
267  // Watcher watching both root and identity certs.
268  WatcherState* watcher_state_1 =
269  MakeWatcher(provider.distributor(), kCertName, kCertName);
270  EXPECT_THAT(watcher_state_1->GetErrorQueue(),
272  EXPECT_THAT(watcher_state_1->GetCredentialQueue(), ::testing::ElementsAre());
273  CancelWatch(watcher_state_1);
274  // Watcher watching only root certs.
275  WatcherState* watcher_state_2 =
276  MakeWatcher(provider.distributor(), kCertName, absl::nullopt);
277  EXPECT_THAT(watcher_state_2->GetErrorQueue(),
278  ::testing::ElementsAre(ErrorInfo(kRootError, "")));
279  EXPECT_THAT(watcher_state_2->GetCredentialQueue(), ::testing::ElementsAre());
280  CancelWatch(watcher_state_2);
281  // Watcher watching only identity certs.
282  WatcherState* watcher_state_3 =
283  MakeWatcher(provider.distributor(), absl::nullopt, kCertName);
284  EXPECT_THAT(watcher_state_3->GetErrorQueue(),
285  ::testing::ElementsAre(ErrorInfo("", kIdentityError)));
286  EXPECT_THAT(watcher_state_3->GetCredentialQueue(), ::testing::ElementsAre());
287  CancelWatch(watcher_state_3);
288 }
289 
290 // The following tests write credential data to temporary files to test the
291 // transition behavior of the provider.
293  FileWatcherCertificateProviderOnBothCertsRefreshed) {
294  // Create temporary files and copy cert data into them.
295  TmpFile tmp_root_cert(root_cert_);
296  TmpFile tmp_identity_key(private_key_);
297  TmpFile tmp_identity_cert(cert_chain_);
298  // Create FileWatcherCertificateProvider.
299  FileWatcherCertificateProvider provider(tmp_identity_key.name(),
300  tmp_identity_cert.name(),
301  tmp_root_cert.name(), 1);
302  WatcherState* watcher_state_1 =
303  MakeWatcher(provider.distributor(), kCertName, kCertName);
304  // Expect to see the credential data.
305  EXPECT_THAT(watcher_state_1->GetCredentialQueue(),
306  ::testing::ElementsAre(CredentialInfo(
307  root_cert_, MakeCertKeyPairs(private_key_.c_str(),
308  cert_chain_.c_str()))));
309  // Copy new data to files.
310  // TODO(ZhenLian): right now it is not completely atomic. Use the real atomic
311  // update when the directory renaming is added in gpr.
312  tmp_root_cert.RewriteFile(root_cert_2_);
313  tmp_identity_key.RewriteFile(private_key_2_);
314  tmp_identity_cert.RewriteFile(cert_chain_2_);
315  // Wait 2 seconds for the provider's refresh thread to read the updated files.
318  // Expect to see the new credential data.
319  EXPECT_THAT(watcher_state_1->GetCredentialQueue(),
320  ::testing::ElementsAre(CredentialInfo(
321  root_cert_2_, MakeCertKeyPairs(private_key_2_.c_str(),
322  cert_chain_2_.c_str()))));
323  // Clean up.
324  CancelWatch(watcher_state_1);
325 }
326 
328  FileWatcherCertificateProviderOnRootCertsRefreshed) {
329  // Create temporary files and copy cert data into them.
330  TmpFile tmp_root_cert(root_cert_);
331  TmpFile tmp_identity_key(private_key_);
332  TmpFile tmp_identity_cert(cert_chain_);
333  // Create FileWatcherCertificateProvider.
334  FileWatcherCertificateProvider provider(tmp_identity_key.name(),
335  tmp_identity_cert.name(),
336  tmp_root_cert.name(), 1);
337  WatcherState* watcher_state_1 =
338  MakeWatcher(provider.distributor(), kCertName, kCertName);
339  // Expect to see the credential data.
340  EXPECT_THAT(watcher_state_1->GetCredentialQueue(),
341  ::testing::ElementsAre(CredentialInfo(
342  root_cert_, MakeCertKeyPairs(private_key_.c_str(),
343  cert_chain_.c_str()))));
344  // Copy new data to files.
345  // TODO(ZhenLian): right now it is not completely atomic. Use the real atomic
346  // update when the directory renaming is added in gpr.
347  tmp_root_cert.RewriteFile(root_cert_2_);
348  // Wait 2 seconds for the provider's refresh thread to read the updated files.
351  // Expect to see the new credential data.
352  EXPECT_THAT(watcher_state_1->GetCredentialQueue(),
353  ::testing::ElementsAre(CredentialInfo(
354  root_cert_2_, MakeCertKeyPairs(private_key_.c_str(),
355  cert_chain_.c_str()))));
356  // Clean up.
357  CancelWatch(watcher_state_1);
358 }
359 
361  FileWatcherCertificateProviderOnIdentityCertsRefreshed) {
362  // Create temporary files and copy cert data into them.
363  TmpFile tmp_root_cert(root_cert_);
364  TmpFile tmp_identity_key(private_key_);
365  TmpFile tmp_identity_cert(cert_chain_);
366  // Create FileWatcherCertificateProvider.
367  FileWatcherCertificateProvider provider(tmp_identity_key.name(),
368  tmp_identity_cert.name(),
369  tmp_root_cert.name(), 1);
370  WatcherState* watcher_state_1 =
371  MakeWatcher(provider.distributor(), kCertName, kCertName);
372  // Expect to see the credential data.
373  EXPECT_THAT(watcher_state_1->GetCredentialQueue(),
374  ::testing::ElementsAre(CredentialInfo(
375  root_cert_, MakeCertKeyPairs(private_key_.c_str(),
376  cert_chain_.c_str()))));
377  // Copy new data to files.
378  // TODO(ZhenLian): right now it is not completely atomic. Use the real atomic
379  // update when the directory renaming is added in gpr.
380  tmp_identity_key.RewriteFile(private_key_2_);
381  tmp_identity_cert.RewriteFile(cert_chain_2_);
382  // Wait 2 seconds for the provider's refresh thread to read the updated files.
385  // Expect to see the new credential data.
386  EXPECT_THAT(watcher_state_1->GetCredentialQueue(),
387  ::testing::ElementsAre(CredentialInfo(
388  root_cert_, MakeCertKeyPairs(private_key_2_.c_str(),
389  cert_chain_2_.c_str()))));
390  // Clean up.
391  CancelWatch(watcher_state_1);
392 }
393 
395  FileWatcherCertificateProviderWithGoodAtFirstThenDeletedBothCerts) {
396  // Create temporary files and copy cert data into it.
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_);
400  // Create FileWatcherCertificateProvider.
401  FileWatcherCertificateProvider provider(tmp_identity_key->name(),
402  tmp_identity_cert->name(),
403  tmp_root_cert->name(), 1);
404  WatcherState* watcher_state_1 =
405  MakeWatcher(provider.distributor(), kCertName, kCertName);
406  // The initial data is all good, so we expect to have successful credential
407  // updates.
408  EXPECT_THAT(watcher_state_1->GetCredentialQueue(),
409  ::testing::ElementsAre(CredentialInfo(
410  root_cert_, MakeCertKeyPairs(private_key_.c_str(),
411  cert_chain_.c_str()))));
412  // Delete TmpFile objects, which will remove the corresponding files.
413  tmp_root_cert.reset();
414  tmp_identity_key.reset();
415  tmp_identity_cert.reset();
416  // Wait 2 seconds for the provider's refresh thread to read the deleted files.
419  // Expect to see errors sent to watchers, and no credential updates.
420  // We have no ideas on how many errors we will receive, so we only check once.
421  EXPECT_THAT(watcher_state_1->GetErrorQueue(),
423  EXPECT_THAT(watcher_state_1->GetCredentialQueue(), ::testing::ElementsAre());
424  // Clean up.
425  CancelWatch(watcher_state_1);
426 }
427 
429  FileWatcherCertificateProviderWithGoodAtFirstThenDeletedRootCerts) {
430  // Create temporary files and copy cert data into it.
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_);
434  // Create FileWatcherCertificateProvider.
435  FileWatcherCertificateProvider provider(tmp_identity_key.name(),
436  tmp_identity_cert.name(),
437  tmp_root_cert->name(), 1);
438  WatcherState* watcher_state_1 =
439  MakeWatcher(provider.distributor(), kCertName, kCertName);
440  // The initial data is all good, so we expect to have successful credential
441  // updates.
442  EXPECT_THAT(watcher_state_1->GetCredentialQueue(),
443  ::testing::ElementsAre(CredentialInfo(
444  root_cert_, MakeCertKeyPairs(private_key_.c_str(),
445  cert_chain_.c_str()))));
446  // Delete root TmpFile object, which will remove the corresponding file.
447  tmp_root_cert.reset();
448  // Wait 2 seconds for the provider's refresh thread to read the deleted files.
451  // Expect to see errors sent to watchers, and no credential updates.
452  // We have no ideas on how many errors we will receive, so we only check once.
453  EXPECT_THAT(watcher_state_1->GetErrorQueue(),
454  ::testing::Contains(ErrorInfo(kRootError, "")));
455  EXPECT_THAT(watcher_state_1->GetCredentialQueue(), ::testing::ElementsAre());
456  // Clean up.
457  CancelWatch(watcher_state_1);
458 }
459 
461  FileWatcherCertificateProviderWithGoodAtFirstThenDeletedIdentityCerts) {
462  // Create temporary files and copy cert data into it.
463  TmpFile tmp_root_cert(root_cert_);
464  auto tmp_identity_key = absl::make_unique<TmpFile>(private_key_);
465  auto tmp_identity_cert = absl::make_unique<TmpFile>(cert_chain_);
466  // Create FileWatcherCertificateProvider.
467  FileWatcherCertificateProvider provider(tmp_identity_key->name(),
468  tmp_identity_cert->name(),
469  tmp_root_cert.name(), 1);
470  WatcherState* watcher_state_1 =
471  MakeWatcher(provider.distributor(), kCertName, kCertName);
472  // The initial data is all good, so we expect to have successful credential
473  // updates.
474  EXPECT_THAT(watcher_state_1->GetCredentialQueue(),
475  ::testing::ElementsAre(CredentialInfo(
476  root_cert_, MakeCertKeyPairs(private_key_.c_str(),
477  cert_chain_.c_str()))));
478  // Delete identity TmpFile objects, which will remove the corresponding files.
479  tmp_identity_key.reset();
480  tmp_identity_cert.reset();
481  // Wait 2 seconds for the provider's refresh thread to read the deleted files.
484  // Expect to see errors sent to watchers, and no credential updates.
485  // We have no ideas on how many errors we will receive, so we only check once.
486  EXPECT_THAT(watcher_state_1->GetErrorQueue(),
487  ::testing::Contains(ErrorInfo("", kIdentityError)));
488  EXPECT_THAT(watcher_state_1->GetCredentialQueue(), ::testing::ElementsAre());
489  // Clean up.
490  CancelWatch(watcher_state_1);
491 }
492 
493 TEST_F(GrpcTlsCertificateProviderTest, FailedKeyCertMatchOnEmptyPrivateKey) {
495  PrivateKeyAndCertificateMatch(/*private_key=*/"", cert_chain_);
498  EXPECT_EQ(status.status().message(), "Private key string is empty.");
499 }
500 
501 TEST_F(GrpcTlsCertificateProviderTest, FailedKeyCertMatchOnEmptyCertificate) {
503  PrivateKeyAndCertificateMatch(private_key_2_, /*cert_chain=*/"");
506  EXPECT_EQ(status.status().message(), "Certificate string is empty.");
507 }
508 
509 TEST_F(GrpcTlsCertificateProviderTest, FailedKeyCertMatchOnInvalidCertFormat) {
511  PrivateKeyAndCertificateMatch(private_key_2_, "invalid_certificate");
514  EXPECT_EQ(status.status().message(),
515  "Conversion from PEM string to X509 failed.");
516 }
517 
519  FailedKeyCertMatchOnInvalidPrivateKeyFormat) {
521  PrivateKeyAndCertificateMatch("invalid_private_key", cert_chain_2_);
523  EXPECT_EQ(status.status().message(),
524  "Conversion from PEM string to EVP_PKEY failed.");
525 }
526 
527 TEST_F(GrpcTlsCertificateProviderTest, SuccessfulKeyCertMatch) {
529  PrivateKeyAndCertificateMatch(private_key_2_, cert_chain_2_);
530  EXPECT_TRUE(status.ok());
532 }
533 
534 TEST_F(GrpcTlsCertificateProviderTest, FailedKeyCertMatchOnInvalidPair) {
536  PrivateKeyAndCertificateMatch(private_key_2_, cert_chain_);
537  EXPECT_TRUE(status.ok());
539 }
540 
541 } // namespace testing
542 } // namespace grpc_core
543 
544 int main(int argc, char** argv) {
545  grpc::testing::TestEnvironment env(&argc, argv);
546  ::testing::InitGoogleTest(&argc, argv);
547  grpc_init();
548  int ret = RUN_ALL_TESTS();
549  grpc_shutdown();
550  return ret;
551 }
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1970
grpc_core::testing::TmpFile
Definition: test/core/util/tls_utils.h:27
GPR_TIMESPAN
@ GPR_TIMESPAN
Definition: gpr_types.h:45
grpc_core::testing::GrpcTlsCertificateProviderTest::cert_chain_2_
std::string cert_chain_2_
Definition: grpc_tls_certificate_provider_test.cc:199
testing
Definition: aws_request_signer_test.cc:25
grpc_core::testing::GrpcTlsCertificateProviderTest::mu_
Mutex mu_
Definition: grpc_tls_certificate_provider_test.cc:205
log.h
grpc_core::testing::MakeCertKeyPairs
PemKeyCertPairList MakeCertKeyPairs(absl::string_view private_key, absl::string_view certs)
Definition: test/core/util/tls_utils.cc:60
tls_utils.h
generate.env
env
Definition: generate.py:37
grpc_core::testing::GrpcTlsCertificateProviderTest
Definition: grpc_tls_certificate_provider_test.cc:52
load_file.h
grpc_core::testing::GrpcTlsCertificateProviderTest::WatcherState::watcher
TlsCertificatesTestWatcher * watcher
Definition: grpc_tls_certificate_provider_test.cc:88
EXPECT_THAT
#define EXPECT_THAT(value, matcher)
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::MutexLock
Definition: src/core/lib/gprpp/sync.h:88
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_core::testing::GrpcTlsCertificateProviderTest::private_key_
std::string private_key_
Definition: grpc_tls_certificate_provider_test.cc:195
grpc_core::testing::GrpcTlsCertificateProviderTest::watchers_
std::list< WatcherState > watchers_
Definition: grpc_tls_certificate_provider_test.cc:203
grpc_tls_certificate_distributor
Definition: grpc_tls_certificate_distributor.h:43
status
absl::Status status
Definition: rls.cc:251
grpc_core::FileWatcherCertificateProvider::distributor
RefCountedPtr< grpc_tls_certificate_distributor > distributor() const override
Definition: grpc_tls_certificate_provider.h:140
grpc_core::testing::TEST_F
TEST_F(ServiceConfigTest, ErrorCheck1)
Definition: service_config_test.cc:192
GRPC_ERROR_STR_DESCRIPTION
@ GRPC_ERROR_STR_DESCRIPTION
top-level textual description of this error
Definition: error.h:106
grpc_core::testing::GrpcTlsCertificateProviderTest::WatcherState::mu
Mutex mu
Definition: grpc_tls_certificate_provider_test.cc:91
grpc_core::testing::kRootError
constexpr const char * kRootError
Definition: grpc_tls_certificate_provider_test.cc:48
grpc_core::testing::GrpcTlsCertificateProviderTest::ErrorInfo::operator==
bool operator==(const ErrorInfo &other) const
Definition: grpc_tls_certificate_provider_test.cc:81
grpc_core::testing::GrpcTlsCertificateProviderTest::ErrorInfo::root_cert_str
std::string root_cert_str
Definition: grpc_tls_certificate_provider_test.cc:76
testing::Test
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:402
grpc_core::testing::kCertName
constexpr const char * kCertName
Definition: grpc_tls_certificate_provider_test.cc:47
grpc_tls_certificate_distributor::WatchTlsCertificates
void WatchTlsCertificates(std::unique_ptr< TlsCertificatesWatcherInterface > watcher, absl::optional< std::string > root_cert_name, absl::optional< std::string > identity_cert_name)
Definition: grpc_tls_certificate_distributor.cc:176
grpc_core::testing::TmpFile::RewriteFile
void RewriteFile(absl::string_view data)
Definition: test/core/util/tls_utils.cc:37
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
testing::ElementsAre
internal::ElementsAreMatcher< ::testing::tuple<> > ElementsAre()
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:13040
INVALID_PATH
#define INVALID_PATH
Definition: grpc_tls_certificate_provider_test.cc:41
grpc_core::testing::GrpcTlsCertificateProviderTest::ErrorInfo::ErrorInfo
ErrorInfo(std::string root, std::string identity)
Definition: grpc_tls_certificate_provider_test.cc:78
string_util.h
grpc_core::testing::GrpcTlsCertificateProviderTest::CredentialInfo::key_cert_pairs
PemKeyCertPairList key_cert_pairs
Definition: grpc_tls_certificate_provider_test.cc:63
root_cert_
std::string root_cert_
Definition: xds_end2end_test.cc:415
grpc_tls_certificate_provider.h
grpc_core::RefCountedPtr< grpc_tls_certificate_distributor >
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
absl::optional::has_value
constexpr bool has_value() const noexcept
Definition: abseil-cpp/absl/types/optional.h:461
root
RefCountedPtr< grpc_tls_certificate_provider > root
Definition: xds_server_config_fetcher.cc:223
grpc_core::testing::GrpcTlsCertificateProviderTest::CredentialInfo
Definition: grpc_tls_certificate_provider_test.cc:61
SERVER_KEY_PATH_2
#define SERVER_KEY_PATH_2
Definition: grpc_tls_certificate_provider_test.cc:40
grpc_core::testing::GrpcTlsCertificateProviderTest::TlsCertificatesTestWatcher::OnCertificatesChanged
void OnCertificatesChanged(absl::optional< absl::string_view > root_certs, absl::optional< PemKeyCertPairList > key_cert_pairs) override
Definition: grpc_tls_certificate_provider_test.cc:118
SERVER_CERT_PATH
#define SERVER_CERT_PATH
Definition: grpc_tls_certificate_provider_test.cc:36
gpr_sleep_until
GPRAPI void gpr_sleep_until(gpr_timespec until)
absl::Status::message
absl::string_view message() const
Definition: third_party/abseil-cpp/absl/status/status.h:806
grpc_core::testing::GrpcTlsCertificateProviderTest::SetUp
void SetUp() override
Definition: grpc_tls_certificate_provider_test.cc:160
tmpfile.h
absl::optional< absl::string_view >
SERVER_CERT_PATH_2
#define SERVER_CERT_PATH_2
Definition: grpc_tls_certificate_provider_test.cc:39
grpc_core::testing::GrpcTlsCertificateProviderTest::TlsCertificatesTestWatcher::~TlsCertificatesTestWatcher
~TlsCertificatesTestWatcher() override
Definition: grpc_tls_certificate_provider_test.cc:116
grpc_core::testing::GrpcTlsCertificateProviderTest::TlsCertificatesTestWatcher
Definition: grpc_tls_certificate_provider_test.cc:107
GPR_CLOCK_MONOTONIC
@ GPR_CLOCK_MONOTONIC
Definition: gpr_types.h:36
grpc_core::testing::GrpcTlsCertificateProviderTest::distributor_
RefCountedPtr< grpc_tls_certificate_distributor > distributor_
Definition: grpc_tls_certificate_provider_test.cc:200
slice_internal.h
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
gpr_now
GPRAPI gpr_timespec gpr_now(gpr_clock_type clock)
grpc_core::PrivateKeyAndCertificateMatch
absl::StatusOr< bool > PrivateKeyAndCertificateMatch(absl::string_view private_key, absl::string_view cert_chain)
Definition: grpc_tls_certificate_provider.cc:397
grpc_core::testing::TmpFile::name
const std::string & name()
Definition: test/core/util/tls_utils.h:34
absl::StatusCode::kInvalidArgument
@ kInvalidArgument
test_config.h
grpc_core::Mutex
Definition: src/core/lib/gprpp/sync.h:61
grpc_tls_certificate_distributor::CancelTlsCertificatesWatch
void CancelTlsCertificatesWatch(TlsCertificatesWatcherInterface *watcher)
Definition: grpc_tls_certificate_distributor.cc:264
grpc_core::testing::GrpcTlsCertificateProviderTest::WatcherState
Definition: grpc_tls_certificate_provider_test.cc:87
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
grpc_core::StaticDataCertificateProvider::distributor
RefCountedPtr< grpc_tls_certificate_distributor > distributor() const override
Definition: grpc_tls_certificate_provider.h:101
grpc_core::testing::GrpcTlsCertificateProviderTest::CancelWatch
void CancelWatch(WatcherState *state)
Definition: grpc_tls_certificate_provider_test.cc:188
grpc_core::testing::GrpcTlsCertificateProviderTest::ErrorInfo
Definition: grpc_tls_certificate_provider_test.cc:75
grpc_core::testing::GrpcTlsCertificateProviderTest::root_cert_2_
std::string root_cert_2_
Definition: grpc_tls_certificate_provider_test.cc:197
gpr_time_add
GPRAPI gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b)
Definition: src/core/lib/gpr/time.cc:135
grpc_core::PemKeyCertPairList
std::vector< PemKeyCertPair > PemKeyCertPairList
Definition: ssl_utils.h:183
grpc_core::testing::GrpcTlsCertificateProviderTest::TlsCertificatesTestWatcher::OnError
void OnError(grpc_error_handle root_cert_error, grpc_error_handle identity_cert_error) override
Definition: grpc_tls_certificate_provider_test.cc:134
main
int main(int argc, char **argv)
Definition: grpc_tls_certificate_provider_test.cc:544
SERVER_KEY_PATH
#define SERVER_KEY_PATH
Definition: grpc_tls_certificate_provider_test.cc:37
grpc_core::testing::GrpcTlsCertificateProviderTest::cert_chain_
std::string cert_chain_
Definition: grpc_tls_certificate_provider_test.cc:196
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
alloc.h
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
CA_CERT_PATH_2
#define CA_CERT_PATH_2
Definition: grpc_tls_certificate_provider_test.cc:38
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
absl::Status::ok
ABSL_MUST_USE_RESULT bool ok() const
Definition: third_party/abseil-cpp/absl/status/status.h:802
grpc_core::testing::GrpcTlsCertificateProviderTest::WatcherState::GetErrorQueue
std::deque< ErrorInfo > GetErrorQueue()
Definition: grpc_tls_certificate_provider_test.cc:99
GRPC_ERROR_UNREF
#define GRPC_ERROR_UNREF(err)
Definition: error.h:262
grpc_core::StaticDataCertificateProvider
Definition: grpc_tls_certificate_provider.h:93
grpc_core::testing::GrpcTlsCertificateProviderTest::ErrorInfo::identity_cert_str
std::string identity_cert_str
Definition: grpc_tls_certificate_provider_test.cc:77
watcher
ClusterWatcher * watcher
Definition: cds.cc:148
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1967
grpc_core::testing::GrpcTlsCertificateProviderTest::TlsCertificatesTestWatcher::TlsCertificatesTestWatcher
TlsCertificatesTestWatcher(WatcherState *state)
Definition: grpc_tls_certificate_provider_test.cc:111
grpc_core::testing::GrpcTlsCertificateProviderTest::TlsCertificatesTestWatcher::state_
WatcherState * state_
Definition: grpc_tls_certificate_provider_test.cc:157
grpc_core::FileWatcherCertificateProvider
Definition: grpc_tls_certificate_provider.h:130
absl::StatusOr
Definition: abseil-cpp/absl/status/statusor.h:187
grpc_error_get_str
bool grpc_error_get_str(grpc_error_handle err, grpc_error_strs which, std::string *s)
Returns false if the specified string is not set.
Definition: error.cc:659
grpc_core::testing::GrpcTlsCertificateProviderTest::WatcherState::GetCredentialQueue
std::deque< CredentialInfo > GetCredentialQueue()
Definition: grpc_tls_certificate_provider_test.cc:93
grpc_init
GRPCAPI void grpc_init(void)
Definition: init.cc:146
grpc_error
Definition: error_internal.h:42
grpc_core::testing::GrpcTlsCertificateProviderTest::MakeWatcher
WatcherState * MakeWatcher(RefCountedPtr< grpc_tls_certificate_distributor > distributor, absl::optional< std::string > root_cert_name, absl::optional< std::string > identity_cert_name)
Definition: grpc_tls_certificate_provider_test.cc:169
CA_CERT_PATH
#define CA_CERT_PATH
Definition: grpc_tls_certificate_provider_test.cc:35
grpc_core::testing::GrpcTlsCertificateProviderTest::root_cert_
std::string root_cert_
Definition: grpc_tls_certificate_provider_test.cc:194
grpc_core::testing::GrpcTlsCertificateProviderTest::WatcherState::cert_update_queue
std::deque< CredentialInfo > cert_update_queue
Definition: grpc_tls_certificate_provider_test.cc:89
absl::Status::code
absl::StatusCode code() const
Definition: third_party/abseil-cpp/absl/status/status.cc:233
grpc_core::testing::GrpcTlsCertificateProviderTest::private_key_2_
std::string private_key_2_
Definition: grpc_tls_certificate_provider_test.cc:198
grpc_core::testing::GetFileContents
std::string GetFileContents(const char *path)
Definition: test/core/util/tls_utils.cc:68
testing::Contains
internal::ContainsMatcher< M > Contains(M matcher)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:9101
grpc_core::testing::GrpcTlsCertificateProviderTest::WatcherState::error_queue
std::deque< ErrorInfo > error_queue
Definition: grpc_tls_certificate_provider_test.cc:90
grpc_shutdown
GRPCAPI void grpc_shutdown(void)
Definition: init.cc:209
grpc_core::testing::kIdentityError
constexpr const char * kIdentityError
Definition: grpc_tls_certificate_provider_test.cc:49
grpc_core::testing::GrpcTlsCertificateProviderTest::CredentialInfo::operator==
bool operator==(const CredentialInfo &other) const
Definition: grpc_tls_certificate_provider_test.cc:66
grpc_core::testing::GrpcTlsCertificateProviderTest::CredentialInfo::CredentialInfo
CredentialInfo(std::string root, PemKeyCertPairList key_cert)
Definition: grpc_tls_certificate_provider_test.cc:64
gpr_time_from_seconds
GPRAPI gpr_timespec gpr_time_from_seconds(int64_t s, gpr_clock_type clock_type)
Definition: src/core/lib/gpr/time.cc:123
GRPC_ERROR_IS_NONE
#define GRPC_ERROR_IS_NONE(err)
Definition: error.h:241
grpc_core::testing::GrpcTlsCertificateProviderTest::CredentialInfo::root_certs
std::string root_certs
Definition: grpc_tls_certificate_provider_test.cc:62


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:45