1 // 2 // 3 // Copyright 2015 gRPC authors. 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 // 17 // 18 19 #include "test/cpp/interop/server_helper.h" 20 21 #include <grpcpp/security/server_credentials.h> 22 23 #include <memory> 24 25 #include "absl/flags/declare.h" 26 #include "absl/flags/flag.h" 27 #include "src/core/lib/surface/call_test_only.h" 28 #include "src/core/lib/transport/transport.h" 29 #include "test/cpp/util/test_credentials_provider.h" 30 31 ABSL_DECLARE_FLAG(bool, use_alts); 32 ABSL_DECLARE_FLAG(bool, use_tls); 33 ABSL_DECLARE_FLAG(std::string, custom_credentials_type); 34 35 namespace grpc { 36 namespace testing { 37 CreateInteropServerCredentials()38std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() { 39 if (!absl::GetFlag(FLAGS_custom_credentials_type).empty()) { 40 return GetCredentialsProvider()->GetServerCredentials( 41 absl::GetFlag(FLAGS_custom_credentials_type)); 42 } else if (absl::GetFlag(FLAGS_use_alts)) { 43 return GetCredentialsProvider()->GetServerCredentials(kAltsCredentialsType); 44 } else if (absl::GetFlag(FLAGS_use_tls)) { 45 return GetCredentialsProvider()->GetServerCredentials(kTlsCredentialsType); 46 } else { 47 return GetCredentialsProvider()->GetServerCredentials( 48 kInsecureCredentialsType); 49 } 50 } 51 InteropServerContextInspector(const grpc::ServerContext & context)52InteropServerContextInspector::InteropServerContextInspector( 53 const grpc::ServerContext& context) 54 : context_(context) {} 55 56 grpc_compression_algorithm GetCallCompressionAlgorithm() const57InteropServerContextInspector::GetCallCompressionAlgorithm() const { 58 return grpc_call_test_only_get_compression_algorithm(context_.call_.call); 59 } 60 GetEncodingsAcceptedByClient() const61uint32_t InteropServerContextInspector::GetEncodingsAcceptedByClient() const { 62 return grpc_call_test_only_get_encodings_accepted_by_peer( 63 context_.call_.call); 64 } 65 WasCompressed() const66bool InteropServerContextInspector::WasCompressed() const { 67 return (grpc_call_test_only_get_message_flags(context_.call_.call) & 68 GRPC_WRITE_INTERNAL_COMPRESS) || 69 (grpc_call_test_only_get_message_flags(context_.call_.call) & 70 GRPC_WRITE_INTERNAL_TEST_ONLY_WAS_COMPRESSED); 71 } 72 73 std::shared_ptr<const AuthContext> GetAuthContext() const74InteropServerContextInspector::GetAuthContext() const { 75 return context_.auth_context(); 76 } 77 IsCancelled() const78bool InteropServerContextInspector::IsCancelled() const { 79 return context_.IsCancelled(); 80 } 81 82 } // namespace testing 83 } // namespace grpc 84