Danny Reidenbach 5 лет назад
Родитель
Сommit
1852788b99

+ 1 - 0
include/grpcpp/security/alts_context.h

@@ -22,6 +22,7 @@
 #include <grpc/grpc_security_constants.h>
 #include <grpcpp/security/auth_context.h>
 
+#include <map>
 #include <memory>
 #include <map>
 

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

@@ -263,7 +263,8 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
   }
   tsi_handshaker_result* result = nullptr;
   if (is_handshake_finished_properly(resp)) {
-    tsi_result status = alts_tsi_handshaker_result_create(resp, client->is_client, &result);
+    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);

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

@@ -337,19 +337,24 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp,
       context, const_cast<grpc_gcp_RpcProtocolVersions*>(peer_rpc_version));
 
   grpc_gcp_Identity* peer_identity = const_cast<grpc_gcp_Identity*>(identity);
-  if(peer_identity == nullptr) {
+  if (peer_identity == nullptr) {
     gpr_log(GPR_ERROR, "Null peer identity in ALTS context.");
     return TSI_FAILED_PRECONDITION;
   }
 
-  if ( grpc_gcp_Identity_has_attributes(const_cast<grpc_gcp_Identity*>(peer_identity))) {
+  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);
+    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);
     }
   }
  
@@ -691,5 +696,5 @@ alts_handshaker_client* alts_tsi_handshaker_get_client_for_testing(
   return handshaker->client;
 }
 
-} // namespace internal
-} // namespace grpc_core
+}  // namespace internal
+}  // namespace grpc_core

+ 11 - 7
src/cpp/common/alts_context.cc

@@ -81,14 +81,18 @@ AltsContext::AltsContext(const grpc_gcp_AltsContext* ctx) {
         grpc_gcp_AltsContext_security_level(ctx));
   }
   if (grpc_gcp_AltsContext_has_peer_attributes(ctx)) {
-    // std::map<std::string, std::string> peer_attributes_map;
     size_t iter = UPB_MAP_BEGIN;
-    const grpc_gcp_AltsContext_PeerAttributesEntry* peer_attributes_entry= grpc_gcp_AltsContext_peer_attributes_next(ctx, &iter);
-    while ( peer_attributes_entry != nullptr) {
-      upb_strview key = grpc_gcp_AltsContext_PeerAttributesEntry_key(peer_attributes_entry);
-      upb_strview val = grpc_gcp_AltsContext_PeerAttributesEntry_value(peer_attributes_entry);
-      peer_attributes_map[std::string(key.data, key.size)] = std::string(val.data, val.size);
-      peer_attributes_entry = grpc_gcp_AltsContext_peer_attributes_next(ctx, &iter);
+    const grpc_gcp_AltsContext_PeerAttributesEntry* peer_attributes_entry =
+        grpc_gcp_AltsContext_peer_attributes_next(ctx, &iter);
+    while (peer_attributes_entry != nullptr) {
+      upb_strview key =
+          grpc_gcp_AltsContext_PeerAttributesEntry_key(peer_attributes_entry);
+      upb_strview val = 
+          grpc_gcp_AltsContext_PeerAttributesEntry_value(peer_attributes_entry);
+      peer_attributes_map[std::string(key.data, key.size)] = 
+          std::string(val.data, val.size);
+      peer_attributes_entry = 
+          grpc_gcp_AltsContext_peer_attributes_next(ctx, &iter);
     }
 
   }

+ 40 - 18
test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc

@@ -151,9 +151,11 @@ 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());
-      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_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));
@@ -183,9 +185,11 @@ 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());
-      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_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));
@@ -338,14 +342,23 @@ static void on_client_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 = UPB_MAP_BEGIN;
-  grpc_gcp_AltsContext_PeerAttributesEntry* peer_attributes_entry = grpc_gcp_AltsContext_peer_attributes_nextmutable(ctx, &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);
+    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,
@@ -423,14 +436,23 @@ static void on_server_next_success_cb(tsi_result status, void* user_data,
                     local_account.size) == 0);
 
   size_t iter = UPB_MAP_BEGIN;
-  grpc_gcp_AltsContext_PeerAttributesEntry* peer_attributes_entry = grpc_gcp_AltsContext_peer_attributes_nextmutable(ctx, &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);
+    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,

+ 18 - 0
test/cpp/common/alts_util_test.cc

@@ -83,8 +83,11 @@ TEST(AltsUtilTest, AuthContextWithGoodAltsContextWithoutRpcVersions) {
   std::string expected_rp("record protocol");
   std::string expected_peer("peer");
   std::string expected_local("local");
+<<<<<<< HEAD
 
   //doggo
+=======
+>>>>>>> 8900f41dafc213da9aceac8c81daa2208d656e9c
   std::string expected_peer_atrributes_key("peer");
   std::string expected_peer_atrributes_value("attributes");
 
@@ -102,10 +105,20 @@ TEST(AltsUtilTest, AuthContextWithGoodAltsContextWithoutRpcVersions) {
       context,
       upb_strview_make(expected_local.data(), expected_local.length()));
 
+<<<<<<< HEAD
 grpc_gcp_AltsContext_peer_attributes_set(context,
       upb_strview_make(expected_peer_atrributes_key.data(), expected_peer_atrributes_key.length()),
       upb_strview_make(expected_peer_atrributes_value.data(), expected_peer_atrributes_value.length()),
       context_arena.ptr()); 
+=======
+grpc_gcp_AltsContext_peer_attributes_set(
+    context,
+    upb_strview_make(expected_peer_atrributes_key.data(), 
+                     expected_peer_atrributes_key.length()),
+    upb_strview_make(expected_peer_atrributes_value.data(), 
+                     expected_peer_atrributes_value.length()),
+    context_arena.ptr()); 
+>>>>>>> 8900f41dafc213da9aceac8c81daa2208d656e9c
 
   size_t serialized_ctx_length;
   char* serialized_ctx = grpc_gcp_AltsContext_serialize(
@@ -129,7 +142,12 @@ grpc_gcp_AltsContext_peer_attributes_set(context,
   EXPECT_EQ(0, rpc_protocol_versions.min_rpc_version.major_version);
   EXPECT_EQ(0, rpc_protocol_versions.min_rpc_version.minor_version);
 
+<<<<<<< HEAD
   EXPECT_EQ(expected_peer_atrributes_value, alts_context->peer_attributes()[expected_peer_atrributes_key]);
+=======
+  EXPECT_EQ(expected_peer_atrributes_value, 
+            alts_context->peer_attributes()[expected_peer_atrributes_key]);
+>>>>>>> 8900f41dafc213da9aceac8c81daa2208d656e9c
 }
 
 TEST(AltsUtilTest, AuthContextWithGoodAltsContext) {