blob: 80419efce4bf46abe0d620c8cd35d95dcb7769ea [file] [log] [blame]
yang-gd482e592015-12-10 14:04:00 -08001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
yang-gd482e592015-12-10 14:04:00 -08004 * 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 <string.h>
35
36#include <grpc/grpc.h>
37#include <grpc/grpc_security.h>
38#include <grpc/support/log.h>
Craig Tillerd4c98332016-03-31 13:45:47 -070039#include "src/core/ext/client_config/resolver_registry.h"
Craig Tiller9533d042016-03-25 17:11:06 -070040#include "src/core/lib/security/credentials.h"
41#include "src/core/lib/security/security_connector.h"
42#include "src/core/lib/surface/channel.h"
yang-gd482e592015-12-10 14:04:00 -080043#include "test/core/util/test_config.h"
44
45void test_unknown_scheme_target(void) {
46 grpc_channel *chan;
47 grpc_channel_credentials *creds;
48 grpc_resolver_registry_shutdown();
49 grpc_resolver_registry_init("");
50
51 creds = grpc_fake_transport_security_credentials_create();
52 chan = grpc_secure_channel_create(creds, "blah://blah", NULL, NULL);
53 GPR_ASSERT(chan == NULL);
54 grpc_channel_credentials_unref(creds);
55}
56
57void test_security_connector_already_in_arg(void) {
58 grpc_channel *chan;
59 grpc_channel_element *elem;
60 grpc_channel_args args;
61 grpc_arg arg;
62 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
63
64 arg.type = GRPC_ARG_POINTER;
65 arg.value.pointer.p = NULL;
66 arg.key = GRPC_SECURITY_CONNECTOR_ARG;
67 args.num_args = 1;
68 args.args = &arg;
69 chan = grpc_secure_channel_create(NULL, NULL, &args, NULL);
70 elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0);
71 GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client"));
72 GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, chan, "test");
73 grpc_exec_ctx_finish(&exec_ctx);
74}
75
76void test_null_creds(void) {
77 grpc_channel *chan;
78 grpc_channel_element *elem;
79 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
80 chan = grpc_secure_channel_create(NULL, NULL, NULL, NULL);
81 elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0);
82 GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client"));
83 GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, chan, "test");
84 grpc_exec_ctx_finish(&exec_ctx);
85}
86
87int main(int argc, char **argv) {
88 grpc_test_init(argc, argv);
89 grpc_init();
90 test_security_connector_already_in_arg();
91 test_null_creds();
92 test_unknown_scheme_target();
93 grpc_shutdown();
94 return 0;
95}