|
|
|
@ -21,6 +21,8 @@ |
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
|
|
#include <gtest/gtest.h> |
|
|
|
|
|
|
|
|
|
#include "upb/upb.hpp" |
|
|
|
|
|
|
|
|
|
#include <grpc/grpc.h> |
|
|
|
@ -162,7 +164,7 @@ static grpc_byte_buffer* generate_handshaker_response( |
|
|
|
|
upb_StringView_FromString(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY)); |
|
|
|
|
grpc_gcp_HandshakerResult_set_key_data( |
|
|
|
|
result, upb_StringView_FromString(ALTS_TSI_HANDSHAKER_TEST_KEY_DATA)); |
|
|
|
|
GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_rpc_versions( |
|
|
|
|
EXPECT_TRUE(grpc_gcp_handshaker_resp_set_peer_rpc_versions( |
|
|
|
|
resp, arena.ptr(), ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MAJOR, |
|
|
|
|
ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MINOR, |
|
|
|
|
ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MAJOR, |
|
|
|
@ -199,7 +201,7 @@ static grpc_byte_buffer* generate_handshaker_response( |
|
|
|
|
upb_StringView_FromString(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY)); |
|
|
|
|
grpc_gcp_HandshakerResult_set_key_data( |
|
|
|
|
result, upb_StringView_FromString(ALTS_TSI_HANDSHAKER_TEST_KEY_DATA)); |
|
|
|
|
GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_rpc_versions( |
|
|
|
|
EXPECT_TRUE(grpc_gcp_handshaker_resp_set_peer_rpc_versions( |
|
|
|
|
resp, arena.ptr(), ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MAJOR, |
|
|
|
|
ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MINOR, |
|
|
|
|
ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MAJOR, |
|
|
|
@ -240,33 +242,35 @@ static void check_must_not_be_called(tsi_result /*status*/, void* /*user_data*/, |
|
|
|
|
const unsigned char* /*bytes_to_send*/, |
|
|
|
|
size_t /*bytes_to_send_size*/, |
|
|
|
|
tsi_handshaker_result* /*result*/) { |
|
|
|
|
GPR_ASSERT(0); |
|
|
|
|
ASSERT_TRUE(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void on_client_start_success_cb(tsi_result status, void* user_data, |
|
|
|
|
const unsigned char* bytes_to_send, |
|
|
|
|
size_t bytes_to_send_size, |
|
|
|
|
tsi_handshaker_result* result) { |
|
|
|
|
GPR_ASSERT(status == TSI_OK); |
|
|
|
|
GPR_ASSERT(user_data == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send_size == strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME)); |
|
|
|
|
GPR_ASSERT(memcmp(bytes_to_send, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, |
|
|
|
|
bytes_to_send_size) == 0); |
|
|
|
|
GPR_ASSERT(result == nullptr); |
|
|
|
|
ASSERT_EQ(status, TSI_OK); |
|
|
|
|
ASSERT_EQ(user_data, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send_size, strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME)); |
|
|
|
|
ASSERT_EQ(memcmp(bytes_to_send, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, |
|
|
|
|
bytes_to_send_size), |
|
|
|
|
0); |
|
|
|
|
ASSERT_EQ(result, nullptr); |
|
|
|
|
/* Validate peer identity. */ |
|
|
|
|
tsi_peer peer; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == |
|
|
|
|
TSI_INVALID_ARGUMENT); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_result_extract_peer(result, &peer), |
|
|
|
|
TSI_INVALID_ARGUMENT); |
|
|
|
|
/* Validate frame protector. */ |
|
|
|
|
tsi_frame_protector* protector = nullptr; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_create_frame_protector( |
|
|
|
|
result, nullptr, &protector) == TSI_INVALID_ARGUMENT); |
|
|
|
|
ASSERT_EQ( |
|
|
|
|
tsi_handshaker_result_create_frame_protector(result, nullptr, &protector), |
|
|
|
|
TSI_INVALID_ARGUMENT); |
|
|
|
|
/* Validate unused bytes. */ |
|
|
|
|
const unsigned char* unused_bytes = nullptr; |
|
|
|
|
size_t unused_bytes_size = 0; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(result, &unused_bytes, |
|
|
|
|
&unused_bytes_size) == |
|
|
|
|
TSI_INVALID_ARGUMENT); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_result_get_unused_bytes(result, &unused_bytes, |
|
|
|
|
&unused_bytes_size), |
|
|
|
|
TSI_INVALID_ARGUMENT); |
|
|
|
|
signal(&tsi_to_caller_notification); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -274,26 +278,28 @@ static void on_server_start_success_cb(tsi_result status, void* user_data, |
|
|
|
|
const unsigned char* bytes_to_send, |
|
|
|
|
size_t bytes_to_send_size, |
|
|
|
|
tsi_handshaker_result* result) { |
|
|
|
|
GPR_ASSERT(status == TSI_OK); |
|
|
|
|
GPR_ASSERT(user_data == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send_size == strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME)); |
|
|
|
|
GPR_ASSERT(memcmp(bytes_to_send, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, |
|
|
|
|
bytes_to_send_size) == 0); |
|
|
|
|
GPR_ASSERT(result == nullptr); |
|
|
|
|
ASSERT_EQ(status, TSI_OK); |
|
|
|
|
ASSERT_EQ(user_data, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send_size, strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME)); |
|
|
|
|
ASSERT_EQ(memcmp(bytes_to_send, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, |
|
|
|
|
bytes_to_send_size), |
|
|
|
|
0); |
|
|
|
|
ASSERT_EQ(result, nullptr); |
|
|
|
|
/* Validate peer identity. */ |
|
|
|
|
tsi_peer peer; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == |
|
|
|
|
TSI_INVALID_ARGUMENT); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_result_extract_peer(result, &peer), |
|
|
|
|
TSI_INVALID_ARGUMENT); |
|
|
|
|
/* Validate frame protector. */ |
|
|
|
|
tsi_frame_protector* protector = nullptr; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_create_frame_protector( |
|
|
|
|
result, nullptr, &protector) == TSI_INVALID_ARGUMENT); |
|
|
|
|
ASSERT_EQ( |
|
|
|
|
tsi_handshaker_result_create_frame_protector(result, nullptr, &protector), |
|
|
|
|
TSI_INVALID_ARGUMENT); |
|
|
|
|
/* Validate unused bytes. */ |
|
|
|
|
const unsigned char* unused_bytes = nullptr; |
|
|
|
|
size_t unused_bytes_size = 0; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(result, &unused_bytes, |
|
|
|
|
&unused_bytes_size) == |
|
|
|
|
TSI_INVALID_ARGUMENT); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_result_get_unused_bytes(result, &unused_bytes, |
|
|
|
|
&unused_bytes_size), |
|
|
|
|
TSI_INVALID_ARGUMENT); |
|
|
|
|
signal(&tsi_to_caller_notification); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -301,56 +307,64 @@ static void on_client_next_success_cb(tsi_result status, void* user_data, |
|
|
|
|
const unsigned char* bytes_to_send, |
|
|
|
|
size_t bytes_to_send_size, |
|
|
|
|
tsi_handshaker_result* result) { |
|
|
|
|
GPR_ASSERT(status == TSI_OK); |
|
|
|
|
GPR_ASSERT(user_data == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send_size == strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME)); |
|
|
|
|
GPR_ASSERT(memcmp(bytes_to_send, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, |
|
|
|
|
bytes_to_send_size) == 0); |
|
|
|
|
GPR_ASSERT(result != nullptr); |
|
|
|
|
ASSERT_EQ(status, TSI_OK); |
|
|
|
|
ASSERT_EQ(user_data, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send_size, strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME)); |
|
|
|
|
ASSERT_EQ(memcmp(bytes_to_send, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, |
|
|
|
|
bytes_to_send_size), |
|
|
|
|
0); |
|
|
|
|
ASSERT_NE(result, nullptr); |
|
|
|
|
// Validate max frame size value after Frame Size Negotiation. Here peer max
|
|
|
|
|
// frame size is greater than default value, and user specified max frame size
|
|
|
|
|
// is absent.
|
|
|
|
|
tsi_zero_copy_grpc_protector* zero_copy_protector = nullptr; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_create_zero_copy_grpc_protector( |
|
|
|
|
result, nullptr, &zero_copy_protector) == TSI_OK); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_result_create_zero_copy_grpc_protector( |
|
|
|
|
result, nullptr, &zero_copy_protector), |
|
|
|
|
TSI_OK); |
|
|
|
|
size_t actual_max_frame_size; |
|
|
|
|
tsi_zero_copy_grpc_protector_max_frame_size(zero_copy_protector, |
|
|
|
|
&actual_max_frame_size); |
|
|
|
|
GPR_ASSERT(actual_max_frame_size == kTsiAltsMaxFrameSize); |
|
|
|
|
ASSERT_EQ(actual_max_frame_size, kTsiAltsMaxFrameSize); |
|
|
|
|
tsi_zero_copy_grpc_protector_destroy(zero_copy_protector); |
|
|
|
|
/* Validate peer identity. */ |
|
|
|
|
tsi_peer peer; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == TSI_OK); |
|
|
|
|
GPR_ASSERT(peer.property_count == kTsiAltsNumOfPeerProperties); |
|
|
|
|
GPR_ASSERT(memcmp(TSI_ALTS_CERTIFICATE_TYPE, peer.properties[0].value.data, |
|
|
|
|
peer.properties[0].value.length) == 0); |
|
|
|
|
GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY, |
|
|
|
|
peer.properties[1].value.data, |
|
|
|
|
peer.properties[1].value.length) == 0); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_result_extract_peer(result, &peer), TSI_OK); |
|
|
|
|
ASSERT_EQ(peer.property_count, kTsiAltsNumOfPeerProperties); |
|
|
|
|
ASSERT_EQ(memcmp(TSI_ALTS_CERTIFICATE_TYPE, peer.properties[0].value.data, |
|
|
|
|
peer.properties[0].value.length), |
|
|
|
|
0); |
|
|
|
|
ASSERT_EQ( |
|
|
|
|
memcmp(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY, |
|
|
|
|
peer.properties[1].value.data, peer.properties[1].value.length), |
|
|
|
|
0); |
|
|
|
|
/* Validate alts context. */ |
|
|
|
|
upb::Arena context_arena; |
|
|
|
|
grpc_gcp_AltsContext* ctx = grpc_gcp_AltsContext_parse( |
|
|
|
|
peer.properties[3].value.data, peer.properties[3].value.length, |
|
|
|
|
context_arena.ptr()); |
|
|
|
|
GPR_ASSERT(ctx != nullptr); |
|
|
|
|
ASSERT_NE(ctx, nullptr); |
|
|
|
|
upb_StringView application_protocol = |
|
|
|
|
grpc_gcp_AltsContext_application_protocol(ctx); |
|
|
|
|
upb_StringView record_protocol = grpc_gcp_AltsContext_record_protocol(ctx); |
|
|
|
|
upb_StringView peer_account = grpc_gcp_AltsContext_peer_service_account(ctx); |
|
|
|
|
upb_StringView local_account = |
|
|
|
|
grpc_gcp_AltsContext_local_service_account(ctx); |
|
|
|
|
GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_APPLICATION_PROTOCOL, |
|
|
|
|
application_protocol.data, application_protocol.size) == 0); |
|
|
|
|
GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_RECORD_PROTOCOL, |
|
|
|
|
record_protocol.data, record_protocol.size) == 0); |
|
|
|
|
GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY, peer_account.data, |
|
|
|
|
peer_account.size) == 0); |
|
|
|
|
GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_LOCAL_IDENTITY, local_account.data, |
|
|
|
|
local_account.size) == 0); |
|
|
|
|
ASSERT_EQ(memcmp(ALTS_TSI_HANDSHAKER_TEST_APPLICATION_PROTOCOL, |
|
|
|
|
application_protocol.data, application_protocol.size), |
|
|
|
|
0); |
|
|
|
|
ASSERT_EQ(memcmp(ALTS_TSI_HANDSHAKER_TEST_RECORD_PROTOCOL, |
|
|
|
|
record_protocol.data, record_protocol.size), |
|
|
|
|
0); |
|
|
|
|
ASSERT_EQ(memcmp(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY, peer_account.data, |
|
|
|
|
peer_account.size), |
|
|
|
|
0); |
|
|
|
|
ASSERT_EQ(memcmp(ALTS_TSI_HANDSHAKER_TEST_LOCAL_IDENTITY, local_account.data, |
|
|
|
|
local_account.size), |
|
|
|
|
0); |
|
|
|
|
size_t iter = kUpb_Map_Begin; |
|
|
|
|
grpc_gcp_AltsContext_PeerAttributesEntry* peer_attributes_entry = |
|
|
|
|
grpc_gcp_AltsContext_peer_attributes_nextmutable(ctx, &iter); |
|
|
|
|
GPR_ASSERT(peer_attributes_entry != nullptr); |
|
|
|
|
ASSERT_NE(peer_attributes_entry, nullptr); |
|
|
|
|
while (peer_attributes_entry != nullptr) { |
|
|
|
|
upb_StringView key = grpc_gcp_AltsContext_PeerAttributesEntry_key( |
|
|
|
|
const_cast<grpc_gcp_AltsContext_PeerAttributesEntry*>( |
|
|
|
@ -358,33 +372,35 @@ static void on_client_next_success_cb(tsi_result status, void* user_data, |
|
|
|
|
upb_StringView val = grpc_gcp_AltsContext_PeerAttributesEntry_value( |
|
|
|
|
const_cast<grpc_gcp_AltsContext_PeerAttributesEntry*>( |
|
|
|
|
peer_attributes_entry)); |
|
|
|
|
GPR_ASSERT(upb_StringView_IsEqual( |
|
|
|
|
ASSERT_TRUE(upb_StringView_IsEqual( |
|
|
|
|
key, upb_StringView_FromString( |
|
|
|
|
ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_KEY))); |
|
|
|
|
GPR_ASSERT(upb_StringView_IsEqual( |
|
|
|
|
ASSERT_TRUE(upb_StringView_IsEqual( |
|
|
|
|
val, upb_StringView_FromString( |
|
|
|
|
ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_VALUE))); |
|
|
|
|
peer_attributes_entry = |
|
|
|
|
grpc_gcp_AltsContext_peer_attributes_nextmutable(ctx, &iter); |
|
|
|
|
} |
|
|
|
|
/* Validate security level. */ |
|
|
|
|
GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_SECURITY_LEVEL, |
|
|
|
|
peer.properties[4].value.data, |
|
|
|
|
peer.properties[4].value.length) == 0); |
|
|
|
|
ASSERT_EQ( |
|
|
|
|
memcmp(ALTS_TSI_HANDSHAKER_TEST_SECURITY_LEVEL, |
|
|
|
|
peer.properties[4].value.data, peer.properties[4].value.length), |
|
|
|
|
0); |
|
|
|
|
tsi_peer_destruct(&peer); |
|
|
|
|
/* Validate unused bytes. */ |
|
|
|
|
const unsigned char* bytes = nullptr; |
|
|
|
|
size_t bytes_size = 0; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(result, &bytes, |
|
|
|
|
&bytes_size) == TSI_OK); |
|
|
|
|
GPR_ASSERT(bytes_size == strlen(ALTS_TSI_HANDSHAKER_TEST_REMAIN_BYTES)); |
|
|
|
|
GPR_ASSERT(memcmp(bytes, ALTS_TSI_HANDSHAKER_TEST_REMAIN_BYTES, bytes_size) == |
|
|
|
|
0); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_result_get_unused_bytes(result, &bytes, &bytes_size), |
|
|
|
|
TSI_OK); |
|
|
|
|
ASSERT_EQ(bytes_size, strlen(ALTS_TSI_HANDSHAKER_TEST_REMAIN_BYTES)); |
|
|
|
|
ASSERT_EQ(memcmp(bytes, ALTS_TSI_HANDSHAKER_TEST_REMAIN_BYTES, bytes_size), |
|
|
|
|
0); |
|
|
|
|
/* Validate frame protector. */ |
|
|
|
|
tsi_frame_protector* protector = nullptr; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_create_frame_protector( |
|
|
|
|
result, nullptr, &protector) == TSI_OK); |
|
|
|
|
GPR_ASSERT(protector != nullptr); |
|
|
|
|
ASSERT_EQ( |
|
|
|
|
tsi_handshaker_result_create_frame_protector(result, nullptr, &protector), |
|
|
|
|
TSI_OK); |
|
|
|
|
ASSERT_NE(protector, nullptr); |
|
|
|
|
tsi_frame_protector_destroy(protector); |
|
|
|
|
tsi_handshaker_result_destroy(result); |
|
|
|
|
signal(&tsi_to_caller_notification); |
|
|
|
@ -394,58 +410,64 @@ static void on_server_next_success_cb(tsi_result status, void* user_data, |
|
|
|
|
const unsigned char* bytes_to_send, |
|
|
|
|
size_t bytes_to_send_size, |
|
|
|
|
tsi_handshaker_result* result) { |
|
|
|
|
GPR_ASSERT(status == TSI_OK); |
|
|
|
|
GPR_ASSERT(user_data == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send_size == 0); |
|
|
|
|
GPR_ASSERT(bytes_to_send == nullptr); |
|
|
|
|
GPR_ASSERT(result != nullptr); |
|
|
|
|
ASSERT_EQ(status, TSI_OK); |
|
|
|
|
ASSERT_EQ(user_data, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send_size, 0); |
|
|
|
|
ASSERT_EQ(bytes_to_send, nullptr); |
|
|
|
|
ASSERT_NE(result, nullptr); |
|
|
|
|
// Validate max frame size value after Frame Size Negotiation. The negotiated
|
|
|
|
|
// frame size value equals minimum send frame size, due to the absence of peer
|
|
|
|
|
// max frame size.
|
|
|
|
|
tsi_zero_copy_grpc_protector* zero_copy_protector = nullptr; |
|
|
|
|
size_t user_specified_max_frame_size = |
|
|
|
|
ALTS_TSI_HANDSHAKER_TEST_MAX_FRAME_SIZE; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_create_zero_copy_grpc_protector( |
|
|
|
|
result, &user_specified_max_frame_size, |
|
|
|
|
&zero_copy_protector) == TSI_OK); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_result_create_zero_copy_grpc_protector( |
|
|
|
|
result, &user_specified_max_frame_size, &zero_copy_protector), |
|
|
|
|
TSI_OK); |
|
|
|
|
size_t actual_max_frame_size; |
|
|
|
|
tsi_zero_copy_grpc_protector_max_frame_size(zero_copy_protector, |
|
|
|
|
&actual_max_frame_size); |
|
|
|
|
GPR_ASSERT(actual_max_frame_size == kTsiAltsMinFrameSize); |
|
|
|
|
ASSERT_EQ(actual_max_frame_size, kTsiAltsMinFrameSize); |
|
|
|
|
tsi_zero_copy_grpc_protector_destroy(zero_copy_protector); |
|
|
|
|
/* Validate peer identity. */ |
|
|
|
|
tsi_peer peer; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == TSI_OK); |
|
|
|
|
GPR_ASSERT(peer.property_count == kTsiAltsNumOfPeerProperties); |
|
|
|
|
GPR_ASSERT(memcmp(TSI_ALTS_CERTIFICATE_TYPE, peer.properties[0].value.data, |
|
|
|
|
peer.properties[0].value.length) == 0); |
|
|
|
|
GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY, |
|
|
|
|
peer.properties[1].value.data, |
|
|
|
|
peer.properties[1].value.length) == 0); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_result_extract_peer(result, &peer), TSI_OK); |
|
|
|
|
ASSERT_EQ(peer.property_count, kTsiAltsNumOfPeerProperties); |
|
|
|
|
ASSERT_EQ(memcmp(TSI_ALTS_CERTIFICATE_TYPE, peer.properties[0].value.data, |
|
|
|
|
peer.properties[0].value.length), |
|
|
|
|
0); |
|
|
|
|
ASSERT_EQ( |
|
|
|
|
memcmp(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY, |
|
|
|
|
peer.properties[1].value.data, peer.properties[1].value.length), |
|
|
|
|
0); |
|
|
|
|
/* Validate alts context. */ |
|
|
|
|
upb::Arena context_arena; |
|
|
|
|
grpc_gcp_AltsContext* ctx = grpc_gcp_AltsContext_parse( |
|
|
|
|
peer.properties[3].value.data, peer.properties[3].value.length, |
|
|
|
|
context_arena.ptr()); |
|
|
|
|
GPR_ASSERT(ctx != nullptr); |
|
|
|
|
ASSERT_NE(ctx, nullptr); |
|
|
|
|
upb_StringView application_protocol = |
|
|
|
|
grpc_gcp_AltsContext_application_protocol(ctx); |
|
|
|
|
upb_StringView record_protocol = grpc_gcp_AltsContext_record_protocol(ctx); |
|
|
|
|
upb_StringView peer_account = grpc_gcp_AltsContext_peer_service_account(ctx); |
|
|
|
|
upb_StringView local_account = |
|
|
|
|
grpc_gcp_AltsContext_local_service_account(ctx); |
|
|
|
|
GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_APPLICATION_PROTOCOL, |
|
|
|
|
application_protocol.data, application_protocol.size) == 0); |
|
|
|
|
GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_RECORD_PROTOCOL, |
|
|
|
|
record_protocol.data, record_protocol.size) == 0); |
|
|
|
|
GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY, peer_account.data, |
|
|
|
|
peer_account.size) == 0); |
|
|
|
|
GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_LOCAL_IDENTITY, local_account.data, |
|
|
|
|
local_account.size) == 0); |
|
|
|
|
ASSERT_EQ(memcmp(ALTS_TSI_HANDSHAKER_TEST_APPLICATION_PROTOCOL, |
|
|
|
|
application_protocol.data, application_protocol.size), |
|
|
|
|
0); |
|
|
|
|
ASSERT_EQ(memcmp(ALTS_TSI_HANDSHAKER_TEST_RECORD_PROTOCOL, |
|
|
|
|
record_protocol.data, record_protocol.size), |
|
|
|
|
0); |
|
|
|
|
ASSERT_EQ(memcmp(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY, peer_account.data, |
|
|
|
|
peer_account.size), |
|
|
|
|
0); |
|
|
|
|
ASSERT_EQ(memcmp(ALTS_TSI_HANDSHAKER_TEST_LOCAL_IDENTITY, local_account.data, |
|
|
|
|
local_account.size), |
|
|
|
|
0); |
|
|
|
|
size_t iter = kUpb_Map_Begin; |
|
|
|
|
grpc_gcp_AltsContext_PeerAttributesEntry* peer_attributes_entry = |
|
|
|
|
grpc_gcp_AltsContext_peer_attributes_nextmutable(ctx, &iter); |
|
|
|
|
GPR_ASSERT(peer_attributes_entry != nullptr); |
|
|
|
|
ASSERT_NE(peer_attributes_entry, nullptr); |
|
|
|
|
while (peer_attributes_entry != nullptr) { |
|
|
|
|
upb_StringView key = grpc_gcp_AltsContext_PeerAttributesEntry_key( |
|
|
|
|
const_cast<grpc_gcp_AltsContext_PeerAttributesEntry*>( |
|
|
|
@ -453,33 +475,35 @@ static void on_server_next_success_cb(tsi_result status, void* user_data, |
|
|
|
|
upb_StringView val = grpc_gcp_AltsContext_PeerAttributesEntry_value( |
|
|
|
|
const_cast<grpc_gcp_AltsContext_PeerAttributesEntry*>( |
|
|
|
|
peer_attributes_entry)); |
|
|
|
|
GPR_ASSERT(upb_StringView_IsEqual( |
|
|
|
|
ASSERT_TRUE(upb_StringView_IsEqual( |
|
|
|
|
key, upb_StringView_FromString( |
|
|
|
|
ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_KEY))); |
|
|
|
|
GPR_ASSERT(upb_StringView_IsEqual( |
|
|
|
|
ASSERT_TRUE(upb_StringView_IsEqual( |
|
|
|
|
val, upb_StringView_FromString( |
|
|
|
|
ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_VALUE))); |
|
|
|
|
peer_attributes_entry = |
|
|
|
|
grpc_gcp_AltsContext_peer_attributes_nextmutable(ctx, &iter); |
|
|
|
|
} |
|
|
|
|
/* Check security level. */ |
|
|
|
|
GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_SECURITY_LEVEL, |
|
|
|
|
peer.properties[4].value.data, |
|
|
|
|
peer.properties[4].value.length) == 0); |
|
|
|
|
ASSERT_EQ( |
|
|
|
|
memcmp(ALTS_TSI_HANDSHAKER_TEST_SECURITY_LEVEL, |
|
|
|
|
peer.properties[4].value.data, peer.properties[4].value.length), |
|
|
|
|
0); |
|
|
|
|
|
|
|
|
|
tsi_peer_destruct(&peer); |
|
|
|
|
/* Validate unused bytes. */ |
|
|
|
|
const unsigned char* bytes = nullptr; |
|
|
|
|
size_t bytes_size = 0; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(result, &bytes, |
|
|
|
|
&bytes_size) == TSI_OK); |
|
|
|
|
GPR_ASSERT(bytes_size == 0); |
|
|
|
|
GPR_ASSERT(bytes == nullptr); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_result_get_unused_bytes(result, &bytes, &bytes_size), |
|
|
|
|
TSI_OK); |
|
|
|
|
ASSERT_EQ(bytes_size, 0); |
|
|
|
|
ASSERT_EQ(bytes, nullptr); |
|
|
|
|
/* Validate frame protector. */ |
|
|
|
|
tsi_frame_protector* protector = nullptr; |
|
|
|
|
GPR_ASSERT(tsi_handshaker_result_create_frame_protector( |
|
|
|
|
result, nullptr, &protector) == TSI_OK); |
|
|
|
|
GPR_ASSERT(protector != nullptr); |
|
|
|
|
ASSERT_EQ( |
|
|
|
|
tsi_handshaker_result_create_frame_protector(result, nullptr, &protector), |
|
|
|
|
TSI_OK); |
|
|
|
|
ASSERT_NE(protector, nullptr); |
|
|
|
|
tsi_frame_protector_destroy(protector); |
|
|
|
|
tsi_handshaker_result_destroy(result); |
|
|
|
|
signal(&tsi_to_caller_notification); |
|
|
|
@ -514,7 +538,7 @@ static tsi_result mock_server_start(alts_handshaker_client* client, |
|
|
|
|
alts_handshaker_client_check_fields_for_testing( |
|
|
|
|
client, on_server_start_success_cb, nullptr, true, nullptr); |
|
|
|
|
grpc_slice slice = grpc_empty_slice(); |
|
|
|
|
GPR_ASSERT(grpc_slice_cmp(*bytes_received, slice) == 0); |
|
|
|
|
EXPECT_EQ(grpc_slice_cmp(*bytes_received, slice), 0); |
|
|
|
|
/* Populate handshaker response for server_start request. */ |
|
|
|
|
grpc_byte_buffer** recv_buffer_ptr = |
|
|
|
|
alts_handshaker_client_get_recv_buffer_addr_for_testing(client); |
|
|
|
@ -539,10 +563,11 @@ static tsi_result mock_next(alts_handshaker_client* client, |
|
|
|
|
alts_handshaker_client_set_recv_bytes_for_testing(client, bytes_received); |
|
|
|
|
alts_handshaker_client_check_fields_for_testing(client, cb, nullptr, true, |
|
|
|
|
bytes_received); |
|
|
|
|
GPR_ASSERT(bytes_received != nullptr); |
|
|
|
|
GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*bytes_received), |
|
|
|
|
ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, |
|
|
|
|
GRPC_SLICE_LENGTH(*bytes_received)) == 0); |
|
|
|
|
EXPECT_NE(bytes_received, nullptr); |
|
|
|
|
EXPECT_EQ(memcmp(GRPC_SLICE_START_PTR(*bytes_received), |
|
|
|
|
ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, |
|
|
|
|
GRPC_SLICE_LENGTH(*bytes_received)), |
|
|
|
|
0); |
|
|
|
|
/* Populate handshaker response for next request. */ |
|
|
|
|
grpc_slice out_frame = |
|
|
|
|
grpc_slice_from_static_string(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME); |
|
|
|
@ -583,22 +608,24 @@ static void run_tsi_handshaker_destroy_with_exec_ctx( |
|
|
|
|
tsi_handshaker_destroy(handshaker); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void check_handshaker_next_invalid_input() { |
|
|
|
|
TEST(AltsTsiHandshakerTest, CheckHandshakerNextInvalidInput) { |
|
|
|
|
should_handshaker_client_api_succeed = true; |
|
|
|
|
/* Initialization. */ |
|
|
|
|
tsi_handshaker* handshaker = create_test_handshaker(true); |
|
|
|
|
/* Check nullptr handshaker. */ |
|
|
|
|
GPR_ASSERT(tsi_handshaker_next(nullptr, nullptr, 0, nullptr, nullptr, nullptr, |
|
|
|
|
check_must_not_be_called, |
|
|
|
|
nullptr) == TSI_INVALID_ARGUMENT); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_next(nullptr, nullptr, 0, nullptr, nullptr, nullptr, |
|
|
|
|
check_must_not_be_called, nullptr), |
|
|
|
|
TSI_INVALID_ARGUMENT); |
|
|
|
|
/* Check nullptr callback. */ |
|
|
|
|
GPR_ASSERT(tsi_handshaker_next(handshaker, nullptr, 0, nullptr, nullptr, |
|
|
|
|
nullptr, nullptr, |
|
|
|
|
nullptr) == TSI_INVALID_ARGUMENT); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_next(handshaker, nullptr, 0, nullptr, nullptr, |
|
|
|
|
nullptr, nullptr, nullptr), |
|
|
|
|
TSI_INVALID_ARGUMENT); |
|
|
|
|
/* Cleanup. */ |
|
|
|
|
run_tsi_handshaker_destroy_with_exec_ctx(handshaker); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void check_handshaker_shutdown_invalid_input() { |
|
|
|
|
TEST(AltsTsiHandshakerTest, CheckHandshakerShutdownInvalidInput) { |
|
|
|
|
should_handshaker_client_api_succeed = false; |
|
|
|
|
/* Initialization. */ |
|
|
|
|
tsi_handshaker* handshaker = create_test_handshaker(true /* is_client */); |
|
|
|
|
/* Check nullptr handshaker. */ |
|
|
|
@ -617,28 +644,30 @@ static void check_handshaker_next_success() { |
|
|
|
|
tsi_handshaker* server_handshaker = |
|
|
|
|
create_test_handshaker(false /* is_client */); |
|
|
|
|
/* Client start. */ |
|
|
|
|
GPR_ASSERT(tsi_handshaker_next(client_handshaker, nullptr, 0, nullptr, |
|
|
|
|
nullptr, nullptr, on_client_start_success_cb, |
|
|
|
|
nullptr) == TSI_ASYNC); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_next(client_handshaker, nullptr, 0, nullptr, nullptr, |
|
|
|
|
nullptr, on_client_start_success_cb, nullptr), |
|
|
|
|
TSI_ASYNC); |
|
|
|
|
wait(&tsi_to_caller_notification); |
|
|
|
|
/* Client next. */ |
|
|
|
|
GPR_ASSERT(tsi_handshaker_next( |
|
|
|
|
client_handshaker, |
|
|
|
|
(const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, |
|
|
|
|
strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, |
|
|
|
|
nullptr, on_client_next_success_cb, nullptr) == TSI_ASYNC); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_next( |
|
|
|
|
client_handshaker, |
|
|
|
|
(const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, |
|
|
|
|
strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, |
|
|
|
|
nullptr, on_client_next_success_cb, nullptr), |
|
|
|
|
TSI_ASYNC); |
|
|
|
|
wait(&tsi_to_caller_notification); |
|
|
|
|
/* Server start. */ |
|
|
|
|
GPR_ASSERT(tsi_handshaker_next(server_handshaker, nullptr, 0, nullptr, |
|
|
|
|
nullptr, nullptr, on_server_start_success_cb, |
|
|
|
|
nullptr) == TSI_ASYNC); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_next(server_handshaker, nullptr, 0, nullptr, nullptr, |
|
|
|
|
nullptr, on_server_start_success_cb, nullptr), |
|
|
|
|
TSI_ASYNC); |
|
|
|
|
wait(&tsi_to_caller_notification); |
|
|
|
|
/* Server next. */ |
|
|
|
|
GPR_ASSERT(tsi_handshaker_next( |
|
|
|
|
server_handshaker, |
|
|
|
|
(const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, |
|
|
|
|
strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, |
|
|
|
|
nullptr, on_server_next_success_cb, nullptr) == TSI_ASYNC); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_next( |
|
|
|
|
server_handshaker, |
|
|
|
|
(const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, |
|
|
|
|
strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, |
|
|
|
|
nullptr, on_server_next_success_cb, nullptr), |
|
|
|
|
TSI_ASYNC); |
|
|
|
|
wait(&tsi_to_caller_notification); |
|
|
|
|
/* Cleanup. */ |
|
|
|
|
run_tsi_handshaker_destroy_with_exec_ctx(server_handshaker); |
|
|
|
@ -648,17 +677,17 @@ static void check_handshaker_next_success() { |
|
|
|
|
static void check_handshaker_next_with_shutdown() { |
|
|
|
|
tsi_handshaker* handshaker = create_test_handshaker(true /* is_client*/); |
|
|
|
|
/* next(success) -- shutdown(success) -- next (fail) */ |
|
|
|
|
GPR_ASSERT(tsi_handshaker_next(handshaker, nullptr, 0, nullptr, nullptr, |
|
|
|
|
nullptr, on_client_start_success_cb, |
|
|
|
|
nullptr) == TSI_ASYNC); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_next(handshaker, nullptr, 0, nullptr, nullptr, |
|
|
|
|
nullptr, on_client_start_success_cb, nullptr), |
|
|
|
|
TSI_ASYNC); |
|
|
|
|
wait(&tsi_to_caller_notification); |
|
|
|
|
tsi_handshaker_shutdown(handshaker); |
|
|
|
|
GPR_ASSERT(tsi_handshaker_next( |
|
|
|
|
handshaker, |
|
|
|
|
(const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, |
|
|
|
|
strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, |
|
|
|
|
nullptr, on_client_next_success_cb, |
|
|
|
|
nullptr) == TSI_HANDSHAKE_SHUTDOWN); |
|
|
|
|
ASSERT_EQ( |
|
|
|
|
tsi_handshaker_next( |
|
|
|
|
handshaker, (const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, |
|
|
|
|
strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, |
|
|
|
|
nullptr, on_client_next_success_cb, nullptr), |
|
|
|
|
TSI_HANDSHAKE_SHUTDOWN); |
|
|
|
|
/* Cleanup. */ |
|
|
|
|
run_tsi_handshaker_destroy_with_exec_ctx(handshaker); |
|
|
|
|
} |
|
|
|
@ -668,7 +697,8 @@ static void check_handle_response_with_shutdown(void* /*unused*/) { |
|
|
|
|
alts_handshaker_client_handle_response(cb_event, true /* is_ok */); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void check_handshaker_next_failure() { |
|
|
|
|
TEST(AltsTsiHandshakerTest, CheckHandshakerNextFailure) { |
|
|
|
|
should_handshaker_client_api_succeed = false; |
|
|
|
|
/**
|
|
|
|
|
* Create handshakers for which internal mock client is always going to fail. |
|
|
|
|
*/ |
|
|
|
@ -677,27 +707,27 @@ static void check_handshaker_next_failure() { |
|
|
|
|
tsi_handshaker* server_handshaker = |
|
|
|
|
create_test_handshaker(false /* is_client */); |
|
|
|
|
/* Client start. */ |
|
|
|
|
GPR_ASSERT(tsi_handshaker_next(client_handshaker, nullptr, 0, nullptr, |
|
|
|
|
nullptr, nullptr, check_must_not_be_called, |
|
|
|
|
nullptr) == TSI_INTERNAL_ERROR); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_next(client_handshaker, nullptr, 0, nullptr, nullptr, |
|
|
|
|
nullptr, check_must_not_be_called, nullptr), |
|
|
|
|
TSI_INTERNAL_ERROR); |
|
|
|
|
/* Server start. */ |
|
|
|
|
GPR_ASSERT(tsi_handshaker_next(server_handshaker, nullptr, 0, nullptr, |
|
|
|
|
nullptr, nullptr, check_must_not_be_called, |
|
|
|
|
nullptr) == TSI_INTERNAL_ERROR); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_next(server_handshaker, nullptr, 0, nullptr, nullptr, |
|
|
|
|
nullptr, check_must_not_be_called, nullptr), |
|
|
|
|
TSI_INTERNAL_ERROR); |
|
|
|
|
/* Server next. */ |
|
|
|
|
GPR_ASSERT(tsi_handshaker_next( |
|
|
|
|
server_handshaker, |
|
|
|
|
(const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, |
|
|
|
|
strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, |
|
|
|
|
nullptr, check_must_not_be_called, |
|
|
|
|
nullptr) == TSI_INTERNAL_ERROR); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_next( |
|
|
|
|
server_handshaker, |
|
|
|
|
(const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, |
|
|
|
|
strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, |
|
|
|
|
nullptr, check_must_not_be_called, nullptr), |
|
|
|
|
TSI_INTERNAL_ERROR); |
|
|
|
|
/* Client next. */ |
|
|
|
|
GPR_ASSERT(tsi_handshaker_next( |
|
|
|
|
client_handshaker, |
|
|
|
|
(const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, |
|
|
|
|
strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, |
|
|
|
|
nullptr, check_must_not_be_called, |
|
|
|
|
nullptr) == TSI_INTERNAL_ERROR); |
|
|
|
|
ASSERT_EQ(tsi_handshaker_next( |
|
|
|
|
client_handshaker, |
|
|
|
|
(const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, |
|
|
|
|
strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, |
|
|
|
|
nullptr, check_must_not_be_called, nullptr), |
|
|
|
|
TSI_INTERNAL_ERROR); |
|
|
|
|
/* Cleanup. */ |
|
|
|
|
run_tsi_handshaker_destroy_with_exec_ctx(server_handshaker); |
|
|
|
|
run_tsi_handshaker_destroy_with_exec_ctx(client_handshaker); |
|
|
|
@ -707,25 +737,26 @@ static void on_invalid_input_cb(tsi_result status, void* user_data, |
|
|
|
|
const unsigned char* bytes_to_send, |
|
|
|
|
size_t bytes_to_send_size, |
|
|
|
|
tsi_handshaker_result* result) { |
|
|
|
|
GPR_ASSERT(status == TSI_INTERNAL_ERROR); |
|
|
|
|
GPR_ASSERT(user_data == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send_size == 0); |
|
|
|
|
GPR_ASSERT(result == nullptr); |
|
|
|
|
ASSERT_EQ(status, TSI_INTERNAL_ERROR); |
|
|
|
|
ASSERT_EQ(user_data, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send_size, 0); |
|
|
|
|
ASSERT_EQ(result, nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void on_failed_grpc_call_cb(tsi_result status, void* user_data, |
|
|
|
|
const unsigned char* bytes_to_send, |
|
|
|
|
size_t bytes_to_send_size, |
|
|
|
|
tsi_handshaker_result* result) { |
|
|
|
|
GPR_ASSERT(status == TSI_INTERNAL_ERROR); |
|
|
|
|
GPR_ASSERT(user_data == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send_size == 0); |
|
|
|
|
GPR_ASSERT(result == nullptr); |
|
|
|
|
ASSERT_EQ(status, TSI_INTERNAL_ERROR); |
|
|
|
|
ASSERT_EQ(user_data, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send_size, 0); |
|
|
|
|
ASSERT_EQ(result, nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void check_handle_response_nullptr_handshaker() { |
|
|
|
|
TEST(AltsTsiHandshakerTest, CheckHandleResponseNullptrHandshaker) { |
|
|
|
|
should_handshaker_client_api_succeed = false; |
|
|
|
|
/* Initialization. */ |
|
|
|
|
notification_init(&caller_to_tsi_notification); |
|
|
|
|
notification_init(&tsi_to_caller_notification); |
|
|
|
@ -764,7 +795,8 @@ static void check_handle_response_nullptr_handshaker() { |
|
|
|
|
notification_destroy(&tsi_to_caller_notification); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void check_handle_response_nullptr_recv_bytes() { |
|
|
|
|
TEST(AltsTsiHandshakerTest, CheckHandleResponseNullptrRecvBytes) { |
|
|
|
|
should_handshaker_client_api_succeed = false; |
|
|
|
|
/* Initialization. */ |
|
|
|
|
notification_init(&caller_to_tsi_notification); |
|
|
|
|
notification_init(&tsi_to_caller_notification); |
|
|
|
@ -796,7 +828,9 @@ static void check_handle_response_nullptr_recv_bytes() { |
|
|
|
|
notification_destroy(&tsi_to_caller_notification); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void check_handle_response_failed_grpc_call_to_handshaker_service() { |
|
|
|
|
TEST(AltsTsiHandshakerTest, |
|
|
|
|
CheckHandleResponseFailedGrpcCallToHandshakerService) { |
|
|
|
|
should_handshaker_client_api_succeed = false; |
|
|
|
|
/* Initialization. */ |
|
|
|
|
notification_init(&caller_to_tsi_notification); |
|
|
|
|
notification_init(&tsi_to_caller_notification); |
|
|
|
@ -831,8 +865,9 @@ static void check_handle_response_failed_grpc_call_to_handshaker_service() { |
|
|
|
|
notification_destroy(&tsi_to_caller_notification); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
check_handle_response_failed_recv_message_from_handshaker_service() { |
|
|
|
|
TEST(AltsTsiHandshakerTest, |
|
|
|
|
CheckHandleResponseFailedRecvMessageFromHandshakerService) { |
|
|
|
|
should_handshaker_client_api_succeed = false; |
|
|
|
|
/* Initialization. */ |
|
|
|
|
notification_init(&caller_to_tsi_notification); |
|
|
|
|
notification_init(&tsi_to_caller_notification); |
|
|
|
@ -871,14 +906,15 @@ static void on_invalid_resp_cb(tsi_result status, void* user_data, |
|
|
|
|
const unsigned char* bytes_to_send, |
|
|
|
|
size_t bytes_to_send_size, |
|
|
|
|
tsi_handshaker_result* result) { |
|
|
|
|
GPR_ASSERT(status == TSI_DATA_CORRUPTED); |
|
|
|
|
GPR_ASSERT(user_data == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send_size == 0); |
|
|
|
|
GPR_ASSERT(result == nullptr); |
|
|
|
|
ASSERT_EQ(status, TSI_DATA_CORRUPTED); |
|
|
|
|
ASSERT_EQ(user_data, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send_size, 0); |
|
|
|
|
ASSERT_EQ(result, nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void check_handle_response_invalid_resp() { |
|
|
|
|
TEST(AltsTsiHandshakerTest, CheckHandleResponseInvalidResp) { |
|
|
|
|
should_handshaker_client_api_succeed = false; |
|
|
|
|
/* Initialization. */ |
|
|
|
|
notification_init(&caller_to_tsi_notification); |
|
|
|
|
notification_init(&tsi_to_caller_notification); |
|
|
|
@ -942,14 +978,15 @@ static void on_failed_resp_cb(tsi_result status, void* user_data, |
|
|
|
|
const unsigned char* bytes_to_send, |
|
|
|
|
size_t bytes_to_send_size, |
|
|
|
|
tsi_handshaker_result* result) { |
|
|
|
|
GPR_ASSERT(status == TSI_INVALID_ARGUMENT); |
|
|
|
|
GPR_ASSERT(user_data == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send_size == 0); |
|
|
|
|
GPR_ASSERT(result == nullptr); |
|
|
|
|
ASSERT_EQ(status, TSI_INVALID_ARGUMENT); |
|
|
|
|
ASSERT_EQ(user_data, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send_size, 0); |
|
|
|
|
ASSERT_EQ(result, nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void check_handle_response_failure() { |
|
|
|
|
TEST(AltsTsiHandshakerTest, CheckHandleResponseFailure) { |
|
|
|
|
should_handshaker_client_api_succeed = false; |
|
|
|
|
/* Initialization. */ |
|
|
|
|
notification_init(&caller_to_tsi_notification); |
|
|
|
|
notification_init(&tsi_to_caller_notification); |
|
|
|
@ -986,14 +1023,15 @@ static void on_shutdown_resp_cb(tsi_result status, void* user_data, |
|
|
|
|
const unsigned char* bytes_to_send, |
|
|
|
|
size_t bytes_to_send_size, |
|
|
|
|
tsi_handshaker_result* result) { |
|
|
|
|
GPR_ASSERT(status == TSI_HANDSHAKE_SHUTDOWN); |
|
|
|
|
GPR_ASSERT(user_data == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send == nullptr); |
|
|
|
|
GPR_ASSERT(bytes_to_send_size == 0); |
|
|
|
|
GPR_ASSERT(result == nullptr); |
|
|
|
|
ASSERT_EQ(status, TSI_HANDSHAKE_SHUTDOWN); |
|
|
|
|
ASSERT_EQ(user_data, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send, nullptr); |
|
|
|
|
ASSERT_EQ(bytes_to_send_size, 0); |
|
|
|
|
ASSERT_EQ(result, nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void check_handle_response_after_shutdown() { |
|
|
|
|
TEST(AltsTsiHandshakerTest, CheckHandleResponseAfterShutdown) { |
|
|
|
|
should_handshaker_client_api_succeed = true; |
|
|
|
|
/* Initialization. */ |
|
|
|
|
notification_init(&caller_to_tsi_notification); |
|
|
|
|
notification_init(&tsi_to_caller_notification); |
|
|
|
@ -1027,7 +1065,8 @@ static void check_handle_response_after_shutdown() { |
|
|
|
|
notification_destroy(&tsi_to_caller_notification); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void check_handshaker_next_fails_after_shutdown() { |
|
|
|
|
TEST(AltsTsiHandshakerTest, CheckHandshakerNextFailsAfterShutdown) { |
|
|
|
|
should_handshaker_client_api_succeed = true; |
|
|
|
|
/* Initialization. */ |
|
|
|
|
notification_init(&caller_to_tsi_notification); |
|
|
|
|
notification_init(&tsi_to_caller_notification); |
|
|
|
@ -1043,7 +1082,8 @@ void check_handshaker_next_fails_after_shutdown() { |
|
|
|
|
notification_destroy(&tsi_to_caller_notification); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void check_handshaker_success() { |
|
|
|
|
TEST(AltsTsiHandshakerTest, CheckHandshakerSuccess) { |
|
|
|
|
should_handshaker_client_api_succeed = true; |
|
|
|
|
/* Initialization. */ |
|
|
|
|
notification_init(&caller_to_tsi_notification); |
|
|
|
|
notification_init(&tsi_to_caller_notification); |
|
|
|
@ -1060,26 +1100,10 @@ void check_handshaker_success() { |
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) { |
|
|
|
|
grpc::testing::TestEnvironment env(&argc, argv); |
|
|
|
|
/* Initialization. */ |
|
|
|
|
grpc_init(); |
|
|
|
|
::testing::InitGoogleTest(&argc, argv); |
|
|
|
|
grpc::testing::TestGrpcScope grpc_scope; |
|
|
|
|
grpc_alts_shared_resource_dedicated_init(); |
|
|
|
|
/* Tests. */ |
|
|
|
|
should_handshaker_client_api_succeed = true; |
|
|
|
|
check_handshaker_success(); |
|
|
|
|
check_handshaker_next_invalid_input(); |
|
|
|
|
check_handshaker_next_fails_after_shutdown(); |
|
|
|
|
check_handle_response_after_shutdown(); |
|
|
|
|
should_handshaker_client_api_succeed = false; |
|
|
|
|
check_handshaker_shutdown_invalid_input(); |
|
|
|
|
check_handshaker_next_failure(); |
|
|
|
|
check_handle_response_nullptr_handshaker(); |
|
|
|
|
check_handle_response_nullptr_recv_bytes(); |
|
|
|
|
check_handle_response_failed_grpc_call_to_handshaker_service(); |
|
|
|
|
check_handle_response_failed_recv_message_from_handshaker_service(); |
|
|
|
|
check_handle_response_invalid_resp(); |
|
|
|
|
check_handle_response_failure(); |
|
|
|
|
/* Cleanup. */ |
|
|
|
|
int ret = RUN_ALL_TESTS(); |
|
|
|
|
grpc_alts_shared_resource_dedicated_shutdown(); |
|
|
|
|
grpc_shutdown(); |
|
|
|
|
return 0; |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|