浏览代码

fixed null peer attributes test error and added method logging

Danny Reidenbach 5 年之前
父节点
当前提交
9f6d8c5d1b

+ 10 - 0
src/core/tsi/alts/handshaker/alts_handshaker_client.cc

@@ -192,9 +192,11 @@ static void handle_response_done(alts_grpc_handshaker_client* client,
 
 void alts_handshaker_client_handle_response(alts_handshaker_client* c,
                                             bool is_ok) {
+  gpr_log(GPR_ERROR, "alts handshaker client handle response");
   GPR_ASSERT(c != nullptr);
   alts_grpc_handshaker_client* client =
       reinterpret_cast<alts_grpc_handshaker_client*>(c);
+  gpr_log(GPR_ERROR,"recv_buffer pulled from given client");
   grpc_byte_buffer* recv_buffer = client->recv_buffer;
   grpc_status_code status = client->status;
   alts_tsi_handshaker* handshaker = client->handshaker;
@@ -228,7 +230,9 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
     handle_response_done(client, TSI_INTERNAL_ERROR, nullptr, 0, nullptr);
     return;
   }
+  gpr_log(GPR_ERROR, "set up of alts handshaker client handle response arena");
   upb::Arena arena;
+  gpr_log(GPR_ERROR, "HandshakerResp created from recv buffer");
   grpc_gcp_HandshakerResp* resp =
       alts_tsi_utils_deserialize_response(recv_buffer, arena.ptr());
   grpc_byte_buffer_destroy(client->recv_buffer);
@@ -246,6 +250,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
     handle_response_done(client, TSI_DATA_CORRUPTED, nullptr, 0, nullptr);
     return;
   }
+  gpr_log(GPR_ERROR, "alts handshaker client handle get bytes");
   upb_strview out_frames = grpc_gcp_HandshakerResp_out_frames(resp);
   unsigned char* bytes_to_send = nullptr;
   size_t bytes_to_send_size = 0;
