فهرست منبع

Finished Testing Peer Attribute plumbing

Danny Reidenbach 5 سال پیش
والد
کامیت
40abe287bb

+ 1 - 13
src/core/tsi/alts/handshaker/alts_handshaker_client.cc

@@ -194,11 +194,9 @@ 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;
@@ -232,9 +230,7 @@ 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);
@@ -252,7 +248,6 @@ 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;
@@ -268,11 +263,7 @@ 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");
     tsi_result status = alts_tsi_handshaker_result_create(resp, client->is_client, &result);
-    gpr_log(GPR_ERROR, "RESULT CREATE FINISH");
-
     if (status != TSI_OK) {
       gpr_log(GPR_ERROR, "alts_tsi_handshaker_result_create() failed");
       handle_response_done(client, status, nullptr, 0, nullptr);
@@ -283,11 +274,10 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
         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) {
-    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);
@@ -300,7 +290,6 @@ 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);
 }
@@ -703,7 +692,6 @@ 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 - 36
src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc

@@ -86,7 +86,6 @@ 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;
@@ -258,8 +257,6 @@ 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()");
     return TSI_INVALID_ARGUMENT;
@@ -308,11 +305,6 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp,
     return TSI_FAILED_PRECONDITION;
   }
 
-
-
-
-
-
   upb_strview local_service_account =
       grpc_gcp_Identity_service_account(local_identity);
   // We don't check if local service account is empty here
@@ -348,34 +340,24 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp,
       context, const_cast<grpc_gcp_RpcProtocolVersions*>(peer_rpc_version));
 
 // START OF PLUMBING
-  grpc_gcp_HandshakerResult* ncresult = const_cast<grpc_gcp_HandshakerResult*>(hresult);
+  // 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) {
+  if(peer_identity == 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_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);
+  if ( grpc_gcp_Identity_has_attributes(const_cast<grpc_gcp_Identity*>(peer_identity))) {
+    size_t iter = UPB_MAP_BEGIN;
+    grpc_gcp_Identity_AttributesEntry* peer_attributes_entry = grpc_gcp_Identity_attributes_nextmutable(peer_identity, &iter);
+    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);
+    }
   }
  
-
-
-  // serialization below
   size_t serialized_ctx_length;
   char* serialized_ctx = grpc_gcp_AltsContext_serialize(
       context, context_arena.ptr(), &serialized_ctx_length);
@@ -523,7 +505,6 @@ 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;
@@ -643,8 +624,6 @@ 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()");
@@ -677,7 +656,6 @@ 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,7 +681,6 @@ 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;
 }
@@ -719,5 +696,5 @@ alts_handshaker_client* alts_tsi_handshaker_get_client_for_testing(
   return handshaker->client;
 }
 
-}  // namespace internal
-}  // namespace grpc_core
+}
+}

+ 0 - 13
test/core/tsi/alts/handshaker/BUILD

@@ -40,19 +40,6 @@ grpc_cc_test(
         "//test/core/util:grpc_test_util",
     ],
 )
