1 /*
2 *
3 * Copyright 2018 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 #include <sstream>
19
20 #include "absl/flags/flag.h"
21
22 #include <grpc/support/log.h>
23 #include <grpcpp/impl/codegen/service_type.h>
24 #include <grpcpp/server_builder.h>
25
26 #include "test/core/tsi/alts/fake_handshaker/fake_handshaker_server.h"
27 #include "test/core/util/test_config.h"
28 #include "test/cpp/util/test_config.h"
29
30 ABSL_FLAG(int32_t, handshaker_port, 55056,
31 "TCP port on which the fake handshaker server listens to.");
32
RunFakeHandshakerServer(const std::string & server_address)33 static void RunFakeHandshakerServer(const std::string& server_address) {
34 std::unique_ptr<grpc::Service> service =
35 grpc::gcp::CreateFakeHandshakerService(
36 0 /* expected max concurrent rpcs unset */);
37 grpc::ServerBuilder builder;
38 builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
39 builder.RegisterService(service.get());
40 gpr_log(GPR_INFO, "Fake handshaker server listening on %s",
41 server_address.c_str());
42 std::unique_ptr<grpc::Server> server = builder.BuildAndStart();
43 server->Wait();
44 }
45
main(int argc,char ** argv)46 int main(int argc, char** argv) {
47 grpc::testing::TestEnvironment env(argc, argv);
48 grpc::testing::InitTest(&argc, &argv, true);
49
50 GPR_ASSERT(absl::GetFlag(FLAGS_handshaker_port) != 0);
51 std::ostringstream server_address;
52 server_address << "[::1]:" << absl::GetFlag(FLAGS_handshaker_port);
53
54 RunFakeHandshakerServer(server_address.str());
55 return 0;
56 }
57