Added tests.

pull/22292/head
Ashitha Santhosh 5 years ago
parent 895a46564a
commit 72112d034e
  1. 2
      src/core/tsi/alts/handshaker/alts_handshaker_client.h
  2. 2
      src/core/tsi/alts/handshaker/alts_tsi_handshaker.h
  3. 20
      test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc
  4. 32
      test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc

@ -134,7 +134,7 @@ void alts_handshaker_client_destroy(alts_handshaker_client* client);
* - is_client: a boolean value indicating if the created handshaker client is
* used at the client (is_client = true) or server (is_client = false) side.
* - max_frame_size: Maximum frame size used by frame protector (User specified
* maximum frame size if present or default max frame size).
* maximum frame size if present or default max frame size).
*
* It returns the created ALTS handshaker client on success, and NULL
* on failure.

@ -55,7 +55,7 @@ typedef struct alts_tsi_handshaker alts_tsi_handshaker;
* - self: address of ALTS TSI handshaker instance to be returned from the
* method.
* - user_specified_max_frame_size: Determines the maximum frame size used by
* frame protector that is specified via user. If unspecified, the value is 0.
* frame protector that is specified via user. If unspecified, the value is 0.
*
* It returns TSI_OK on success and an error status code on failure. Note that
* if interested_parties is nullptr, a dedicated TSI thread will be created and

@ -31,6 +31,7 @@
#define ALTS_HANDSHAKER_CLIENT_TEST_TARGET_NAME "bigtable.google.api.com"
#define ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT1 "A@google.com"
#define ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT2 "B@google.com"
#define ALTS_HANDSHAKER_CLIENT_TEST_MAX_FRAME_SIZE 64 * 1024
const size_t kHandshakerClientOpNum = 4;
const size_t kMaxRpcVersionMajor = 3;
@ -155,8 +156,8 @@ static grpc_call_error check_must_not_be_called(grpc_call* /*call*/,
/**
* A mock grpc_caller used to check correct execution of client_start operation.
* It checks if the client_start handshaker request is populated with correct
* handshake_security_protocol, application_protocol, and record_protocol, and
* op is correctly populated.
* handshake_security_protocol, application_protocol, record_protocol and
* max_frame_size, and op is correctly populated.
*/
static grpc_call_error check_client_start_success(grpc_call* /*call*/,
const grpc_op* op,
@ -196,7 +197,8 @@ static grpc_call_error check_client_start_success(grpc_call* /*call*/,
GPR_ASSERT(upb_strview_eql(
grpc_gcp_StartClientHandshakeReq_target_name(client_start),
upb_strview_makez(ALTS_HANDSHAKER_CLIENT_TEST_TARGET_NAME)));
GPR_ASSERT(grpc_gcp_StartClientHandshakeReq_max_frame_size(
client_start, ALTS_HANDSHAKER_CLIENT_TEST_MAX_FRAME_SIZE));
GPR_ASSERT(validate_op(client, op, nops, true /* is_start */));
return GRPC_CALL_OK;
}
@ -204,8 +206,8 @@ static grpc_call_error check_client_start_success(grpc_call* /*call*/,
/**
* A mock grpc_caller used to check correct execution of server_start operation.
* It checks if the server_start handshaker request is populated with correct
* handshake_security_protocol, application_protocol, and record_protocol, and
* op is correctly populated.
* handshake_security_protocol, application_protocol, record_protocol and
* max_frame_size, and op is correctly populated.
*/
static grpc_call_error check_server_start_success(grpc_call* /*call*/,
const grpc_op* op,
@ -245,6 +247,8 @@ static grpc_call_error check_server_start_success(grpc_call* /*call*/,
upb_strview_makez(ALTS_RECORD_PROTOCOL)));
validate_rpc_protocol_versions(
grpc_gcp_StartServerHandshakeReq_rpc_versions(server_start));
GPR_ASSERT(grpc_gcp_StartServerHandshakeReq_max_frame_size(
server_start, ALTS_HANDSHAKER_CLIENT_TEST_MAX_FRAME_SIZE));
GPR_ASSERT(validate_op(client, op, nops, true /* is_start */));
return GRPC_CALL_OK;
}
@ -321,12 +325,14 @@ static alts_handshaker_client_test_config* create_config() {
nullptr, config->channel, ALTS_HANDSHAKER_SERVICE_URL_FOR_TESTING,
nullptr, server_options,
grpc_slice_from_static_string(ALTS_HANDSHAKER_CLIENT_TEST_TARGET_NAME),
nullptr, nullptr, nullptr, nullptr, false);
nullptr, nullptr, nullptr, nullptr, false,
ALTS_HANDSHAKER_CLIENT_TEST_MAX_FRAME_SIZE);
config->client = alts_grpc_handshaker_client_create(
nullptr, config->channel, ALTS_HANDSHAKER_SERVICE_URL_FOR_TESTING,
nullptr, client_options,
grpc_slice_from_static_string(ALTS_HANDSHAKER_CLIENT_TEST_TARGET_NAME),
nullptr, nullptr, nullptr, nullptr, true);
nullptr, nullptr, nullptr, nullptr, true,
ALTS_HANDSHAKER_CLIENT_TEST_MAX_FRAME_SIZE);
GPR_ASSERT(config->client != nullptr);
GPR_ASSERT(config->server != nullptr);
grpc_alts_credentials_options_destroy(client_options);

