| 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 <memory> |
| 22 |
|
| 23 |
#include "absl/flags/declare.h" |
| 24 |
#include "absl/flags/flag.h" |
| 25 |
|
| 26 |
#include <grpcpp/security/server_credentials.h> |
| 27 |
|
| 28 |
#include "src/core/lib/surface/call_test_only.h" |
| 29 |
#include "src/core/lib/transport/transport.h" |
| 30 |
#include "test/cpp/util/test_credentials_provider.h" |
| 31 |
|
| 32 |
ABSL_DECLARE_FLAG(bool, use_alts); |
| 33 |
ABSL_DECLARE_FLAG(bool, use_tls); |
| 34 |
ABSL_DECLARE_FLAG(std::string, custom_credentials_type); |
| 35 |
|
| 36 |
namespace grpc { |
| 37 |
namespace testing { |
| 38 |
|
| 39 |
std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() { |
| 40 |
if (!absl::GetFlag(FLAGS_custom_credentials_type).empty()) { |
| 41 |
return GetCredentialsProvider()->GetServerCredentials( |
| 42 |
absl::GetFlag(FLAGS_custom_credentials_type)); |
| 43 |
} else if (absl::GetFlag(FLAGS_use_alts)) { |
| 44 |
return GetCredentialsProvider()->GetServerCredentials(kAltsCredentialsType); |
| 45 |
} else if (absl::GetFlag(FLAGS_use_tls)) { |
| 46 |
return GetCredentialsProvider()->GetServerCredentials(kTlsCredentialsType); |
| 47 |
} else { |
| 48 |
return GetCredentialsProvider()->GetServerCredentials( |
| 49 |
kInsecureCredentialsType); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
InteropServerContextInspector::InteropServerContextInspector( |
| 54 |
const grpc::ServerContext& context) |
| 55 |
: context_(context) {} |
| 56 |
|
| 57 |
grpc_compression_algorithm |
| 58 |
InteropServerContextInspector::GetCallCompressionAlgorithm() const { |
| 59 |
return grpc_call_test_only_get_compression_algorithm(context_.call_.call); |
| 60 |
} |
| 61 |
|
| 62 |
uint32_t InteropServerContextInspector::GetEncodingsAcceptedByClient() const { |
| 63 |
return grpc_call_test_only_get_encodings_accepted_by_peer( |
| 64 |
context_.call_.call); |
| 65 |
} |
| 66 |
|
| 67 |
bool InteropServerContextInspector::WasCompressed() const { |
| 68 |
return (grpc_call_test_only_get_message_flags(context_.call_.call) & |
| 69 |
GRPC_WRITE_INTERNAL_COMPRESS) || |
| 70 |
(grpc_call_test_only_get_message_flags(context_.call_.call) & |
| 71 |
GRPC_WRITE_INTERNAL_TEST_ONLY_WAS_COMPRESSED); |
| 72 |
} |
| 73 |
|
| 74 |
std::shared_ptr<const AuthContext> |
| 75 |
InteropServerContextInspector::GetAuthContext() const { |
| 76 |
return context_.auth_context(); |
| 77 |
} |
| 78 |
|
| 79 |
bool InteropServerContextInspector::IsCancelled() const { |
| 80 |
return context_.IsCancelled(); |
| 81 |
} |
| 82 |
|
| 83 |
} // namespace testing |
| 84 |
} // namespace grpc |