Small changes to/for unit tests.

pull/19778/head
Matthew Stevenson 5 years ago
parent de3a6465b4
commit 94d3e95e8d
  1. 10
      src/cpp/common/tls_credentials_options.cc
  2. 32
      test/cpp/client/credentials_test.cc

@ -72,11 +72,12 @@ std::shared_ptr<TlsKeyMaterialsConfig> tls_key_materials_c_to_cpp(
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++) {
::grpc_core::PemKeyCertPair key_cert_pair = pem_key_cert_pair_list[i]; ::grpc_core::PemKeyCertPair key_cert_pair = pem_key_cert_pair_list[i];
TlsKeyMaterialsConfig::PemKeyCertPair p = { TlsKeyMaterialsConfig::PemKeyCertPair p = {
gpr_strdup(key_cert_pair.private_key()), //gpr_strdup(key_cert_pair.private_key()),
gpr_strdup(key_cert_pair.cert_chain())}; //gpr_strdup(key_cert_pair.cert_chain())};
key_cert_pair.private_key(), 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(std::move(gpr_strdup(config->pem_root_certs())), cpp_config->set_key_materials(std::move(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;
@ -188,7 +189,8 @@ TlsServerAuthorizationCheckArg::TlsServerAuthorizationCheckArg(
c_arg_ = arg; c_arg_ = arg;
} }
TlsServerAuthorizationCheckArg::~TlsServerAuthorizationCheckArg() {} TlsServerAuthorizationCheckArg::~TlsServerAuthorizationCheckArg() {
}
void* TlsServerAuthorizationCheckArg::cb_user_data() const { void* TlsServerAuthorizationCheckArg::cb_user_data() const {
return c_arg_.cb_user_data; return c_arg_.cb_user_data;

@ -55,6 +55,8 @@ static int tls_credential_reload_sync(void* config_user_data,
std::vector<TlsKeyMaterialsConfig::PemKeyCertPair> pair_list = std::vector<TlsKeyMaterialsConfig::PemKeyCertPair> pair_list =
key_materials_config->pem_key_cert_pair_list(); key_materials_config->pem_key_cert_pair_list();
pair_list.push_back(pair3); pair_list.push_back(pair3);
pair_list[0].private_key = "private_key01";
pair_list[0].cert_chain = "cert_chain01";
key_materials_config->set_key_materials("new_pem_root_certs", pair_list); key_materials_config->set_key_materials("new_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);
@ -356,8 +358,8 @@ TEST_F(CredentialsTest, TlsCredentialReloadConfigSchedule) {
"new_pem_root_certs"); "new_pem_root_certs");
pair_list = arg.key_materials_config()->pem_key_cert_pair_list(); pair_list = arg.key_materials_config()->pem_key_cert_pair_list();
EXPECT_EQ(static_cast<int>(pair_list.size()), 3); EXPECT_EQ(static_cast<int>(pair_list.size()), 3);
EXPECT_STREQ(pair_list[0].private_key.c_str(), "private_key1"); EXPECT_STREQ(pair_list[0].private_key.c_str(), "private_key01");
EXPECT_STREQ(pair_list[0].cert_chain.c_str(), "cert_chain1"); EXPECT_STREQ(pair_list[0].cert_chain.c_str(), "cert_chain01");
EXPECT_STREQ(pair_list[1].private_key.c_str(), "private_key2"); EXPECT_STREQ(pair_list[1].private_key.c_str(), "private_key2");
EXPECT_STREQ(pair_list[1].cert_chain.c_str(), "cert_chain2"); EXPECT_STREQ(pair_list[1].cert_chain.c_str(), "cert_chain2");
EXPECT_STREQ(pair_list[2].private_key.c_str(), "private_key3"); EXPECT_STREQ(pair_list[2].private_key.c_str(), "private_key3");
@ -404,8 +406,8 @@ TEST_F(CredentialsTest, TlsCredentialReloadConfigCppToC) {
::grpc_core::InlinedVector<::grpc_core::PemKeyCertPair, 1> pair_list = ::grpc_core::InlinedVector<::grpc_core::PemKeyCertPair, 1> pair_list =
c_arg.key_materials_config->pem_key_cert_pair_list(); c_arg.key_materials_config->pem_key_cert_pair_list();
EXPECT_EQ(static_cast<int>(pair_list.size()), 2); EXPECT_EQ(static_cast<int>(pair_list.size()), 2);
EXPECT_STREQ(pair_list[0].private_key(), "private_key"); EXPECT_STREQ(pair_list[0].private_key(), "private_key01");
EXPECT_STREQ(pair_list[0].cert_chain(), "cert_chain"); EXPECT_STREQ(pair_list[0].cert_chain(), "cert_chain01");
EXPECT_STREQ(pair_list[1].private_key(), "private_key3"); EXPECT_STREQ(pair_list[1].private_key(), "private_key3");
EXPECT_STREQ(pair_list[1].cert_chain(), "cert_chain3"); EXPECT_STREQ(pair_list[1].cert_chain(), "cert_chain3");
EXPECT_EQ(c_arg.status, GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_NEW); EXPECT_EQ(c_arg.status, GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_NEW);
@ -426,13 +428,19 @@ typedef class ::grpc_impl::experimental::TlsServerAuthorizationCheckConfig
TEST_F(CredentialsTest, TlsServerAuthorizationCheckArgCallback) { TEST_F(CredentialsTest, TlsServerAuthorizationCheckArgCallback) {
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;
c_arg.success = 0; //c_arg.success = 0;
c_arg.target_name = "target_name"; //c_arg.target_name = "target_name";
c_arg.peer_cert = "peer_cert"; //c_arg.peer_cert = "peer_cert";
c_arg.status = GRPC_STATUS_UNAUTHENTICATED; //c_arg.status = GRPC_STATUS_UNAUTHENTICATED;
c_arg.error_details = "error_details"; //c_arg.error_details = "error_details";
TlsServerAuthorizationCheckArg arg(c_arg); TlsServerAuthorizationCheckArg arg(c_arg);
arg.set_cb_user_data(nullptr);
arg.set_success(0);
arg.set_target_name("target_name");
arg.set_peer_cert("peer_cert");
arg.set_status(GRPC_STATUS_UNAUTHENTICATED);
arg.set_error_details("error_details");
arg.callback(); arg.callback();
EXPECT_STREQ(static_cast<char*>(arg.cb_user_data()), "cb_user_data"); EXPECT_STREQ(static_cast<char*>(arg.cb_user_data()), "cb_user_data");
gpr_free(arg.cb_user_data()); gpr_free(arg.cb_user_data());
@ -567,8 +575,8 @@ TEST_F(CredentialsTest, TlsCredentialsOptionsCppToC) {
::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);
EXPECT_STREQ(c_pair_list[0].private_key(), "private_key"); EXPECT_STREQ(c_pair_list[0].private_key(), "private_key01");
EXPECT_STREQ(c_pair_list[0].cert_chain(), "cert_chain"); EXPECT_STREQ(c_pair_list[0].cert_chain(), "cert_chain01");
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, EXPECT_EQ(c_credential_reload_arg.status,

Loading…
Cancel
Save