瀏覽代碼

upb issues with peer attributes next mutable method.

Danny Reidenbach 5 年之前
父節點
當前提交
7bab343c92

+ 5 - 6
src/core/tsi/alts/handshaker/alts_handshaker_client.cc

@@ -268,23 +268,22 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
   }
   tsi_handshaker_result* result = nullptr;
   if (is_handshake_finished_properly(resp)) {
-<<<<<<< HEAD
+
     gpr_log(GPR_ERROR, "alts handshaker client handle response CALL TO RESULT CREATE");
-    alts_tsi_handshaker_result_create(resp, client->is_client, &result);
+    tsi_result status = alts_tsi_handshaker_result_create(resp, client->is_client, &result);
     gpr_log(GPR_ERROR, "RESULT CREATE FINISH");
-=======
-    tsi_result status =
-        alts_tsi_handshaker_result_create(resp, client->is_client, &result);
+
     if (status != TSI_OK) {
       gpr_log(GPR_ERROR, "alts_tsi_handshaker_result_create() failed");
       handle_response_done(client, status, nullptr, 0, nullptr);
       return;
     }
->>>>>>> upstream/master
+
     alts_tsi_handshaker_result_set_unused_bytes(
         result, &client->recv_bytes,
         grpc_gcp_HandshakerResp_bytes_consumed(resp));
   }
+  
   grpc_status_code code = static_cast<grpc_status_code>(
       grpc_gcp_HandshakerStatus_code(resp_status));
   if (code != GRPC_STATUS_OK) {

+ 14 - 30
src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc

@@ -347,51 +347,35 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp,
   grpc_gcp_AltsContext_set_peer_rpc_versions(
       context, const_cast<grpc_gcp_RpcProtocolVersions*>(peer_rpc_version));
 
-
+// START OF PLUMBING
   grpc_gcp_HandshakerResult* ncresult = const_cast<grpc_gcp_HandshakerResult*>(hresult);
   grpc_gcp_Identity* peer_identity = const_cast<grpc_gcp_Identity*>(identity);
   if(peer_identity == nullptr ) { //|| *peer_attributes_counter == nullptr) {
     gpr_log(GPR_ERROR, "Null Peer Identity.");
     return TSI_FAILED_PRECONDITION;
   }
-  
+
+  if ( ! grpc_gcp_Identity_has_attributes(const_cast<grpc_gcp_Identity*>(peer_identity))) {
+        gpr_log(GPR_ERROR, "XOXO  Failed to DEFINE PEER ATTRIBUTES ENTRY AND VALUES");
+      }
+
   size_t iter;
   grpc_gcp_Identity_AttributesEntry* peer_attributes_entry = grpc_gcp_Identity_attributes_nextmutable(peer_identity, &iter);
+  if(peer_attributes_entry == nullptr ) { //|| *peer_attributes_counter == nullptr) {
+    gpr_log(GPR_ERROR, "XXXXXX Null Peer ENTRY.");
+    return TSI_FAILED_PRECONDITION;
+  }
 
-   while ( peer_attributes_entry != nullptr) {
-    upb_strview key = grpc_gcp_Identity_AttributesEntry_key(const_cast<grpc_gcp_AltsContext_PeerAttributesEntry*>(peer_attributes_entry));
-    upb_strview val = grpc_gcp_Identity_AttributesEntry_value(const_cast<grpc_gcp_AltsContext_PeerAttributesEntry*>(peer_attributes_entry));
+  while ( peer_attributes_entry != nullptr) {
+    upb_strview key = grpc_gcp_Identity_AttributesEntry_key(const_cast<grpc_gcp_Identity_AttributesEntry*>(peer_attributes_entry));
+    upb_strview val = grpc_gcp_Identity_AttributesEntry_value(const_cast<grpc_gcp_Identity_AttributesEntry*>(peer_attributes_entry));
     grpc_gcp_AltsContext_peer_attributes_set(context, key, val, context_arena.ptr());
     peer_attributes_entry = grpc_gcp_Identity_attributes_nextmutable(peer_identity, &iter);
   }
  
 
 
-  // need to searilze before storing
-
-
-  // grpc_gcp_Identity_AttributesEntry** peer_attributes = grpc_gcp_Identity_mutable_attributes(peer_identity, lenz); // need size_t *len)
-  // // 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);
-  //   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
-  // //   upb_strview value = grpc_gcp_Identity_AttributesEntry_value(*peer_attributes_counter);
-  // //   grpc_gcp_AltsContext_PeerAttributesEntry_set_key(peer_entry, key);
-  // //   grpc_gcp_AltsContext_PeerAttributesEntry_set_value(peer_entry, value);
-  //   *peer_attributes_counter++;
-
-  // }
-
-
-
-
+  // serialization below
   size_t serialized_ctx_length;
   char* serialized_ctx = grpc_gcp_AltsContext_serialize(
       context, context_arena.ptr(), &serialized_ctx_length);

+ 52 - 2
test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc

@@ -136,6 +136,8 @@ static grpc_byte_buffer* generate_handshaker_response(
       grpc_gcp_HandshakerResp_mutable_status(resp, arena.ptr());
   grpc_gcp_HandshakerStatus_set_code(status, 0);
   grpc_gcp_Identity* local_identity;
+
+  upb_strview val9;
   switch (type) {
     case INVALID:
       break;
@@ -164,6 +166,14 @@ static grpc_byte_buffer* generate_handshaker_response(
       // 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");
+      if ( ! grpc_gcp_Identity_has_attributes(const_cast<grpc_gcp_Identity*>(peer_identity))) {
+        gpr_log(GPR_ERROR, "XOXO  Failed to DEFINE PEER ATTRIBUTES ENTRY AND VALUES");
+      }
+
+      val9 = upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_VALUE);
+      if (! grpc_gcp_Identity_attributes_get(const_cast<grpc_gcp_Identity*>(peer_identity), upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_KEY), &val9)){
+        gpr_log(GPR_ERROR, "XOXOXO Getting is Failing");
+      }
 
 
 
@@ -192,7 +202,14 @@ 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");
+
+      // upb_strview val = upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_VALUE);
+      // gpr_log(GPR_ERROR, "start of generate handshaker response finished setting client info");
+      // bool getTest = grpc_gcp_Identity_attributes_get(const_cast<grpc_gcp_Identity*>(peer_identity), upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_KEY), &val);
+      // if (! getTest){
+      //   gpr_log(GPR_ERROR, "XOXOXO Getting is Failing");
+      // }
+
       break;
     case SERVER_NEXT:
       gpr_log(GPR_ERROR, "start of generate handshaker response server next");
@@ -203,6 +220,7 @@ static grpc_byte_buffer* generate_handshaker_response(
           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
+      grpc_gcp_Identity_attributes_set(peer_identity, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_KEY), upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_VALUE), arena.ptr());
       // 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));
@@ -311,11 +329,12 @@ static void on_server_start_success_cb(tsi_result status, void* user_data,
   signal(&tsi_to_caller_notification);
 }
 
+//doggo
 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_log(GPR_ERROR, "....... TESTING 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));
@@ -343,6 +362,7 @@ static void on_client_next_success_cb(tsi_result status, void* user_data,
                     peer.properties[1].value.data,
                     peer.properties[1].value.length) == 0);
   /* Validate alts context. */
+  //doggo this is where to add the test
   upb::Arena context_arena;
   grpc_gcp_AltsContext* ctx = grpc_gcp_AltsContext_parse(
       peer.properties[3].value.data, peer.properties[3].value.length,
@@ -361,6 +381,24 @@ static void on_client_next_success_cb(tsi_result status, void* user_data,
                     peer_account.size) == 0);
   GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_LOCAL_IDENTITY, local_account.data,
                     local_account.size) == 0);