-grpc_cc_test(
-    name = "alts_tsi_handshaker_peer_attributes_test",
-    srcs = ["alts_tsi_handshaker_peer_attributes_test.cc"],
-    language = "C++",
-    deps = [
-        ":alts_handshaker_service_api_test_lib",
-        "//:gpr",
-        "//:gpr_base",
-        "//:grpc",
-        "//:tsi",
-        "//test/core/util:grpc_test_util",
-    ],
-)
 
 grpc_cc_test(
     name = "alts_tsi_handshaker_test",

+ 0 - 248
test/core/tsi/alts/handshaker/alts_tsi_handshaker_peer_attributes_test.cc

@@ -1,248 +0,0 @@
-/*
- *
- * Copyright 2018 gRPC authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <iostream>
-
-#include <grpc/grpc.h>
-#include <grpc/support/sync.h>
-
-#include "src/core/lib/gprpp/thd.h"
-#include "src/core/tsi/alts/handshaker/alts_handshaker_client.h"
-#include "src/core/tsi/alts/handshaker/alts_shared_resource.h"
-#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h"
-#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h"
-#include "src/core/tsi/transport_security_grpc.h"
-#include "src/proto/grpc/gcp/altscontext.upb.h"
-#include "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h"
-#include "test/core/util/test_config.h"
-
-#define ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES "Hello World"
-#define ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME "Hello Google"
-#define ALTS_TSI_HANDSHAKER_TEST_CONSUMED_BYTES "Hello "
-#define ALTS_TSI_HANDSHAKER_TEST_REMAIN_BYTES "Google"
-#define ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY "chapi@service.google.com"
-#define ALTS_TSI_HANDSHAKER_TEST_SECURITY_LEVEL "TSI_PRIVACY_AND_INTEGRITY"
-#define ALTS_TSI_HANDSHAKER_TEST_KEY_DATA \
-  "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKL"
-#define ALTS_TSI_HANDSHAKER_TEST_BUFFER_SIZE 100
-#define ALTS_TSI_HANDSHAKER_TEST_SLEEP_TIME_IN_SECONDS 2
-#define ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MAJOR 3
-#define ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MINOR 2
-#define ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MAJOR 2
-#define ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MINOR 1
-#define ALTS_TSI_HANDSHAKER_TEST_LOCAL_IDENTITY "chapilocal@service.google.com"
-#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_ATTRIBUTE_KEY "peer"
-#define ALTS_TSI_HANDSHAKER_TEST_ATTRIBUTE_VALUE "attribute"
-
-using grpc_core::internal::alts_handshaker_client_check_fields_for_testing;
-using grpc_core::internal::alts_handshaker_client_get_handshaker_for_testing;
-using grpc_core::internal::
-    alts_handshaker_client_get_recv_buffer_addr_for_testing;
-using grpc_core::internal::
-    alts_handshaker_client_on_status_received_for_testing;
-using grpc_core::internal::alts_handshaker_client_ref_for_testing;
-using grpc_core::internal::alts_handshaker_client_set_cb_for_testing;
-using grpc_core::internal::alts_handshaker_client_set_fields_for_testing;
-using grpc_core::internal::alts_handshaker_client_set_recv_bytes_for_testing;
-using grpc_core::internal::alts_handshaker_client_set_vtable_for_testing;
-using grpc_core::internal::alts_tsi_handshaker_get_client_for_testing;
-using grpc_core::internal::alts_tsi_handshaker_get_is_client_for_testing;
-using grpc_core::internal::alts_tsi_handshaker_set_client_vtable_for_testing;
-static bool should_handshaker_client_api_succeed = true;
-
-/* ALTS mock notification. */
-typedef struct notification {
-  gpr_cv cv;
-  gpr_mu mu;
-  bool notified;
-} notification;
-
-/* Type of ALTS handshaker response. */
-typedef enum {
-  INVALID,
-  FAILED,
-  CLIENT_START,
-  SERVER_START,
-  CLIENT_NEXT,
-  SERVER_NEXT,
-} alts_handshaker_response_type;
-
-static alts_handshaker_client* cb_event = nullptr;
-static notification caller_to_tsi_notification;
-static notification tsi_to_caller_notification;
-
-static void notification_init(notification* n) {
-  gpr_mu_init(&n->mu);
-  gpr_cv_init(&n->cv);
-  n->notified = false;
-}
-
-static void notification_destroy(notification* n) {
-  gpr_mu_destroy(&n->mu);
-  gpr_cv_destroy(&n->cv);
-}
-
-static void signal(notification* n) {
-  gpr_mu_lock(&n->mu);
-  n->notified = true;
-  gpr_cv_signal(&n->cv);
-  gpr_mu_unlock(&n->mu);
-}
-
-static void wait(notification* n) {
-  gpr_mu_lock(&n->mu);
-  while (!n->notified) {
-    gpr_cv_wait(&n->cv, &n->mu, gpr_inf_future(GPR_CLOCK_REALTIME));
-  }
-  n->notified = false;
-  gpr_mu_unlock(&n->mu);
-}
-
-static tsi_result peer_attribute_transfer_test() {
-  upb::Arena arena;
-  grpc_gcp_HandshakerResult* result;
-  grpc_gcp_Identity* peer_identity_;
-  grpc_gcp_HandshakerResp* resp = grpc_gcp_HandshakerResp_new(arena.ptr());
-  grpc_gcp_HandshakerStatus* status = grpc_gcp_HandshakerResp_mutable_status(resp, arena.ptr());
-  grpc_gcp_HandshakerStatus_set_code(status, 0);
-  grpc_gcp_Identity* local_identity_;
-
-  grpc_gcp_HandshakerResp_set_out_frames(resp, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME));
-  grpc_gcp_HandshakerResp_set_bytes_consumed(resp, strlen(ALTS_TSI_HANDSHAKER_TEST_CONSUMED_BYTES));
-  result = grpc_gcp_HandshakerResp_mutable_result(resp, arena.ptr());
-  peer_identity_ =grpc_gcp_HandshakerResult_mutable_peer_identity(result, arena.ptr());
-  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,
-      ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MAJOR,
-      ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MINOR));
-  local_identity_ = grpc_gcp_HandshakerResult_mutable_local_identity(result, arena.ptr());
-  grpc_gcp_Identity_set_service_account(local_identity_,upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_LOCAL_IDENTITY));
-  grpc_gcp_HandshakerResult_set_application_protocol(result,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);
-
-   
-
-  grpc_gcp_Identity_AttributesEntry* peer_attributes_ = grpc_gcp_Identity_add_attributes(peer_identity_, arena.ptr());
-  grpc_gcp_Identity_AttributesEntry_set_key(peer_attributes_, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_ATTRIBUTE_KEY));
-  grpc_gcp_Identity_AttributesEntry_set_value(peer_attributes_, upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_ATTRIBUTE_VALUE));
-// Want to create filled example with attribute but how do you generate a full response?
-  // where is HandshakerResp defined? want to fill that with test information
-
-  
-  // tsi_result TEST_RESULT = alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp, bool is_client, tsi_handshaker_result** self);
-
-
-  const grpc_gcp_HandshakerResult * hresult = const_cast<grpc_gcp_HandshakerResult*>(result);
-  const grpc_gcp_Identity* identity =
-      grpc_gcp_HandshakerResult_peer_identity(hresult);
-  if (identity == nullptr) {
-    gpr_log(GPR_ERROR, "Invalid identity");
-    return TSI_FAILED_PRECONDITION;
-  }
-  upb_strview peer_service_account =
-      grpc_gcp_Identity_service_account(identity);
-  if (peer_service_account.size == 0) {
-    gpr_log(GPR_ERROR, "Invalid peer service account");
-    return TSI_FAILED_PRECONDITION;
-  }
-  upb_strview application_protocol =
-      grpc_gcp_HandshakerResult_application_protocol(hresult);
-  if (application_protocol.size == 0) {
-    gpr_log(GPR_ERROR, "Invalid application protocol");
-    return TSI_FAILED_PRECONDITION;
-  }
-  upb_strview record_protocol =
-      grpc_gcp_HandshakerResult_record_protocol(hresult);
-  if (record_protocol.size == 0) {
-    gpr_log(GPR_ERROR, "Invalid record protocol");
-    return TSI_FAILED_PRECONDITION;
-  }
-
-  const grpc_gcp_RpcProtocolVersions* peer_rpc_version =
-      grpc_gcp_HandshakerResult_peer_rpc_versions(hresult);
-  if (peer_rpc_version == nullptr) {
-    gpr_log(GPR_ERROR, "Peer does not set RPC protocol versions.");
-    return TSI_FAILED_PRECONDITION;
-  }
-
-  const grpc_gcp_Identity* local_identity =
-      grpc_gcp_HandshakerResult_local_identity(hresult);
-  if (local_identity == nullptr) {
-    gpr_log(GPR_ERROR, "Invalid local identity");
-    return TSI_FAILED_PRECONDITION;
-  }
-
-
-  upb_strview local_service_account = grpc_gcp_Identity_service_account(local_identity);
-  upb::Arena rpc_versions_arena;
-
-  upb::Arena context_arena;
-  grpc_gcp_AltsContext* context = grpc_gcp_AltsContext_new(context_arena.ptr());
-  grpc_gcp_AltsContext_set_application_protocol(context, application_protocol);
-  grpc_gcp_AltsContext_set_record_protocol(context, record_protocol);
-  // ALTS currently only supports the security level of 2,
-  // which is "grpc_gcp_INTEGRITY_AND_PRIVACY".
-  grpc_gcp_AltsContext_set_security_level(context, 2);
-  grpc_gcp_AltsContext_set_peer_service_account(context, peer_service_account);
-  grpc_gcp_AltsContext_set_local_service_account(context,
-                                                 local_service_account);
-  grpc_gcp_AltsContext_set_peer_rpc_versions(
-      context, const_cast<grpc_gcp_RpcProtocolVersions*>(peer_rpc_version));
-
-
-  // grpc_gcp_HandshakerResult* ncresult = grpc_gcp_HandshakerResp_mutable_result(resp, context_arena.ptr());
-  grpc_gcp_Identity* peer_identity = grpc_gcp_HandshakerResult_mutable_peer_identity(result, context_arena.ptr());
-  if(peer_identity == nullptr ) { //|| *peer_attributes_counter == nullptr) {
-    gpr_log(GPR_ERROR, "Null Peer Identity.");
-    return TSI_FAILED_PRECONDITION;
-  }
-
-  size_t dog = 2048; // removing this line removes errors messages e0612
-  size_t* lenz = &dog;
-  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.");
-    return TSI_FAILED_PRECONDITION; //This is triggering
-  }
-
-}
-int main(int argc, char** argv) {
-  grpc::testing::TestEnvironment env(argc, argv);
-  /* Initialization. */
-  grpc_init();
-  grpc_alts_shared_resource_dedicated_init();
-  /* Tests. */
-  peer_attribute_transfer_test();
-  /* Cleanup. */
-  grpc_alts_shared_resource_dedicated_shutdown();
-  grpc_shutdown();
-  return 0;
-}

