Addressed Mark's comments

reviewable/pr21984/r6
Moiz Haidry 5 years ago
parent 0c5545a894
commit f53456210d
  1. 17
      src/core/lib/security/credentials/plugin/plugin_credentials.cc
  2. 30
      test/core/security/credentials_test.cc

@ -43,17 +43,16 @@ grpc_plugin_credentials::~grpc_plugin_credentials() {
}
std::string grpc_plugin_credentials::debug_string() {
std::string debug_str;
char* debug_c_str = nullptr;
if (plugin_.debug_string != nullptr) {
char* debug_c_str = plugin_.debug_string(plugin_.state);
if (strlen(debug_c_str) != 0) {
debug_str = debug_c_str;
}
gpr_free(debug_c_str);
debug_c_str = plugin_.debug_string(plugin_.state);
}
return debug_str.empty()
? "grpc_plugin_credentials did not provide a debug string"
: debug_str;
std::string debug_str(
debug_c_str != nullptr
? debug_c_str
: "grpc_plugin_credentials did not provide a debug string");
gpr_free(debug_c_str);
return debug_str;
}
void grpc_plugin_credentials::pending_request_remove_locked(

@ -1228,9 +1228,9 @@ static void test_jwt_creds_lifetime(void) {
grpc_max_auth_token_lifetime()) == 0);
/* Check security level. */
GPR_ASSERT(jwt_creds->min_security_level() == GRPC_PRIVACY_AND_INTEGRITY);
GPR_ASSERT(gpr_strincmp(expected_creds_debug_string_prefix,
jwt_creds->debug_string().c_str(),
strlen(expected_creds_debug_string_prefix)) == 0);
GPR_ASSERT(strncmp(expected_creds_debug_string_prefix,
jwt_creds->debug_string().c_str(),
strlen(expected_creds_debug_string_prefix)) == 0);
grpc_call_credentials_release(jwt_creds);
// Shorter lifetime.
@ -1240,9 +1240,9 @@ static void test_jwt_creds_lifetime(void) {
json_key_string, token_lifetime, nullptr);
GPR_ASSERT(gpr_time_cmp(creds_as_jwt(jwt_creds)->jwt_lifetime(),
token_lifetime) == 0);
GPR_ASSERT(gpr_strincmp(expected_creds_debug_string_prefix,
jwt_creds->debug_string().c_str(),
strlen(expected_creds_debug_string_prefix)) == 0);
GPR_ASSERT(strncmp(expected_creds_debug_string_prefix,
jwt_creds->debug_string().c_str(),
strlen(expected_creds_debug_string_prefix)) == 0);
grpc_call_credentials_release(jwt_creds);
// Cropped lifetime.
@ -1252,9 +1252,9 @@ static void test_jwt_creds_lifetime(void) {
json_key_string, token_lifetime, nullptr);
GPR_ASSERT(gpr_time_cmp(creds_as_jwt(jwt_creds)->jwt_lifetime(),
grpc_max_auth_token_lifetime()) == 0);
GPR_ASSERT(gpr_strincmp(expected_creds_debug_string_prefix,
jwt_creds->debug_string().c_str(),
strlen(expected_creds_debug_string_prefix)) == 0);
GPR_ASSERT(strncmp(expected_creds_debug_string_prefix,
jwt_creds->debug_string().c_str(),
strlen(expected_creds_debug_string_prefix)) == 0);
grpc_call_credentials_release(jwt_creds);
gpr_free(json_key_string);
@ -1298,9 +1298,9 @@ static void test_jwt_creds_success(void) {
grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success);
run_request_metadata_test(creds, auth_md_ctx, state);
grpc_core::ExecCtx::Get()->Flush();
GPR_ASSERT(gpr_strincmp(expected_creds_debug_string_prefix,
creds->debug_string().c_str(),
strlen(expected_creds_debug_string_prefix)) == 0);
GPR_ASSERT(strncmp(expected_creds_debug_string_prefix,
creds->debug_string().c_str(),
strlen(expected_creds_debug_string_prefix)) == 0);
creds->Unref();
gpr_free(json_key_string);
@ -1326,9 +1326,9 @@ static void test_jwt_creds_signing_failure(void) {
run_request_metadata_test(creds, auth_md_ctx, state);
gpr_free(json_key_string);
GPR_ASSERT(gpr_strincmp(expected_creds_debug_string_prefix,
creds->debug_string().c_str(),
strlen(expected_creds_debug_string_prefix)) == 0);
GPR_ASSERT(strncmp(expected_creds_debug_string_prefix,
creds->debug_string().c_str(),
strlen(expected_creds_debug_string_prefix)) == 0);
creds->Unref();
grpc_jwt_encode_and_sign_set_override(nullptr);

Loading…
Cancel
Save