+  
+  // // if ( ! grpc_gcp_Identity_has_attributes(const_cast<grpc_gcp_Identity*>(peer_identity))) {
+  // //       gpr_log(GPR_ERROR, "XOXO  Failed to get PEER IDENTITY ATTRIBUTES");
+  // //     }
+  // if ( ! grpc_gcp_AltsContext_has_peer_attributes(const_cast<grpc_gcp_AltsContext*>(ctx))) {
+  //       gpr_log(GPR_ERROR, "XOXO  Failed to get ALTS CONTEXT ATTRIBUTES");
+  //     }
+  // size_t iter;
+  // grpc_gcp_AltsContext_PeerAttributesEntry* peer_attributes_entry = grpc_gcp_AltsContext_peer_attributes_nextmutable(ctx, &iter);
+  // GPR_ASSERT(peer_attributes_entry != nullptr);
+  // while ( peer_attributes_entry != nullptr) {
+  //   upb_strview key = grpc_gcp_AltsContext_PeerAttributesEntry_key(const_cast<grpc_gcp_AltsContext_PeerAttributesEntry*>(peer_attributes_entry));
+  //   upb_strview val = grpc_gcp_AltsContext_PeerAttributesEntry_value(const_cast<grpc_gcp_AltsContext_PeerAttributesEntry*>(peer_attributes_entry));
+  //   GPR_ASSERT(upb_strview_eql(key, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_KEY)));
+  //   GPR_ASSERT(upb_strview_eql(val, upb_strview_makez(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,
@@ -384,6 +422,7 @@ static void on_client_next_success_cb(tsi_result status, void* user_data,
   signal(&tsi_to_caller_notification);
 }
 
+//doggo need to test here too
 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,
@@ -435,6 +474,17 @@ static void on_server_next_success_cb(tsi_result status, void* user_data,
                     peer_account.size) == 0);
   GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_LOCAL_IDENTITY, local_account.data,
                     local_account.size) == 0);
+
+  // size_t iter;
+  // grpc_gcp_AltsContext_PeerAttributesEntry* peer_attributes_entry = grpc_gcp_AltsContext_peer_attributes_nextmutable(ctx, &iter);
+  // while ( peer_attributes_entry != nullptr) {
+  //   upb_strview key = grpc_gcp_AltsContext_PeerAttributesEntry_key(const_cast<grpc_gcp_AltsContext_PeerAttributesEntry*>(peer_attributes_entry));
+  //   upb_strview val = grpc_gcp_AltsContext_PeerAttributesEntry_value(const_cast<grpc_gcp_AltsContext_PeerAttributesEntry*>(peer_attributes_entry));
+  //   GPR_ASSERT(upb_strview_eql(key, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_ATTRIBUTES_KEY)));
+  //   GPR_ASSERT(upb_strview_eql(val, upb_strview_makez(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,