aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/security
diff options
context:
space:
mode:
authorGravatar Noah Eisen <ncteisen@google.com>2018-02-09 09:16:55 -0800
committerGravatar Noah Eisen <ncteisen@google.com>2018-02-09 09:16:55 -0800
commitbe82e64b3debcdb1d9ec6a149fc85af0d46bfb7e (patch)
treecc5e1234073eb250a2c319b5a4db2919fce060ea /test/core/security
parent194436342137924b4fb7429bede037a4b5ec7edb (diff)
Autofix c casts to c++ casts
Diffstat (limited to 'test/core/security')
-rw-r--r--test/core/security/create_jwt.cc2
-rw-r--r--test/core/security/credentials_test.cc25
-rw-r--r--test/core/security/fetch_oauth2.cc2
-rw-r--r--test/core/security/json_token_test.cc10
-rw-r--r--test/core/security/jwt_verifier_test.cc10
-rw-r--r--test/core/security/oauth2_utils.cc6
-rw-r--r--test/core/security/print_google_default_creds_token.cc4
-rw-r--r--test/core/security/secure_endpoint_test.cc12
-rw-r--r--test/core/security/verify_jwt.cc2
9 files changed, 35 insertions, 38 deletions
diff --git a/test/core/security/create_jwt.cc b/test/core/security/create_jwt.cc
index bb8227f08f..7be4ba08e1 100644
--- a/test/core/security/create_jwt.cc
+++ b/test/core/security/create_jwt.cc
@@ -36,7 +36,7 @@ void create_jwt(const char* json_key_file_path, const char* service_url,
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(json_key_file_path, 1, &json_key_data)));
key = grpc_auth_json_key_create_from_string(
- (const char*)GRPC_SLICE_START_PTR(json_key_data));
+ reinterpret_cast<const char*>GRPC_SLICE_START_PTR(json_key_data));
grpc_slice_unref(json_key_data);
if (!grpc_auth_json_key_is_valid(&key)) {
fprintf(stderr, "Could not parse json key.\n");
diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc
index 90310469aa..77f450b1a3 100644
--- a/test/core/security/credentials_test.cc
+++ b/test/core/security/credentials_test.cc
@@ -140,7 +140,7 @@ static grpc_httpcli_response http_response(int status, const char* body) {
grpc_httpcli_response response;
memset(&response, 0, sizeof(grpc_httpcli_response));
response.status = status;
- response.body = gpr_strdup((char*)body);
+ response.body = gpr_strdup(const_cast<char*>(body));
response.body_length = strlen(body);
return response;
}
@@ -324,7 +324,7 @@ static void check_metadata(const expected_md* expected,
}
static void check_request_metadata(void* arg, grpc_error* error) {
- request_metadata_state* state = (request_metadata_state*)arg;
+ request_metadata_state* state = static_cast<request_metadata_state*>(arg);
gpr_log(GPR_INFO, "expected_error: %s",
grpc_error_string(state->expected_error));
gpr_log(GPR_INFO, "actual_error: %s", grpc_error_string(error));
@@ -754,7 +754,7 @@ static grpc_service_account_jwt_access_credentials* creds_as_jwt(
grpc_call_credentials* creds) {
GPR_ASSERT(creds != nullptr);
GPR_ASSERT(strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_JWT) == 0);
- return (grpc_service_account_jwt_access_credentials*)creds;
+ return reinterpret_cast<grpc_service_account_jwt_access_credentials*>(creds);
}
static void test_jwt_creds_lifetime(void) {
@@ -873,10 +873,9 @@ static void test_google_default_creds_auth_key(void) {
set_google_default_creds_env_var_with_file_contents(
"json_key_google_default_creds", json_key);
gpr_free(json_key);
- creds = (grpc_composite_channel_credentials*)
- grpc_google_default_credentials_create();
+ creds = reinterpret_cast<grpc_composite_channel_credentials*>(grpc_google_default_credentials_create());
GPR_ASSERT(creds != nullptr);
- jwt = (grpc_service_account_jwt_access_credentials*)creds->call_creds;
+ jwt = reinterpret_cast<grpc_service_account_jwt_access_credentials*>(creds->call_creds);
GPR_ASSERT(
strcmp(jwt->key.client_id,
"777-abaslkan11hlb6nmim3bpspl31ud.apps.googleusercontent.com") ==
@@ -892,10 +891,9 @@ static void test_google_default_creds_refresh_token(void) {
grpc_flush_cached_google_default_credentials();
set_google_default_creds_env_var_with_file_contents(
"refresh_token_google_default_creds", test_refresh_token_str);
- creds = (grpc_composite_channel_credentials*)
- grpc_google_default_credentials_create();
+ creds = reinterpret_cast<grpc_composite_channel_credentials*>(grpc_google_default_credentials_create());
GPR_ASSERT(creds != nullptr);
- refresh = (grpc_google_refresh_token_credentials*)creds->call_creds;
+ refresh = reinterpret_cast<grpc_google_refresh_token_credentials*>(creds->call_creds);
GPR_ASSERT(strcmp(refresh->refresh_token.client_id,
"32555999999.apps.googleusercontent.com") == 0);
grpc_channel_credentials_unref(&creds->base);
@@ -938,8 +936,7 @@ static void test_google_default_creds_gce(void) {
default_creds_gce_detection_httpcli_get_success_override,
httpcli_post_should_not_be_called);
grpc_composite_channel_credentials* creds =
- (grpc_composite_channel_credentials*)
- grpc_google_default_credentials_create();
+ reinterpret_cast<grpc_composite_channel_credentials*>(grpc_google_default_credentials_create());
/* Verify that the default creds actually embeds a GCE creds. */
GPR_ASSERT(creds != nullptr);
@@ -1018,7 +1015,7 @@ static int plugin_get_metadata_success(
GPR_ASSERT(context.reserved == nullptr);
GPR_ASSERT(GPR_ARRAY_SIZE(plugin_md) <
GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX);
- plugin_state* s = (plugin_state*)state;
+ plugin_state* s = static_cast<plugin_state*>(state);
*s = PLUGIN_GET_METADATA_CALLED_STATE;
for (size_t i = 0; i < GPR_ARRAY_SIZE(plugin_md); ++i) {
memset(&creds_md[i], 0, sizeof(grpc_metadata));
@@ -1041,7 +1038,7 @@ static int plugin_get_metadata_failure(
GPR_ASSERT(strcmp(context.method_name, test_method) == 0);
GPR_ASSERT(context.channel_auth_context == nullptr);
GPR_ASSERT(context.reserved == nullptr);
- plugin_state* s = (plugin_state*)state;
+ plugin_state* s = static_cast<plugin_state*>(state);
*s = PLUGIN_GET_METADATA_CALLED_STATE;
*status = GRPC_STATUS_UNAUTHENTICATED;
*error_details = gpr_strdup(plugin_error_details);
@@ -1049,7 +1046,7 @@ static int plugin_get_metadata_failure(
}
static void plugin_destroy(void* state) {
- plugin_state* s = (plugin_state*)state;
+ plugin_state* s = static_cast<plugin_state*>(state);
*s = PLUGIN_DESTROY_CALLED_STATE;
}
diff --git a/test/core/security/fetch_oauth2.cc b/test/core/security/fetch_oauth2.cc
index b0fa514400..70a92d773d 100644
--- a/test/core/security/fetch_oauth2.cc
+++ b/test/core/security/fetch_oauth2.cc
@@ -38,7 +38,7 @@ static grpc_call_credentials* create_refresh_token_creds(
"load_file",
grpc_load_file(json_refresh_token_file_path, 1, &refresh_token)));
return grpc_google_refresh_token_credentials_create(
- (const char*)GRPC_SLICE_START_PTR(refresh_token), nullptr);
+ reinterpret_cast<const char*>GRPC_SLICE_START_PTR(refresh_token), nullptr);
}
int main(int argc, char** argv) {
diff --git a/test/core/security/json_token_test.cc b/test/core/security/json_token_test.cc
index aac9cc0029..80bfe45ab3 100644
--- a/test/core/security/json_token_test.cc
+++ b/test/core/security/json_token_test.cc
@@ -218,7 +218,7 @@ static grpc_json* parse_json_part_from_jwt(const char* str, size_t len,
slice = grpc_base64_decode(b64, 1);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(slice));
decoded = static_cast<char*>(gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1));
- strncpy(decoded, (const char*)GRPC_SLICE_START_PTR(slice),
+ strncpy(decoded, reinterpret_cast<const char*>GRPC_SLICE_START_PTR(slice),
GRPC_SLICE_LENGTH(slice));
decoded[GRPC_SLICE_LENGTH(slice)] = '\0';
json = grpc_json_parse_string(decoded);
@@ -386,20 +386,20 @@ static void test_jwt_encode_and_sign(
const char* dot = strchr(jwt, '.');
GPR_ASSERT(dot != nullptr);
parsed_header =
- parse_json_part_from_jwt(jwt, (size_t)(dot - jwt), &scratchpad);
+ parse_json_part_from_jwt(jwt, static_cast<size_t>(dot - jwt), &scratchpad);
GPR_ASSERT(parsed_header != nullptr);
check_jwt_header(parsed_header);
- offset = (size_t)(dot - jwt) + 1;
+ offset = static_cast<size_t>(dot - jwt) + 1;
grpc_json_destroy(parsed_header);
gpr_free(scratchpad);
dot = strchr(jwt + offset, '.');
GPR_ASSERT(dot != nullptr);
parsed_claim = parse_json_part_from_jwt(
- jwt + offset, (size_t)(dot - (jwt + offset)), &scratchpad);
+ jwt + offset, static_cast<size_t>(dot - (jwt + offset)), &scratchpad);
GPR_ASSERT(parsed_claim != nullptr);
check_jwt_claim_func(parsed_claim);
- offset = (size_t)(dot - jwt) + 1;
+ offset = static_cast<size_t>(dot - jwt) + 1;
grpc_json_destroy(parsed_claim);
gpr_free(scratchpad);
diff --git a/test/core/security/jwt_verifier_test.cc b/test/core/security/jwt_verifier_test.cc
index e219260b1d..2c454c1395 100644
--- a/test/core/security/jwt_verifier_test.cc
+++ b/test/core/security/jwt_verifier_test.cc
@@ -207,7 +207,7 @@ static void test_claims_success(void) {
grpc_jwt_claims* claims;
grpc_slice s = grpc_slice_from_copied_string(claims_without_time_constraint);
grpc_json* json = grpc_json_parse_string_with_len(
- (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s));
+ reinterpret_cast<char*>GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s));
GPR_ASSERT(json != nullptr);
grpc_core::ExecCtx exec_ctx;
claims = grpc_jwt_claims_from_json(json, s);
@@ -226,7 +226,7 @@ static void test_expired_claims_failure(void) {
grpc_jwt_claims* claims;
grpc_slice s = grpc_slice_from_copied_string(expired_claims);
grpc_json* json = grpc_json_parse_string_with_len(
- (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s));
+ reinterpret_cast<char*>GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s));
gpr_timespec exp_iat = {100, 0, GPR_CLOCK_REALTIME};
gpr_timespec exp_exp = {120, 0, GPR_CLOCK_REALTIME};
gpr_timespec exp_nbf = {60, 0, GPR_CLOCK_REALTIME};
@@ -251,7 +251,7 @@ static void test_expired_claims_failure(void) {
static void test_invalid_claims_failure(void) {
grpc_slice s = grpc_slice_from_copied_string(invalid_claims);
grpc_json* json = grpc_json_parse_string_with_len(
- (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s));
+ reinterpret_cast<char*>GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s));
grpc_core::ExecCtx exec_ctx;
GPR_ASSERT(grpc_jwt_claims_from_json(json, s) == nullptr);
}
@@ -260,7 +260,7 @@ static void test_bad_audience_claims_failure(void) {
grpc_jwt_claims* claims;
grpc_slice s = grpc_slice_from_copied_string(claims_without_time_constraint);
grpc_json* json = grpc_json_parse_string_with_len(
- (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s));
+ reinterpret_cast<char*>GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s));
GPR_ASSERT(json != nullptr);
grpc_core::ExecCtx exec_ctx;
claims = grpc_jwt_claims_from_json(json, s);
@@ -274,7 +274,7 @@ static void test_bad_subject_claims_failure(void) {
grpc_jwt_claims* claims;
grpc_slice s = grpc_slice_from_copied_string(claims_with_bad_subject);
grpc_json* json = grpc_json_parse_string_with_len(
- (char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s));
+ reinterpret_cast<char*>GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s));
GPR_ASSERT(json != nullptr);
grpc_core::ExecCtx exec_ctx;
claims = grpc_jwt_claims_from_json(json, s);
diff --git a/test/core/security/oauth2_utils.cc b/test/core/security/oauth2_utils.cc
index 0d3a1279af..b18fa455fe 100644
--- a/test/core/security/oauth2_utils.cc
+++ b/test/core/security/oauth2_utils.cc
@@ -40,7 +40,7 @@ typedef struct {
} oauth2_request;
static void on_oauth2_response(void* arg, grpc_error* error) {
- oauth2_request* request = (oauth2_request*)arg;
+ oauth2_request* request = static_cast<oauth2_request*>(arg);
char* token = nullptr;
grpc_slice token_slice;
if (error != GRPC_ERROR_NONE) {
@@ -48,7 +48,7 @@ static void on_oauth2_response(void* arg, grpc_error* error) {
} else {
GPR_ASSERT(request->md_array.size == 1);
token_slice = GRPC_MDVALUE(request->md_array.md[0]);
- token = (char*)gpr_malloc(GRPC_SLICE_LENGTH(token_slice) + 1);
+ token = static_cast<char*>(gpr_malloc(GRPC_SLICE_LENGTH(token_slice) + 1));
memcpy(token, GRPC_SLICE_START_PTR(token_slice),
GRPC_SLICE_LENGTH(token_slice));
token[GRPC_SLICE_LENGTH(token_slice)] = '\0';
@@ -73,7 +73,7 @@ char* grpc_test_fetch_oauth2_token_with_credentials(
grpc_closure do_nothing_closure;
grpc_auth_metadata_context null_ctx = {"", "", nullptr, nullptr};
- grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size());
+ grpc_pollset* pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size()));
grpc_pollset_init(pollset, &request.mu);
request.pops = grpc_polling_entity_create_from_pollset(pollset);
request.is_done = false;
diff --git a/test/core/security/print_google_default_creds_token.cc b/test/core/security/print_google_default_creds_token.cc
index 828694afd1..00e0783089 100644
--- a/test/core/security/print_google_default_creds_token.cc
+++ b/test/core/security/print_google_default_creds_token.cc
@@ -88,7 +88,7 @@ int main(int argc, char** argv) {
}
memset(&sync, 0, sizeof(sync));
- pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size());
+ pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size()));
grpc_pollset_init(pollset, &sync.mu);
sync.pops = grpc_polling_entity_create_from_pollset(pollset);
sync.is_done = false;
@@ -97,7 +97,7 @@ int main(int argc, char** argv) {
error = GRPC_ERROR_NONE;
if (grpc_call_credentials_get_request_metadata(
- ((grpc_composite_channel_credentials*)creds)->call_creds, &sync.pops,
+ (reinterpret_cast<grpc_composite_channel_credentials*>(creds))->call_creds, &sync.pops,
context, &sync.md_array, &sync.on_request_metadata, &error)) {
// Synchronous response. Invoke callback directly.
on_metadata_response(&sync, error);
diff --git a/test/core/security/secure_endpoint_test.cc b/test/core/security/secure_endpoint_test.cc
index 8e92a21e5d..bacadec950 100644
--- a/test/core/security/secure_endpoint_test.cc
+++ b/test/core/security/secure_endpoint_test.cc
@@ -57,7 +57,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
grpc_arg a[1];
a[0].key = const_cast<char*>(GRPC_ARG_TCP_READ_CHUNK_SIZE);
a[0].type = GRPC_ARG_INTEGER;
- a[0].value.integer = (int)slice_size;
+ a[0].value.integer = static_cast<int>(slice_size);
grpc_channel_args args = {GPR_ARRAY_SIZE(a), a};
tcp = grpc_iomgr_create_endpoint_pair("fixture", &args);
grpc_endpoint_add_to_pollset(tcp.client, g_pollset);
@@ -73,7 +73,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
size_t still_pending_size;
size_t total_buffer_size = 8192;
size_t buffer_size = total_buffer_size;
- uint8_t* encrypted_buffer = (uint8_t*)gpr_malloc(buffer_size);
+ uint8_t* encrypted_buffer = static_cast<uint8_t*>(gpr_malloc(buffer_size));
uint8_t* cur = encrypted_buffer;
grpc_slice encrypted_leftover;
for (i = 0; i < leftover_nslices; i++) {
@@ -106,7 +106,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
buffer_size -= protected_buffer_size_to_send;
} while (still_pending_size > 0);
encrypted_leftover = grpc_slice_from_copied_buffer(
- (const char*)encrypted_buffer, total_buffer_size - buffer_size);
+ reinterpret_cast<const char*>(encrypted_buffer), total_buffer_size - buffer_size);
f.client_ep = grpc_secure_endpoint_create(
fake_read_protector, fake_read_zero_copy_protector, tcp.client,
&encrypted_leftover, 1);
@@ -165,7 +165,7 @@ static grpc_endpoint_test_config configs[] = {
clean_up},
};
-static void inc_call_ctr(void* arg, grpc_error* error) { ++*(int*)arg; }
+static void inc_call_ctr(void* arg, grpc_error* error) { ++*static_cast<int*>(arg); }
static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) {
grpc_endpoint_test_fixture f = config.create_fixture(slice_size);
@@ -200,7 +200,7 @@ static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) {
}
static void destroy_pollset(void* p, grpc_error* error) {
- grpc_pollset_destroy((grpc_pollset*)p);
+ grpc_pollset_destroy(static_cast<grpc_pollset*>(p));
}
int main(int argc, char** argv) {
@@ -210,7 +210,7 @@ int main(int argc, char** argv) {
{
grpc_core::ExecCtx exec_ctx;
- g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size());
+ g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size()));
grpc_pollset_init(g_pollset, &g_mu);
grpc_endpoint_tests(configs[0], g_pollset, g_mu);
grpc_endpoint_tests(configs[1], g_pollset, g_mu);
diff --git a/test/core/security/verify_jwt.cc b/test/core/security/verify_jwt.cc
index 747508f6f6..2a4e7c73d3 100644
--- a/test/core/security/verify_jwt.cc
+++ b/test/core/security/verify_jwt.cc
@@ -55,7 +55,7 @@ static void on_jwt_verification_done(void* user_data,
char* claims_str;
GPR_ASSERT(claims != nullptr);
claims_str =
- grpc_json_dump_to_string((grpc_json*)grpc_jwt_claims_json(claims), 2);
+ grpc_json_dump_to_string(const_cast<grpc_json*>(grpc_jwt_claims_json(claims)), 2);
printf("Claims: \n\n%s\n", claims_str);
gpr_free(claims_str);
grpc_jwt_claims_destroy(claims);