@ -49,6 +49,9 @@
#define ALTS_TSI_HANDSHAKER_TEST_APPLICATION_PROTOCOL \
"test application protocol"
#define ALTS_TSI_HANDSHAKER_TEST_RECORD_PROTOCOL "test record protocol"
#define ALTS_TSI_HANDSHAKER_TEST_MAX_FRAME_SIZE 256 * 1024
#define ALTS_TSI_HANDSHAKER_TEST_DEFAULT_MAX_FRAME_SIZE 128 * 1024
#define ALTS_TSI_HANDSHAKER_TEST_MIN_MAX_FRAME_SIZE 16 * 1024
using grpc_core::internal::alts_handshaker_client_check_fields_for_testing;
using grpc_core::internal::alts_handshaker_client_get_handshaker_for_testing;
@ -164,6 +167,8 @@ static grpc_byte_buffer* generate_handshaker_response(
upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_APPLICATION_PROTOCOL));
grpc_gcp_HandshakerResult_set_record_protocol(
result, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_RECORD_PROTOCOL));
grpc_gcp_HandshakerResult_set_max_frame_size(
result, ALTS_TSI_HANDSHAKER_TEST_MAX_FRAME_SIZE);
break;
case SERVER_NEXT:
grpc_gcp_HandshakerResp_set_bytes_consumed(
@ -283,6 +288,17 @@ static void on_client_next_success_cb(tsi_result status, void* user_data,
GPR_ASSERT(memcmp(bytes_to_send, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME,
bytes_to_send_size) == 0);
GPR_ASSERT(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;
GPR_ASSERT(tsi_handshaker_result_create_zero_copy_frame_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,
ALTS_TSI_HANDSHAKER_TEST_DEFAULT_MAX_FRAME_SIZE);
/* Validate peer identity. */
tsi_peer peer;
GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == TSI_OK);
@ -343,6 +359,20 @@ static void on_server_next_success_cb(tsi_result status, void* user_data,
GPR_ASSERT(bytes_to_send_size == 0);
GPR_ASSERT(bytes_to_send == nullptr);
GPR_ASSERT(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;
size_t user_specified_max_frame_size =
ALTS_TSI_HANDSHAKER_TEST_MAX_FRAME_SIZE;
GPR_ASSERT(tsi_handshaker_result_create_zero_copy_frame_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,
ALTS_TSI_HANDSHAKER_TEST_MIN_MAX_FRAME_SIZE);
/* Validate peer identity. */
tsi_peer peer;
GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == TSI_OK);
@ -478,7 +508,7 @@ static tsi_handshaker* create_test_handshaker(bool is_client) {
grpc_alts_credentials_client_options_create();
alts_tsi_handshaker_create(options, "target_name",
ALTS_HANDSHAKER_SERVICE_URL_FOR_TESTING, is_client,
nullptr, &handshaker);
nullptr, &handshaker, 0);
alts_tsi_handshaker* alts_handshaker =
reinterpret_cast<alts_tsi_handshaker*>(handshaker);
alts_tsi_handshaker_set_client_vtable_for_testing(alts_handshaker, &vtable);

Loading…
Cancel
Save