+ 26 - 95
test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc

@@ -126,31 +126,24 @@ 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());
   grpc_gcp_HandshakerStatus_set_code(status, 0);
   grpc_gcp_Identity* local_identity;
 
-  upb_strview val9;
   switch (type) {
     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(
@@ -158,33 +151,14 @@ 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
-      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));
-      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");
-      }
-
-
-
+      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());
       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,
@@ -202,31 +176,16 @@ 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);
-
-      // 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");
       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
-      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));
-      // gpr_log(GPR_ERROR, "DEFINED PEER ATTRIBUTES ENTRY AND VALUES");
-
-      
+      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());
       grpc_gcp_Identity_set_service_account(
           peer_identity,
           upb_strview_makez(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY));
@@ -329,12 +288,10 @@ 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, "....... 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));
@@ -362,7 +319,6 @@ 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,
@@ -381,24 +337,16 @@ 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);
-  // }
-
+  size_t iter = UPB_MAP_BEGIN;
+  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,
@@ -422,7 +370,6 @@ 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,
@@ -475,16 +422,16 @@ static void on_server_next_success_cb(tsi_result status, void* user_data,
   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);
-  // }
-
+  size_t iter = UPB_MAP_BEGIN;
+  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);
+  }
   /* Check security level. */
   GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_SECURITY_LEVEL,
                     peer.properties[4].value.data,
@@ -587,19 +534,15 @@ 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;
 }
@@ -639,28 +582,23 @@ 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);
@@ -944,12 +882,10 @@ 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);
@@ -959,11 +895,9 @@ 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);
@@ -1081,13 +1015,11 @@ 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();
@@ -1103,7 +1035,6 @@ 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();