• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gflags/gflags.h>
24 #include <grpcpp/security/server_credentials.h>
25 
26 #include "src/core/lib/surface/call_test_only.h"
27 #include "src/core/lib/transport/byte_stream.h"
28 #include "test/cpp/util/test_credentials_provider.h"
29 
30 DECLARE_bool(use_alts);
31 DECLARE_bool(use_tls);
32 DECLARE_string(custom_credentials_type);
33 
34 namespace grpc {
35 namespace testing {
36 
CreateInteropServerCredentials()37 std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() {
38   if (!FLAGS_custom_credentials_type.empty()) {
39     return GetCredentialsProvider()->GetServerCredentials(
40         FLAGS_custom_credentials_type);
41   } else if (FLAGS_use_alts) {
42     return GetCredentialsProvider()->GetServerCredentials(kAltsCredentialsType);
43   } else if (FLAGS_use_tls) {
44     return GetCredentialsProvider()->GetServerCredentials(kTlsCredentialsType);
45   } else {
46     return GetCredentialsProvider()->GetServerCredentials(
47         kInsecureCredentialsType);
48   }
49 }
50 
InteropServerContextInspector(const::grpc::ServerContext & context)51 InteropServerContextInspector::InteropServerContextInspector(
52     const ::grpc::ServerContext& context)
53     : context_(context) {}
54 
55 grpc_compression_algorithm
GetCallCompressionAlgorithm() const56 InteropServerContextInspector::GetCallCompressionAlgorithm() const {
57   return grpc_call_test_only_get_compression_algorithm(context_.call_);
58 }
59 
GetEncodingsAcceptedByClient() const60 uint32_t InteropServerContextInspector::GetEncodingsAcceptedByClient() const {
61   return grpc_call_test_only_get_encodings_accepted_by_peer(context_.call_);
62 }
63 
WasCompressed() const64 bool InteropServerContextInspector::WasCompressed() const {
65   return (grpc_call_test_only_get_message_flags(context_.call_) &
66           GRPC_WRITE_INTERNAL_COMPRESS) ||
67          (grpc_call_test_only_get_message_flags(context_.call_) &
68           GRPC_WRITE_INTERNAL_TEST_ONLY_WAS_COMPRESSED);
69 }
70 
71 std::shared_ptr<const AuthContext>
GetAuthContext() const72 InteropServerContextInspector::GetAuthContext() const {
73   return context_.auth_context();
74 }
75 
IsCancelled() const76 bool InteropServerContextInspector::IsCancelled() const {
77   return context_.IsCancelled();
78 }
79 
80 }  // namespace testing
81 }  // namespace grpc
82