Add forgotten callback function for server authorization check.

pull/19778/head
Matthew Stevenson 5 years ago
parent e37836b0c7
commit 967b911f85
  1. 16
      include/grpcpp/security/tls_credentials_options.h
  2. 45
      src/cpp/common/tls_credentials_options.cc
  3. 89
      test/cpp/client/credentials_test.cc

@ -48,7 +48,7 @@ class TlsKeyMaterialsConfig {
* transfers ownership of the arguments to the config. **/ * transfers ownership of the arguments to the config. **/
void set_key_materials(grpc::string pem_root_certs, void set_key_materials(grpc::string pem_root_certs,
std::vector<PemKeyCertPair> pem_key_cert_pair_list); std::vector<PemKeyCertPair> pem_key_cert_pair_list);
void set_version(int version) { version_ = version;}; void set_version(int version) { version_ = version; };
private: private:
int version_; int version_;
@ -63,7 +63,6 @@ grpc_tls_key_materials_config* c_key_materials(
std::shared_ptr<TlsKeyMaterialsConfig> tls_key_materials_c_to_cpp( std::shared_ptr<TlsKeyMaterialsConfig> tls_key_materials_c_to_cpp(
const grpc_tls_key_materials_config* config); const grpc_tls_key_materials_config* config);
/** TLS credential reload arguments, wraps grpc_tls_credential_reload_arg. **/ /** TLS credential reload arguments, wraps grpc_tls_credential_reload_arg. **/
class TlsCredentialReloadArg { class TlsCredentialReloadArg {
public: public:
@ -80,7 +79,7 @@ class TlsCredentialReloadArg {
/** Setters for member fields. **/ /** Setters for member fields. **/
void set_cb_user_data(void* cb_user_data); void set_cb_user_data(void* cb_user_data);
void set_key_materials_config( void set_key_materials_config(
std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config); const std::shared_ptr<TlsKeyMaterialsConfig>& key_materials_config);
void set_status(grpc_ssl_certificate_config_reload_status status); void set_status(grpc_ssl_certificate_config_reload_status status);
void set_error_details(const grpc::string& error_details); void set_error_details(const grpc::string& error_details);
@ -167,9 +166,8 @@ class TlsServerAuthorizationCheckArg {
// Exposed for testing purposes. // Exposed for testing purposes.
int tls_server_authorization_check_config_c_schedule( int tls_server_authorization_check_config_c_schedule(
void* config_user_data, grpc_tls_server_authorization_check_arg* arg); void* config_user_data, grpc_tls_server_authorization_check_arg* arg);
void tls_server_authorization_check_config_c_cancel(void* config_user_data, void tls_server_authorization_check_config_c_cancel(
grpc_tls_server_authorization_check_arg* arg); void* config_user_data, grpc_tls_server_authorization_check_arg* arg);
/** TLS server authorization check config, wraps /** TLS server authorization check config, wraps
* grps_tls_server_authorization_check_config. **/ * grps_tls_server_authorization_check_config. **/
@ -197,7 +195,8 @@ class TlsServerAuthorizationCheckConfig {
} }
/** Creates C struct for the credential reload config. **/ /** Creates C struct for the credential reload config. **/
grpc_tls_server_authorization_check_config* c_server_authorization_check() const { grpc_tls_server_authorization_check_config* c_server_authorization_check()
const {
return c_config_; return c_config_;
} }
@ -219,8 +218,7 @@ class TlsCredentialsOptions {
std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config() const { std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config() const {
return key_materials_config_; return key_materials_config_;
} }
std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config() std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config() const {
const {
return credential_reload_config_; return credential_reload_config_;
} }
std::shared_ptr<TlsServerAuthorizationCheckConfig> std::shared_ptr<TlsServerAuthorizationCheckConfig>

@ -32,13 +32,15 @@ void TlsKeyMaterialsConfig::set_key_materials(
} }
/** Creates a new C struct for the key materials. **/ /** Creates a new C struct for the key materials. **/
grpc_tls_key_materials_config* c_key_materials(const std::shared_ptr<TlsKeyMaterialsConfig>& config) { grpc_tls_key_materials_config* c_key_materials(
const std::shared_ptr<TlsKeyMaterialsConfig>& config) {
grpc_tls_key_materials_config* c_config = grpc_tls_key_materials_config* c_config =
grpc_tls_key_materials_config_create(); grpc_tls_key_materials_config_create();
::grpc_core::InlinedVector<::grpc_core::PemKeyCertPair, 1> ::grpc_core::InlinedVector<::grpc_core::PemKeyCertPair, 1>
c_pem_key_cert_pair_list; c_pem_key_cert_pair_list;
for (auto key_cert_pair = config->pem_key_cert_pair_list().begin(); for (auto key_cert_pair = config->pem_key_cert_pair_list().begin();
key_cert_pair != config->pem_key_cert_pair_list().end(); key_cert_pair++) { key_cert_pair != config->pem_key_cert_pair_list().end();
key_cert_pair++) {
grpc_ssl_pem_key_cert_pair* ssl_pair = grpc_ssl_pem_key_cert_pair* ssl_pair =
(grpc_ssl_pem_key_cert_pair*)gpr_malloc( (grpc_ssl_pem_key_cert_pair*)gpr_malloc(
sizeof(grpc_ssl_pem_key_cert_pair)); sizeof(grpc_ssl_pem_key_cert_pair));
@ -48,7 +50,8 @@ grpc_tls_key_materials_config* c_key_materials(const std::shared_ptr<TlsKeyMater
::grpc_core::PemKeyCertPair(ssl_pair); ::grpc_core::PemKeyCertPair(ssl_pair);
c_pem_key_cert_pair_list.push_back(::std::move(c_pem_key_cert_pair)); c_pem_key_cert_pair_list.push_back(::std::move(c_pem_key_cert_pair));
} }
::grpc_core::UniquePtr<char> c_pem_root_certs(gpr_strdup(config->pem_root_certs().c_str())); ::grpc_core::UniquePtr<char> c_pem_root_certs(
gpr_strdup(config->pem_root_certs().c_str()));
c_config->set_key_materials(std::move(c_pem_root_certs), c_config->set_key_materials(std::move(c_pem_root_certs),
std::move(c_pem_key_cert_pair_list)); std::move(c_pem_key_cert_pair_list));
c_config->set_version(config->version()); c_config->set_version(config->version());
@ -60,8 +63,7 @@ std::shared_ptr<TlsKeyMaterialsConfig> tls_key_materials_c_to_cpp(
const grpc_tls_key_materials_config* config) { const grpc_tls_key_materials_config* config) {
std::shared_ptr<TlsKeyMaterialsConfig> cpp_config( std::shared_ptr<TlsKeyMaterialsConfig> cpp_config(
new TlsKeyMaterialsConfig()); new TlsKeyMaterialsConfig());
std::vector<TlsKeyMaterialsConfig::PemKeyCertPair> std::vector<TlsKeyMaterialsConfig::PemKeyCertPair> cpp_pem_key_cert_pair_list;
cpp_pem_key_cert_pair_list;
grpc_tls_key_materials_config::PemKeyCertPairList pem_key_cert_pair_list = grpc_tls_key_materials_config::PemKeyCertPairList pem_key_cert_pair_list =
config->pem_key_cert_pair_list(); config->pem_key_cert_pair_list();
for (size_t i = 0; i < pem_key_cert_pair_list.size(); i++) { for (size_t i = 0; i < pem_key_cert_pair_list.size(); i++) {
@ -71,9 +73,8 @@ std::shared_ptr<TlsKeyMaterialsConfig> tls_key_materials_c_to_cpp(
gpr_strdup(key_cert_pair.cert_chain())}; gpr_strdup(key_cert_pair.cert_chain())};
cpp_pem_key_cert_pair_list.push_back(::std::move(p)); cpp_pem_key_cert_pair_list.push_back(::std::move(p));
} }
cpp_config->set_key_materials( cpp_config->set_key_materials(std::move(gpr_strdup(config->pem_root_certs())),
std::move(gpr_strdup(config->pem_root_certs())), std::move(cpp_pem_key_cert_pair_list));
std::move(cpp_pem_key_cert_pair_list));
cpp_config->set_version(config->version()); cpp_config->set_version(config->version());
return cpp_config; return cpp_config;
} }
@ -95,16 +96,19 @@ void* TlsCredentialReloadArg::cb_user_data() const {
/** This function creates a new TlsKeyMaterialsConfig instance whose fields are /** This function creates a new TlsKeyMaterialsConfig instance whose fields are
* not shared with the corresponding key materials config fields of the * not shared with the corresponding key materials config fields of the
* TlsCredentialReloadArg instance. **/ * TlsCredentialReloadArg instance. **/
std::shared_ptr<TlsKeyMaterialsConfig> TlsCredentialReloadArg::key_materials_config() const { std::shared_ptr<TlsKeyMaterialsConfig>
TlsCredentialReloadArg::key_materials_config() const {
return tls_key_materials_c_to_cpp(c_arg_.key_materials_config); return tls_key_materials_c_to_cpp(c_arg_.key_materials_config);
} }
grpc_ssl_certificate_config_reload_status TlsCredentialReloadArg::status() const { grpc_ssl_certificate_config_reload_status TlsCredentialReloadArg::status()
const {
return c_arg_.status; return c_arg_.status;
} }
std::shared_ptr<grpc::string> TlsCredentialReloadArg::error_details() const { std::shared_ptr<grpc::string> TlsCredentialReloadArg::error_details() const {
std::shared_ptr<grpc::string> cpp_error_details(new grpc::string(c_arg_.error_details)); std::shared_ptr<grpc::string> cpp_error_details(
new grpc::string(c_arg_.error_details));
return cpp_error_details; return cpp_error_details;
} }
@ -113,7 +117,7 @@ void TlsCredentialReloadArg::set_cb_user_data(void* cb_user_data) {
} }
void TlsCredentialReloadArg::set_key_materials_config( void TlsCredentialReloadArg::set_key_materials_config(
std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config) { const std::shared_ptr<TlsKeyMaterialsConfig>& key_materials_config) {
c_arg_.key_materials_config = c_key_materials(key_materials_config); c_arg_.key_materials_config = c_key_materials(key_materials_config);
} }
@ -122,13 +126,12 @@ void TlsCredentialReloadArg::set_status(
c_arg_.status = status; c_arg_.status = status;
} }
void TlsCredentialReloadArg::set_error_details(const grpc::string& error_details) { void TlsCredentialReloadArg::set_error_details(
const grpc::string& error_details) {
c_arg_.error_details = gpr_strdup(error_details.c_str()); c_arg_.error_details = gpr_strdup(error_details.c_str());
} }
void TlsCredentialReloadArg::callback() { void TlsCredentialReloadArg::callback() { c_arg_.cb(&c_arg_); }
c_arg_.cb(&c_arg_);
}
/** The C schedule and cancel functions for the credential reload config. **/ /** The C schedule and cancel functions for the credential reload config. **/
int tls_credential_reload_config_c_schedule( int tls_credential_reload_config_c_schedule(
@ -211,7 +214,7 @@ grpc_status_code TlsServerAuthorizationCheckArg::status() const {
std::shared_ptr<grpc::string> TlsServerAuthorizationCheckArg::error_details() std::shared_ptr<grpc::string> TlsServerAuthorizationCheckArg::error_details()
const { const {
std::shared_ptr<grpc::string> cpp_error_details( std::shared_ptr<grpc::string> cpp_error_details(
new grpc::string(c_arg_.error_details)); new grpc::string(c_arg_.error_details));
return cpp_error_details; return cpp_error_details;
} }
@ -242,6 +245,8 @@ void TlsServerAuthorizationCheckArg::set_error_details(
c_arg_.error_details = gpr_strdup(error_details.c_str()); c_arg_.error_details = gpr_strdup(error_details.c_str());
} }
void TlsServerAuthorizationCheckArg::callback() { c_arg_.cb(&c_arg_); }
/** The C schedule and cancel functions for the credential reload config. **/ /** The C schedule and cancel functions for the credential reload config. **/
int tls_server_authorization_check_config_c_schedule( int tls_server_authorization_check_config_c_schedule(
void* config_user_data, grpc_tls_server_authorization_check_arg* arg) { void* config_user_data, grpc_tls_server_authorization_check_arg* arg) {
@ -282,14 +287,13 @@ TlsServerAuthorizationCheckConfig::TlsServerAuthorizationCheckConfig(
config_user_data_ = const_cast<void*>(config_user_data); config_user_data_ = const_cast<void*>(config_user_data);
schedule_ = schedule; schedule_ = schedule;
cancel_ = cancel; cancel_ = cancel;
destruct_ = destruct; destruct_ = destruct;
c_config_ = grpc_tls_server_authorization_check_config_create( c_config_ = grpc_tls_server_authorization_check_config_create(
config_user_data_, &tls_server_authorization_check_config_c_schedule, config_user_data_, &tls_server_authorization_check_config_c_schedule,
&tls_server_authorization_check_config_c_cancel, destruct_); &tls_server_authorization_check_config_c_cancel, destruct_);
c_config_->set_context(static_cast<void*>(this)); c_config_->set_context(static_cast<void*>(this));
} }
TlsServerAuthorizationCheckConfig::~TlsServerAuthorizationCheckConfig() {} TlsServerAuthorizationCheckConfig::~TlsServerAuthorizationCheckConfig() {}
/** gRPC TLS credential options API implementation **/ /** gRPC TLS credential options API implementation **/
@ -299,7 +303,8 @@ grpc_tls_credentials_options* TlsCredentialsOptions::c_credentials_options()
grpc_tls_credentials_options_create(); grpc_tls_credentials_options_create();
c_options->set_cert_request_type(cert_request_type_); c_options->set_cert_request_type(cert_request_type_);
c_options->set_key_materials_config( c_options->set_key_materials_config(
::grpc_core::RefCountedPtr<grpc_tls_key_materials_config>(c_key_materials(key_materials_config_))); ::grpc_core::RefCountedPtr<grpc_tls_key_materials_config>(
c_key_materials(key_materials_config_)));
c_options->set_credential_reload_config( c_options->set_credential_reload_config(
::grpc_core::RefCountedPtr<grpc_tls_credential_reload_config>( ::grpc_core::RefCountedPtr<grpc_tls_credential_reload_config>(
credential_reload_config_->c_credential_reload())); credential_reload_config_->c_credential_reload()));

@ -80,7 +80,8 @@ static void tls_server_authorization_check_callback(
arg->error_details = "callback_error_details"; arg->error_details = "callback_error_details";
} }
static int tls_server_authorization_check_sync(void* config_user_data, TlsServerAuthorizationCheckArg* arg) { static int tls_server_authorization_check_sync(
void* config_user_data, TlsServerAuthorizationCheckArg* arg) {
GPR_ASSERT(arg != nullptr); GPR_ASSERT(arg != nullptr);
grpc::string cb_user_data = "cb_user_data"; grpc::string cb_user_data = "cb_user_data";
arg->set_cb_user_data(static_cast<void*>(gpr_strdup(cb_user_data.c_str()))); arg->set_cb_user_data(static_cast<void*>(gpr_strdup(cb_user_data.c_str())));
@ -92,7 +93,8 @@ static int tls_server_authorization_check_sync(void* config_user_data, TlsServer
return 1; return 1;
} }
static void tls_server_authorization_check_cancel(void* config_user_data, TlsServerAuthorizationCheckArg* arg) { static void tls_server_authorization_check_cancel(
void* config_user_data, TlsServerAuthorizationCheckArg* arg) {
GPR_ASSERT(arg != nullptr); GPR_ASSERT(arg != nullptr);
arg->set_status(GRPC_STATUS_PERMISSION_DENIED); arg->set_status(GRPC_STATUS_PERMISSION_DENIED);
arg->set_error_details("cancelled"); arg->set_error_details("cancelled");
@ -314,8 +316,10 @@ TEST_F(CredentialsTest, TlsKeyMaterialsCtoCpp) {
EXPECT_STREQ("cert_chain", cpp_pair_list[0].cert_chain.c_str()); EXPECT_STREQ("cert_chain", cpp_pair_list[0].cert_chain.c_str());
} }
typedef class ::grpc_impl::experimental::TlsCredentialReloadArg TlsCredentialReloadArg; typedef class ::grpc_impl::experimental::TlsCredentialReloadArg
typedef class ::grpc_impl::experimental::TlsCredentialReloadConfig TlsCredentialReloadConfig; TlsCredentialReloadArg;
typedef class ::grpc_impl::experimental::TlsCredentialReloadConfig
TlsCredentialReloadConfig;
TEST_F(CredentialsTest, TlsCredentialReloadArgCallback) { TEST_F(CredentialsTest, TlsCredentialReloadArgCallback) {
grpc_tls_credential_reload_arg c_arg; grpc_tls_credential_reload_arg c_arg;
@ -337,8 +341,7 @@ TEST_F(CredentialsTest, TlsCredentialReloadConfigSchedule) {
"cert_chain1"}; "cert_chain1"};
struct TlsKeyMaterialsConfig::PemKeyCertPair pair2 = {"private_key2", struct TlsKeyMaterialsConfig::PemKeyCertPair pair2 = {"private_key2",
"cert_chain2"}; "cert_chain2"};
std::vector<TlsKeyMaterialsConfig::PemKeyCertPair> pair_list = {pair1, std::vector<TlsKeyMaterialsConfig::PemKeyCertPair> pair_list = {pair1, pair2};
pair2};
key_materials_config->set_key_materials("pem_root_certs", pair_list); key_materials_config->set_key_materials("pem_root_certs", pair_list);
arg.set_key_materials_config(key_materials_config); arg.set_key_materials_config(key_materials_config);
arg.set_status(GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_NEW); arg.set_status(GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_NEW);
@ -435,7 +438,8 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckArgCallback) {
} }
TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigSchedule) { TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigSchedule) {
TlsServerAuthorizationCheckConfig config = TlsServerAuthorizationCheckConfig(nullptr, &tls_server_authorization_check_sync, nullptr, nullptr); TlsServerAuthorizationCheckConfig config = TlsServerAuthorizationCheckConfig(
nullptr, &tls_server_authorization_check_sync, nullptr, nullptr);
TlsServerAuthorizationCheckArg arg; TlsServerAuthorizationCheckArg arg;
arg.set_cb_user_data(nullptr); arg.set_cb_user_data(nullptr);
arg.set_success(0); arg.set_success(0);
@ -455,7 +459,8 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigSchedule) {
TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigCppToC) { TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigCppToC) {
TlsServerAuthorizationCheckConfig config = TlsServerAuthorizationCheckConfig( TlsServerAuthorizationCheckConfig config = TlsServerAuthorizationCheckConfig(
nullptr, &tls_server_authorization_check_sync, &tls_server_authorization_check_cancel, nullptr); nullptr, &tls_server_authorization_check_sync,
&tls_server_authorization_check_cancel, nullptr);
grpc_tls_server_authorization_check_arg c_arg; grpc_tls_server_authorization_check_arg c_arg;
c_arg.cb = tls_server_authorization_check_callback; c_arg.cb = tls_server_authorization_check_callback;
c_arg.cb_user_data = nullptr; c_arg.cb_user_data = nullptr;
@ -465,7 +470,8 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigCppToC) {
c_arg.status = GRPC_STATUS_UNAUTHENTICATED; c_arg.status = GRPC_STATUS_UNAUTHENTICATED;
c_arg.error_details = "error_details"; c_arg.error_details = "error_details";
grpc_tls_server_authorization_check_config* c_config = config.c_server_authorization_check(); grpc_tls_server_authorization_check_config* c_config =
config.c_server_authorization_check();
c_arg.config = c_config; c_arg.config = c_config;
int c_schedule_output = c_config->Schedule(&c_arg); int c_schedule_output = c_config->Schedule(&c_arg);
EXPECT_EQ(c_schedule_output, 1); EXPECT_EQ(c_schedule_output, 1);
@ -495,25 +501,33 @@ TEST_F(CredentialsTest, TlsCredentialsOptionsCppToC) {
key_materials_config->set_key_materials("pem_root_certs", pair_list); key_materials_config->set_key_materials("pem_root_certs", pair_list);
options.set_key_materials_config(key_materials_config); options.set_key_materials_config(key_materials_config);
std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config(new TlsCredentialReloadConfig( std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config(
nullptr, &tls_credential_reload_sync, &tls_credential_reload_cancel, nullptr)); new TlsCredentialReloadConfig(nullptr, &tls_credential_reload_sync,
&tls_credential_reload_cancel, nullptr));
options.set_credential_reload_config(credential_reload_config); options.set_credential_reload_config(credential_reload_config);
std::shared_ptr<TlsServerAuthorizationCheckConfig> server_authorization_check_config(new TlsServerAuthorizationCheckConfig( std::shared_ptr<TlsServerAuthorizationCheckConfig>
nullptr, &tls_server_authorization_check_sync, &tls_server_authorization_check_cancel, nullptr)); server_authorization_check_config(new TlsServerAuthorizationCheckConfig(
options.set_server_authorization_check_config(server_authorization_check_config); nullptr, &tls_server_authorization_check_sync,
&tls_server_authorization_check_cancel, nullptr));
options.set_server_authorization_check_config(
server_authorization_check_config);
grpc_tls_credentials_options* c_options = options.c_credentials_options(); grpc_tls_credentials_options* c_options = options.c_credentials_options();
EXPECT_EQ(c_options->cert_request_type(), EXPECT_EQ(c_options->cert_request_type(),
GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY); GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY);
grpc_tls_key_materials_config* c_key_materials_config = c_options->key_materials_config(); grpc_tls_key_materials_config* c_key_materials_config =
grpc_tls_credential_reload_config* c_credential_reload_config = c_options->credential_reload_config(); c_options->key_materials_config();
grpc_tls_credential_reload_config* c_credential_reload_config =
c_options->credential_reload_config();
grpc_tls_credential_reload_arg c_credential_reload_arg; grpc_tls_credential_reload_arg c_credential_reload_arg;
c_credential_reload_arg.key_materials_config = c_key_materials_config; c_credential_reload_arg.key_materials_config = c_key_materials_config;
c_credential_reload_arg.status = GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_UNCHANGED; c_credential_reload_arg.status = GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_UNCHANGED;
grpc::string test_error_details = "error_details"; grpc::string test_error_details = "error_details";
c_credential_reload_arg.error_details = test_error_details.c_str(); c_credential_reload_arg.error_details = test_error_details.c_str();
grpc_tls_server_authorization_check_config* c_server_authorization_check_config = c_options->server_authorization_check_config(); grpc_tls_server_authorization_check_config*
c_server_authorization_check_config =
c_options->server_authorization_check_config();
grpc_tls_server_authorization_check_arg c_server_authorization_check_arg; grpc_tls_server_authorization_check_arg c_server_authorization_check_arg;
c_server_authorization_check_arg.cb = tls_server_authorization_check_callback; c_server_authorization_check_arg.cb = tls_server_authorization_check_callback;
c_server_authorization_check_arg.cb_user_data = nullptr; c_server_authorization_check_arg.cb_user_data = nullptr;
@ -524,14 +538,21 @@ TEST_F(CredentialsTest, TlsCredentialsOptionsCppToC) {
c_server_authorization_check_arg.error_details = "error_details"; c_server_authorization_check_arg.error_details = "error_details";
EXPECT_STREQ(c_key_materials_config->pem_root_certs(), "pem_root_certs"); EXPECT_STREQ(c_key_materials_config->pem_root_certs(), "pem_root_certs");
EXPECT_EQ(static_cast<int>(c_key_materials_config->pem_key_cert_pair_list().size()), 1); EXPECT_EQ(
EXPECT_STREQ(c_key_materials_config->pem_key_cert_pair_list()[0].private_key(), "private_key"); static_cast<int>(c_key_materials_config->pem_key_cert_pair_list().size()),
EXPECT_STREQ(c_key_materials_config->pem_key_cert_pair_list()[0].cert_chain(), "cert_chain"); 1);
EXPECT_STREQ(
int c_credential_reload_schedule_output = c_credential_reload_config->Schedule(&c_credential_reload_arg); c_key_materials_config->pem_key_cert_pair_list()[0].private_key(),
"private_key");
EXPECT_STREQ(c_key_materials_config->pem_key_cert_pair_list()[0].cert_chain(),
"cert_chain");
int c_credential_reload_schedule_output =
c_credential_reload_config->Schedule(&c_credential_reload_arg);
EXPECT_EQ(c_credential_reload_schedule_output, 0); EXPECT_EQ(c_credential_reload_schedule_output, 0);
EXPECT_EQ(c_credential_reload_arg.cb_user_data, nullptr); EXPECT_EQ(c_credential_reload_arg.cb_user_data, nullptr);
EXPECT_STREQ(c_credential_reload_arg.key_materials_config->pem_root_certs(), "new_pem_root_certs"); EXPECT_STREQ(c_credential_reload_arg.key_materials_config->pem_root_certs(),
"new_pem_root_certs");
::grpc_core::InlinedVector<::grpc_core::PemKeyCertPair, 1> c_pair_list = ::grpc_core::InlinedVector<::grpc_core::PemKeyCertPair, 1> c_pair_list =
c_credential_reload_arg.key_materials_config->pem_key_cert_pair_list(); c_credential_reload_arg.key_materials_config->pem_key_cert_pair_list();
EXPECT_EQ(static_cast<int>(c_pair_list.size()), 2); EXPECT_EQ(static_cast<int>(c_pair_list.size()), 2);
@ -539,17 +560,25 @@ TEST_F(CredentialsTest, TlsCredentialsOptionsCppToC) {
EXPECT_STREQ(c_pair_list[0].cert_chain(), "cert_chain"); EXPECT_STREQ(c_pair_list[0].cert_chain(), "cert_chain");
EXPECT_STREQ(c_pair_list[1].private_key(), "private_key3"); EXPECT_STREQ(c_pair_list[1].private_key(), "private_key3");
EXPECT_STREQ(c_pair_list[1].cert_chain(), "cert_chain3"); EXPECT_STREQ(c_pair_list[1].cert_chain(), "cert_chain3");
EXPECT_EQ(c_credential_reload_arg.status, GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_NEW); EXPECT_EQ(c_credential_reload_arg.status,
EXPECT_STREQ(c_credential_reload_arg.error_details, test_error_details.c_str()); GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_NEW);
EXPECT_STREQ(c_credential_reload_arg.error_details,
int c_server_authorization_check_schedule_output = c_server_authorization_check_config->Schedule(&c_server_authorization_check_arg); test_error_details.c_str());
int c_server_authorization_check_schedule_output =
c_server_authorization_check_config->Schedule(
&c_server_authorization_check_arg);
EXPECT_EQ(c_server_authorization_check_schedule_output, 1); EXPECT_EQ(c_server_authorization_check_schedule_output, 1);
EXPECT_STREQ(static_cast<char*>(c_server_authorization_check_arg.cb_user_data), "cb_user_data"); EXPECT_STREQ(
static_cast<char*>(c_server_authorization_check_arg.cb_user_data),
"cb_user_data");
EXPECT_EQ(c_server_authorization_check_arg.success, 1); EXPECT_EQ(c_server_authorization_check_arg.success, 1);
EXPECT_STREQ(c_server_authorization_check_arg.target_name, "sync_target_name"); EXPECT_STREQ(c_server_authorization_check_arg.target_name,
"sync_target_name");
EXPECT_STREQ(c_server_authorization_check_arg.peer_cert, "sync_peer_cert"); EXPECT_STREQ(c_server_authorization_check_arg.peer_cert, "sync_peer_cert");
EXPECT_EQ(c_server_authorization_check_arg.status, GRPC_STATUS_OK); EXPECT_EQ(c_server_authorization_check_arg.status, GRPC_STATUS_OK);
EXPECT_STREQ(c_server_authorization_check_arg.error_details, "sync_error_details"); EXPECT_STREQ(c_server_authorization_check_arg.error_details,
"sync_error_details");
gpr_free(c_options); gpr_free(c_options);
} }

Loading…
Cancel
Save