Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Side by Side Diff: third_party/grpc/test/cpp/util/create_test_channel.cc

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34 #include "test/cpp/util/create_test_channel.h"
35
36 #include <grpc++/create_channel.h>
37 #include <grpc++/security/credentials.h>
38
39 #include "test/core/end2end/data/ssl_test_data.h"
40
41 namespace grpc {
42
43 // When ssl is enabled, if server is empty, override_hostname is used to
44 // create channel. Otherwise, connect to server and override hostname if
45 // override_hostname is provided.
46 // When ssl is not enabled, override_hostname is ignored.
47 // Set use_prod_root to true to use the SSL root for connecting to google.
48 // In this case, path to the roots pem file must be set via environment variable
49 // GRPC_DEFAULT_SSL_ROOTS_FILE_PATH.
50 // Otherwise, root for test SSL cert will be used.
51 // creds will be used to create a channel when enable_ssl is true.
52 // Use examples:
53 // CreateTestChannel(
54 // "1.1.1.1:12345", "override.hostname.com", true, false, creds);
55 // CreateTestChannel("test.google.com:443", "", true, true, creds);
56 // same as above
57 // CreateTestChannel("", "test.google.com:443", true, true, creds);
58 std::shared_ptr<Channel> CreateTestChannel(
59 const grpc::string& server, const grpc::string& override_hostname,
60 bool enable_ssl, bool use_prod_roots,
61 const std::shared_ptr<CallCredentials>& creds) {
62 ChannelArguments channel_args;
63 if (enable_ssl) {
64 const char* roots_certs = use_prod_roots ? "" : test_root_cert;
65 SslCredentialsOptions ssl_opts = {roots_certs, "", ""};
66
67 std::shared_ptr<ChannelCredentials> channel_creds =
68 SslCredentials(ssl_opts);
69
70 if (!server.empty() && !override_hostname.empty()) {
71 channel_args.SetSslTargetNameOverride(override_hostname);
72 }
73 const grpc::string& connect_to =
74 server.empty() ? override_hostname : server;
75 if (creds.get()) {
76 channel_creds = CompositeChannelCredentials(channel_creds, creds);
77 }
78 return CreateCustomChannel(connect_to, channel_creds, channel_args);
79 } else {
80 return CreateChannel(server, InsecureChannelCredentials());
81 }
82 }
83
84 std::shared_ptr<Channel> CreateTestChannel(
85 const grpc::string& server, const grpc::string& override_hostname,
86 bool enable_ssl, bool use_prod_roots) {
87 return CreateTestChannel(server, override_hostname, enable_ssl,
88 use_prod_roots, std::shared_ptr<CallCredentials>());
89 }
90
91 // Shortcut for end2end and interop tests.
92 std::shared_ptr<Channel> CreateTestChannel(const grpc::string& server,
93 bool enable_ssl) {
94 return CreateTestChannel(server, "foo.test.google.fr", enable_ssl, false);
95 }
96
97 } // namespace grpc
OLDNEW
« no previous file with comments | « third_party/grpc/test/cpp/util/create_test_channel.h ('k') | third_party/grpc/test/cpp/util/grpc_cli.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698