@@ -261,7 +266,9 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
   }
   tsi_handshaker_result* result = nullptr;
   if (is_handshake_finished_properly(resp)) {
+    gpr_log(GPR_ERROR, "alts handshaker client handle response CALL TO RESULT CREATE");
     alts_tsi_handshaker_result_create(resp, client->is_client, &result);
+    gpr_log(GPR_ERROR, "RESULT CREATE FINISH");
     alts_tsi_handshaker_result_set_unused_bytes(
         result, &client->recv_bytes,
         grpc_gcp_HandshakerResp_bytes_consumed(resp));
@@ -269,6 +276,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
   grpc_status_code code = static_cast<grpc_status_code>(
       grpc_gcp_HandshakerStatus_code(resp_status));
   if (code != GRPC_STATUS_OK) {
+    gpr_log(GPR_ERROR, "alts handshaker client handle status code");
     upb_strview details = grpc_gcp_HandshakerStatus_details(resp_status);
     if (details.size > 0) {
       char* error_details = (char*)gpr_zalloc(details.size + 1);
@@ -281,6 +289,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
   // invoking the TSI callback directly if we aren't done yet, if
   // handle_response_done's allocation per message received causes
   // a performance issue.
+  gpr_log(GPR_ERROR, "alts handshaker client handle response handle response done");
   handle_response_done(client, alts_tsi_utils_convert_to_tsi_result(code),
                        bytes_to_send, bytes_to_send_size, result);
 }
@@ -681,6 +690,7 @@ alts_handshaker_client* alts_grpc_handshaker_client_create(
     grpc_iomgr_cb_func grpc_cb, tsi_handshaker_on_next_done_cb cb,
     void* user_data, alts_handshaker_client_vtable* vtable_for_testing,
     bool is_client, size_t max_frame_size) {
+  gpr_log(GPR_ERROR, "alts_grpc_handshaker_client_create");
   if (channel == nullptr || handshaker_service_url == nullptr) {
     gpr_log(GPR_ERROR, "Invalid arguments to alts_handshaker_client_create()");
     return nullptr;

+ 13 - 2
src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc

@@ -84,6 +84,7 @@ typedef struct alts_tsi_handshaker_result {
 
 static tsi_result handshaker_result_extract_peer(
     const tsi_handshaker_result* self, tsi_peer* peer) {
+  gpr_log(GPR_ERROR, "handshaker_result_extract_peer");
   if (self == nullptr || peer == nullptr) {
     gpr_log(GPR_ERROR, "Invalid argument to handshaker_result_extract_peer()");
     return TSI_INVALID_ARGUMENT;
@@ -255,6 +256,7 @@ static const tsi_handshaker_result_vtable result_vtable = {
 tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp,
                                              bool is_client,
                                              tsi_handshaker_result** self) {
+  gpr_log(GPR_ERROR, "Start of result create METHOD OF INTEREST");
 
   if (self == nullptr || resp == nullptr) {
     gpr_log(GPR_ERROR, "Invalid arguments to create_handshaker_result()");
@@ -311,6 +313,8 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp,
     gpr_log(GPR_ERROR, "Invalid peer identity");
     return TSI_FAILED_PRECONDITION;
   }
+  // client next side add teh map key value
+  // let ashitha know what the issue was
 
 
 
@@ -356,6 +360,7 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp,
     gpr_log(GPR_ERROR, "Null Peer Identity.");
     return TSI_FAILED_PRECONDITION;
   }
+  // need to searilze before storing
 
   size_t sample = 2048; // removing this line removes errors messages e0612
   size_t* lenz = &sample;
@@ -363,10 +368,11 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp,
   // where do these labeled functions come from --> upb genreated files
   // grpc_gcp_Identity_AttributesEntry** peer_attributes_counter = peer_attributes;
   if(peer_attributes == nullptr ) { //|| *peer_attributes_counter == nullptr) {
-    gpr_log(GPR_ERROR, "Null Peer Attributes.");
-    GPR_ASSERT(0);
+    gpr_log(GPR_ERROR, "Null PEER ATTRIBUTES.");
+    // GPR_ASSERT(0);
     return TSI_FAILED_PRECONDITION; //This is triggering
   }
+  gpr_log(GPR_ERROR, "NON NULL PEER ATTRIBUTES");
   // // while(*peer_attributes_counter != nullptr) {//map<string, string>::iterator it = peer_attributes.begin(); it != peer_attributes.end(); it++ ) {
   // //   grpc_gcp_AltsContext_PeerAttributesEntry* peer_entry = grpc_gcp_AltsContext_add_peer_attributes(context, context_arena.ptr());
   // //   upb_strview key = grpc_gcp_Identity_AttributesEntry_key(*peer_attributes_counter); USE CONST_CAST
@@ -527,6 +533,7 @@ static tsi_result handshaker_next(
     size_t received_bytes_size, const unsigned char** /*bytes_to_send*/,
     size_t* /*bytes_to_send_size*/, tsi_handshaker_result** /*result*/,
     tsi_handshaker_on_next_done_cb cb, void* user_data) {
+  gpr_log(GPR_ERROR, "start of handshaker next");
   if (self == nullptr || cb == nullptr) {
     gpr_log(GPR_ERROR, "Invalid arguments to handshaker_next()");
     return TSI_INVALID_ARGUMENT;
@@ -646,6 +653,8 @@ tsi_result alts_tsi_handshaker_create(
     const char* handshaker_service_url, bool is_client,
     grpc_pollset_set* interested_parties, tsi_handshaker** self,
     size_t user_specified_max_frame_size) {
+  gpr_log(GPR_ERROR, "alts_tsi_handshaker_create");
+
   if (handshaker_service_url == nullptr || self == nullptr ||
       options == nullptr || (is_client && target_name == nullptr)) {
     gpr_log(GPR_ERROR, "Invalid arguments to alts_tsi_handshaker_create()");
@@ -678,6 +687,7 @@ tsi_result alts_tsi_handshaker_create(
 void alts_tsi_handshaker_result_set_unused_bytes(tsi_handshaker_result* self,
                                                  grpc_slice* recv_bytes,
                                                  size_t bytes_consumed) {
+  gpr_log(GPR_ERROR, "set unused_bytes");
   GPR_ASSERT(recv_bytes != nullptr && self != nullptr);
   if (GRPC_SLICE_LENGTH(*recv_bytes) == bytes_consumed) {
     return;
@@ -703,6 +713,7 @@ bool alts_tsi_handshaker_get_has_sent_start_message_for_testing(
 
 void alts_tsi_handshaker_set_client_vtable_for_testing(
     alts_tsi_handshaker* handshaker, alts_handshaker_client_vtable* vtable) {
+  gpr_log(GPR_ERROR, "set client vtable for testing");
   GPR_ASSERT(handshaker != nullptr);
   handshaker->client_vtable_for_testing = vtable;
 }

+ 48 - 0
test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc

@@ -51,6 +51,8 @@
   "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_PEER_ATTRIBUTES_KEY "peer"
+#define ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_VALUE "attributes"
 
 using grpc_core::internal::alts_handshaker_client_check_fields_for_testing;
 using grpc_core::internal::alts_handshaker_client_get_handshaker_for_testing;
@@ -122,9 +124,11 @@ static void wait(notification* n) {
  */
 static grpc_byte_buffer* generate_handshaker_response(
     alts_handshaker_response_type type) {
+  gpr_log(GPR_ERROR, "start of generate handshaker response");
   upb::Arena arena;
   grpc_gcp_HandshakerResult* result;
   grpc_gcp_Identity* peer_identity;
+  grpc_gcp_Identity_AttributesEntry* test_peer_attributes_entry;
   grpc_gcp_HandshakerResp* resp = grpc_gcp_HandshakerResp_new(arena.ptr());
   grpc_gcp_HandshakerStatus* status =
       grpc_gcp_HandshakerResp_mutable_status(resp, arena.ptr());
@@ -134,11 +138,15 @@ static grpc_byte_buffer* generate_handshaker_response(
     case INVALID:
       break;
     case CLIENT_START:
+      gpr_log(GPR_ERROR, "start of generate handshaker response client start");
     case SERVER_START:
+      gpr_log(GPR_ERROR, "start of generate handshaker response server start");
       grpc_gcp_HandshakerResp_set_out_frames(
           resp, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME));
       break;
     case CLIENT_NEXT:
+    // doggo
+      gpr_log(GPR_ERROR, "start of generate handshaker response client next");
       grpc_gcp_HandshakerResp_set_out_frames(
           resp, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME));
       grpc_gcp_HandshakerResp_set_bytes_consumed(
@@ -146,11 +154,24 @@ static grpc_byte_buffer* generate_handshaker_response(
       result = grpc_gcp_HandshakerResp_mutable_result(resp, arena.ptr());
       peer_identity =
           grpc_gcp_HandshakerResult_mutable_peer_identity(result, arena.ptr());
+      gpr_log(GPR_ERROR, "Setting Peer Identity in generate handshaker response client next");
+
+       // doggo this set of code gets it to not fail once but creates the same error later on
+      test_peer_attributes_entry = grpc_gcp_Identity_add_attributes(peer_identity, arena.ptr());
+      grpc_gcp_Identity_AttributesEntry_set_key(test_peer_attributes_entry, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_KEY));
+      grpc_gcp_Identity_AttributesEntry_set_value(test_peer_attributes_entry, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_VALUE));
+      gpr_log(GPR_ERROR, "DEFINED PEER ATTRIBUTES ENTRY AND VALUES");
+
+
+
       grpc_gcp_Identity_set_service_account(
           peer_identity,
           upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY));
       grpc_gcp_HandshakerResult_set_key_data(
           result, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_KEY_DATA));
+
+
+
       GPR_ASSERT(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,
@@ -168,13 +189,23 @@ static grpc_byte_buffer* generate_handshaker_response(
           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);
+      gpr_log(GPR_ERROR, "start of generate handshaker response finished setting client info");
       break;
     case SERVER_NEXT:
+      gpr_log(GPR_ERROR, "start of generate handshaker response server next");
       grpc_gcp_HandshakerResp_set_bytes_consumed(
           resp, strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME));
       result = grpc_gcp_HandshakerResp_mutable_result(resp, arena.ptr());
       peer_identity =
           grpc_gcp_HandshakerResult_mutable_peer_identity(result, arena.ptr());
+
+        // doggo this set of code gets it to not fail once but creates the same error later on
+      test_peer_attributes_entry = grpc_gcp_Identity_add_attributes(peer_identity, arena.ptr());
+      grpc_gcp_Identity_AttributesEntry_set_key(test_peer_attributes_entry, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_KEY));
+      grpc_gcp_Identity_AttributesEntry_set_value(test_peer_attributes_entry, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_VALUE));
+      gpr_log(GPR_ERROR, "DEFINED PEER ATTRIBUTES ENTRY AND VALUES");
+
+      
       grpc_gcp_Identity_set_service_account(
           peer_identity,
           upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY));
@@ -281,6 +312,7 @@ 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_log(GPR_ERROR, "start of on_client_next_success_cb");
   GPR_ASSERT(status == TSI_OK);
   GPR_ASSERT(user_data == nullptr);
   GPR_ASSERT(bytes_to_send_size == strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME));
@@ -502,15 +534,19 @@ static alts_handshaker_client_vtable vtable = {mock_client_start,
                                                mock_shutdown, mock_destruct};
 
 static tsi_handshaker* create_test_handshaker(bool is_client) {
+  gpr_log(GPR_ERROR, "create test handshaker");
   tsi_handshaker* handshaker = nullptr;
   grpc_alts_credentials_options* options =
       grpc_alts_credentials_client_options_create();
+  gpr_log(GPR_ERROR, "create test handhsaker CANNOT FIND: Where is grpc_alts_credentials_client_options_create");
   alts_tsi_handshaker_create(options, "target_name",
                              ALTS_HANDSHAKER_SERVICE_URL_FOR_TESTING, is_client,
                              nullptr, &handshaker, 0);
   alts_tsi_handshaker* alts_handshaker =
       reinterpret_cast<alts_tsi_handshaker*>(handshaker);
+  gpr_log(GPR_ERROR, "create test handshaker set v table. WHAT IS THIS VTABLE");
   alts_tsi_handshaker_set_client_vtable_for_testing(alts_handshaker, &vtable);
+  gpr_log(GPR_ERROR, "create tset handshaker destroy handshaker options");
   grpc_alts_credentials_options_destroy(options);
   return handshaker;
 }
@@ -550,23 +586,28 @@ static void check_handshaker_next_success() {
    * Create handshakers for which internal mock client is going to do
    * correctness check.
    */
+  gpr_log(GPR_ERROR, "start of check_handshaker_next_success");
   tsi_handshaker* client_handshaker =
       create_test_handshaker(true /* is_client */);
   tsi_handshaker* server_handshaker =
       create_test_handshaker(false /* is_client */);
   /* Client start. */
+  gpr_log(GPR_ERROR, "check handshaker next success client start");
   GPR_ASSERT(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_log(GPR_ERROR, "check handshaker next success 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);
+  gpr_log(GPR_ERROR, "check handshaker next success client next pre wait");
   wait(&tsi_to_caller_notification);
   /* Server start. */
+  gpr_log(GPR_ERROR, "check handshaker next success  server start");
   GPR_ASSERT(tsi_handshaker_next(server_handshaker, nullptr, 0, nullptr,
                                  nullptr, nullptr, on_server_start_success_cb,
                                  nullptr) == TSI_ASYNC);
@@ -850,10 +891,12 @@ static void check_handle_response_invalid_resp() {
 }
 
 static void check_handle_response_success(void* /*unused*/) {
+  gpr_log(GPR_ERROR, "Start of check handle response success");
   /* Client start. */
   wait(&caller_to_tsi_notification);
   alts_handshaker_client_handle_response(cb_event, true /* is_ok */);
   /* Client next. */
+  gpr_log(GPR_ERROR, "check handle response success client next");
   wait(&caller_to_tsi_notification);
   alts_handshaker_client_handle_response(cb_event, true /* is_ok */);
   alts_handshaker_client_ref_for_testing(cb_event);
@@ -863,9 +906,11 @@ static void check_handle_response_success(void* /*unused*/) {
         cb_event, GRPC_STATUS_OK, GRPC_ERROR_NONE);
   }
   /* Server start. */
+  gpr_log(GPR_ERROR, "check handle response success server start");
   wait(&caller_to_tsi_notification);
   alts_handshaker_client_handle_response(cb_event, true /* is_ok */);
   /* Server next. */
+  gpr_log(GPR_ERROR, "check handle response success server next");
   wait(&caller_to_tsi_notification);
   alts_handshaker_client_handle_response(cb_event, true /* is_ok */);
   alts_handshaker_client_ref_for_testing(cb_event);
@@ -983,11 +1028,13 @@ void check_handshaker_next_fails_after_shutdown() {
 
 void check_handshaker_success() {
   /* Initialization. */
+  gpr_log(GPR_ERROR, "Start of check handshaker success");
   notification_init(&caller_to_tsi_notification);
   notification_init(&tsi_to_caller_notification);
   /* Tests. */
   grpc_core::Thread thd("alts_tsi_handshaker_test",
                         &check_handle_response_success, nullptr);
+  gpr_log(GPR_ERROR, "handshaker success thread");
   thd.Start();
   check_handshaker_next_success();
   thd.Join();
@@ -1003,6 +1050,7 @@ int main(int argc, char** argv) {
   grpc_alts_shared_resource_dedicated_init();
   /* Tests. */
   should_handshaker_client_api_succeed = true;
+  gpr_log(GPR_ERROR, "Starting tests from main");
   check_handshaker_success();
   check_handshaker_next_invalid_input();
   check_handshaker_next_fails_after_shutdown();