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 <string.h>
20
21 #include <grpc/grpc.h>
22 #include <grpc/grpc_security.h>
23 #include <grpc/support/log.h>
24 #include "src/core/ext/filters/client_channel/resolver_registry.h"
25 #include "src/core/lib/security/credentials/fake/fake_credentials.h"
26 #include "src/core/lib/security/security_connector/security_connector.h"
27 #include "src/core/lib/surface/channel.h"
28 #include "test/core/util/test_config.h"
29
test_unknown_scheme_target(void)30 void test_unknown_scheme_target(void) {
31 grpc_core::ResolverRegistry::Builder::ShutdownRegistry();
32 grpc_core::ResolverRegistry::Builder::InitRegistry();
33 grpc_channel_credentials* creds =
34 grpc_fake_transport_security_credentials_create();
35 grpc_channel* chan =
36 grpc_secure_channel_create(creds, "blah://blah", nullptr, nullptr);
37 grpc_channel_element* elem =
38 grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0);
39 GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client"));
40 grpc_core::ExecCtx exec_ctx;
41 GRPC_CHANNEL_INTERNAL_UNREF(chan, "test");
42 grpc_channel_credentials_unref(creds);
43 }
44
test_security_connector_already_in_arg(void)45 void test_security_connector_already_in_arg(void) {
46 grpc_arg arg;
47 arg.type = GRPC_ARG_POINTER;
48 arg.value.pointer.p = nullptr;
49 arg.key = const_cast<char*>(GRPC_ARG_SECURITY_CONNECTOR);
50 grpc_channel_args args;
51 args.num_args = 1;
52 args.args = &arg;
53 grpc_channel* chan =
54 grpc_secure_channel_create(nullptr, nullptr, &args, nullptr);
55 grpc_channel_element* elem =
56 grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0);
57 GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client"));
58 grpc_core::ExecCtx exec_ctx;
59 GRPC_CHANNEL_INTERNAL_UNREF(chan, "test");
60 }
61
test_null_creds(void)62 void test_null_creds(void) {
63 grpc_channel* chan =
64 grpc_secure_channel_create(nullptr, nullptr, nullptr, nullptr);
65 grpc_channel_element* elem =
66 grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0);
67 GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client"));
68 grpc_core::ExecCtx exec_ctx;
69 GRPC_CHANNEL_INTERNAL_UNREF(chan, "test");
70 }
71
main(int argc,char ** argv)72 int main(int argc, char** argv) {
73 grpc_test_init(argc, argv);
74 grpc_init();
75 test_security_connector_already_in_arg();
76 test_null_creds();
77 test_unknown_scheme_target();
78 grpc_shutdown();
79 return 0;
80 }
81