From 906e3bcfb5a32a25af2f00dd4679052f8a608b3f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 24 Nov 2015 07:31:31 -0800 Subject: Stripping out master channel as a concept --- src/core/surface/secure_channel_create.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/core/surface/secure_channel_create.c') diff --git a/src/core/surface/secure_channel_create.c b/src/core/surface/secure_channel_create.c index 471b5a71e7..344b4d79f7 100644 --- a/src/core/surface/secure_channel_create.c +++ b/src/core/surface/secure_channel_create.c @@ -207,7 +207,6 @@ static grpc_subchannel *subchannel_factory_create_subchannel( gpr_mu_init(&c->mu); gpr_ref_init(&c->refs, 1); args->args = final_args; - args->master = f->master; s = grpc_subchannel_create(&c->base, args); grpc_connector_unref(exec_ctx, &c->base); grpc_channel_args_destroy(final_args); -- cgit v1.2.3 From d482e59d3a05edc0797cbc49639ee7a320e82055 Mon Sep 17 00:00:00 2001 From: yang-g Date: Thu, 10 Dec 2015 14:04:00 -0800 Subject: add a test for secure_channel_create and fix cleanup code --- Makefile | 33 ++++ build.yaml | 10 ++ src/core/surface/secure_channel_create.c | 7 + test/core/surface/secure_channel_create_test.c | 95 +++++++++++ tools/run_tests/sources_and_headers.json | 14 ++ tools/run_tests/tests.json | 18 ++ vsprojects/buildtests_c.sln | 27 +++ .../secure_channel_create_test.vcxproj | 184 +++++++++++++++++++++ .../secure_channel_create_test.vcxproj.filters | 21 +++ 9 files changed, 409 insertions(+) create mode 100644 test/core/surface/secure_channel_create_test.c create mode 100644 vsprojects/vcxproj/test/secure_channel_create_test/secure_channel_create_test.vcxproj create mode 100644 vsprojects/vcxproj/test/secure_channel_create_test/secure_channel_create_test.vcxproj.filters (limited to 'src/core/surface/secure_channel_create.c') diff --git a/Makefile b/Makefile index f30fd1b667..a94ef7172b 100644 --- a/Makefile +++ b/Makefile @@ -847,6 +847,7 @@ multiple_server_queues_test: $(BINDIR)/$(CONFIG)/multiple_server_queues_test murmur_hash_test: $(BINDIR)/$(CONFIG)/murmur_hash_test no_server_test: $(BINDIR)/$(CONFIG)/no_server_test resolve_address_test: $(BINDIR)/$(CONFIG)/resolve_address_test +secure_channel_create_test: $(BINDIR)/$(CONFIG)/secure_channel_create_test secure_endpoint_test: $(BINDIR)/$(CONFIG)/secure_endpoint_test server_chttp2_test: $(BINDIR)/$(CONFIG)/server_chttp2_test set_initial_connect_string_test: $(BINDIR)/$(CONFIG)/set_initial_connect_string_test @@ -1948,6 +1949,7 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/murmur_hash_test \ $(BINDIR)/$(CONFIG)/no_server_test \ $(BINDIR)/$(CONFIG)/resolve_address_test \ + $(BINDIR)/$(CONFIG)/secure_channel_create_test \ $(BINDIR)/$(CONFIG)/secure_endpoint_test \ $(BINDIR)/$(CONFIG)/server_chttp2_test \ $(BINDIR)/$(CONFIG)/set_initial_connect_string_test \ @@ -2992,6 +2994,8 @@ test_c: buildtests_c $(Q) $(BINDIR)/$(CONFIG)/no_server_test || ( echo test no_server_test failed ; exit 1 ) $(E) "[RUN] Testing resolve_address_test" $(Q) $(BINDIR)/$(CONFIG)/resolve_address_test || ( echo test resolve_address_test failed ; exit 1 ) + $(E) "[RUN] Testing secure_channel_create_test" + $(Q) $(BINDIR)/$(CONFIG)/secure_channel_create_test || ( echo test secure_channel_create_test failed ; exit 1 ) $(E) "[RUN] Testing secure_endpoint_test" $(Q) $(BINDIR)/$(CONFIG)/secure_endpoint_test || ( echo test secure_endpoint_test failed ; exit 1 ) $(E) "[RUN] Testing server_chttp2_test" @@ -11244,6 +11248,35 @@ endif endif +SECURE_CHANNEL_CREATE_TEST_SRC = \ + test/core/surface/secure_channel_create_test.c \ + +SECURE_CHANNEL_CREATE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(SECURE_CHANNEL_CREATE_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/secure_channel_create_test: openssl_dep_error + +else + +$(BINDIR)/$(CONFIG)/secure_channel_create_test: $(SECURE_CHANNEL_CREATE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LD) $(LDFLAGS) $(SECURE_CHANNEL_CREATE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/secure_channel_create_test + +endif + +$(OBJDIR)/$(CONFIG)/test/core/surface/secure_channel_create_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +deps_secure_channel_create_test: $(SECURE_CHANNEL_CREATE_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(SECURE_CHANNEL_CREATE_TEST_OBJS:.o=.dep) +endif +endif + + SECURE_ENDPOINT_TEST_SRC = \ test/core/security/secure_endpoint_test.c \ diff --git a/build.yaml b/build.yaml index a67e7d0e71..843b6668fd 100644 --- a/build.yaml +++ b/build.yaml @@ -1500,6 +1500,16 @@ targets: - grpc - gpr_test_util - gpr +- name: secure_channel_create_test + build: test + language: c + src: + - test/core/surface/secure_channel_create_test.c + deps: + - grpc_test_util + - grpc + - gpr_test_util + - gpr - name: secure_endpoint_test build: test language: c diff --git a/src/core/surface/secure_channel_create.c b/src/core/surface/secure_channel_create.c index c9a54d9237..c0a53e9cc0 100644 --- a/src/core/surface/secure_channel_create.c +++ b/src/core/surface/secure_channel_create.c @@ -306,6 +306,13 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds, GRPC_CHANNEL_INTERNAL_REF(channel, "subchannel_factory"); resolver = grpc_resolver_create(target, &f->base); if (!resolver) { + grpc_subchannel_factory_unref(&exec_ctx, &f->base); + GRPC_SECURITY_CONNECTOR_UNREF(&security_connector->base, "channel_create"); + grpc_channel_args_destroy(args_copy); + if (new_args_from_connector != NULL) { + grpc_channel_args_destroy(new_args_from_connector); + } + GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, channel, "subchannel_factory"); grpc_exec_ctx_finish(&exec_ctx); return NULL; } diff --git a/test/core/surface/secure_channel_create_test.c b/test/core/surface/secure_channel_create_test.c new file mode 100644 index 0000000000..f3e5fefaf0 --- /dev/null +++ b/test/core/surface/secure_channel_create_test.c @@ -0,0 +1,95 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include +#include +#include +#include "src/core/client_config/resolver_registry.h" +#include "src/core/security/credentials.h" +#include "src/core/security/security_connector.h" +#include "src/core/surface/channel.h" +#include "test/core/util/test_config.h" + +void test_unknown_scheme_target(void) { + grpc_channel *chan; + grpc_channel_credentials *creds; + grpc_resolver_registry_shutdown(); + grpc_resolver_registry_init(""); + + creds = grpc_fake_transport_security_credentials_create(); + chan = grpc_secure_channel_create(creds, "blah://blah", NULL, NULL); + GPR_ASSERT(chan == NULL); + grpc_channel_credentials_unref(creds); +} + +void test_security_connector_already_in_arg(void) { + grpc_channel *chan; + grpc_channel_element *elem; + grpc_channel_args args; + grpc_arg arg; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + + arg.type = GRPC_ARG_POINTER; + arg.value.pointer.p = NULL; + arg.key = GRPC_SECURITY_CONNECTOR_ARG; + args.num_args = 1; + args.args = &arg; + chan = grpc_secure_channel_create(NULL, NULL, &args, NULL); + elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); + GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); + GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, chan, "test"); + grpc_exec_ctx_finish(&exec_ctx); +} + +void test_null_creds(void) { + grpc_channel *chan; + grpc_channel_element *elem; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + chan = grpc_secure_channel_create(NULL, NULL, NULL, NULL); + elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(chan), 0); + GPR_ASSERT(0 == strcmp(elem->filter->name, "lame-client")); + GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, chan, "test"); + grpc_exec_ctx_finish(&exec_ctx); +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + grpc_init(); + test_security_connector_already_in_arg(); + test_null_creds(); + test_unknown_scheme_target(); + grpc_shutdown(); + return 0; +} diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 704131d5be..d8263621c4 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -934,6 +934,20 @@ "test/core/iomgr/resolve_address_test.c" ] }, + { + "deps": [ + "gpr", + "gpr_test_util", + "grpc", + "grpc_test_util" + ], + "headers": [], + "language": "c", + "name": "secure_channel_create_test", + "src": [ + "test/core/surface/secure_channel_create_test.c" + ] + }, { "deps": [ "gpr", diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json index 289a13d8c4..fd36a99290 100644 --- a/tools/run_tests/tests.json +++ b/tools/run_tests/tests.json @@ -1061,6 +1061,24 @@ "windows" ] }, + { + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "exclude_configs": [], + "flaky": false, + "language": "c", + "name": "secure_channel_create_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ] + }, { "ci_platforms": [ "linux", diff --git a/vsprojects/buildtests_c.sln b/vsprojects/buildtests_c.sln index 8ca27b0215..b0b41edfab 100644 --- a/vsprojects/buildtests_c.sln +++ b/vsprojects/buildtests_c.sln @@ -1758,6 +1758,17 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "resolve_address_test", "vcx {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "secure_channel_create_test", "vcxproj\test\secure_channel_create_test\secure_channel_create_test.vcxproj", "{62B25398-7173-928E-689E-53860B0ACFC4}" + ProjectSection(myProperties) = preProject + lib = "False" + EndProjectSection + ProjectSection(ProjectDependencies) = postProject + {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} = {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} + {29D16885-7228-4C31-81ED-5F9187C7F2A9} = {29D16885-7228-4C31-81ED-5F9187C7F2A9} + {EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037} + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "secure_endpoint_test", "vcxproj\test\secure_endpoint_test\secure_endpoint_test.vcxproj", "{A7747106-A6BC-62D4-2A21-04A4F0CC2683}" ProjectSection(myProperties) = preProject lib = "False" @@ -12728,6 +12739,22 @@ Global {8279AF6C-9584-67F3-1547-B204864FCCA7}.Release-DLL|Win32.Build.0 = Release|Win32 {8279AF6C-9584-67F3-1547-B204864FCCA7}.Release-DLL|x64.ActiveCfg = Release|x64 {8279AF6C-9584-67F3-1547-B204864FCCA7}.Release-DLL|x64.Build.0 = Release|x64 + {62B25398-7173-928E-689E-53860B0ACFC4}.Debug|Win32.ActiveCfg = Debug|Win32 + {62B25398-7173-928E-689E-53860B0ACFC4}.Debug|x64.ActiveCfg = Debug|x64 + {62B25398-7173-928E-689E-53860B0ACFC4}.Release|Win32.ActiveCfg = Release|Win32 + {62B25398-7173-928E-689E-53860B0ACFC4}.Release|x64.ActiveCfg = Release|x64 + {62B25398-7173-928E-689E-53860B0ACFC4}.Debug|Win32.Build.0 = Debug|Win32 + {62B25398-7173-928E-689E-53860B0ACFC4}.Debug|x64.Build.0 = Debug|x64 + {62B25398-7173-928E-689E-53860B0ACFC4}.Release|Win32.Build.0 = Release|Win32 + {62B25398-7173-928E-689E-53860B0ACFC4}.Release|x64.Build.0 = Release|x64 + {62B25398-7173-928E-689E-53860B0ACFC4}.Debug-DLL|Win32.ActiveCfg = Debug|Win32 + {62B25398-7173-928E-689E-53860B0ACFC4}.Debug-DLL|Win32.Build.0 = Debug|Win32 + {62B25398-7173-928E-689E-53860B0ACFC4}.Debug-DLL|x64.ActiveCfg = Debug|x64 + {62B25398-7173-928E-689E-53860B0ACFC4}.Debug-DLL|x64.Build.0 = Debug|x64 + {62B25398-7173-928E-689E-53860B0ACFC4}.Release-DLL|Win32.ActiveCfg = Release|Win32 + {62B25398-7173-928E-689E-53860B0ACFC4}.Release-DLL|Win32.Build.0 = Release|Win32 + {62B25398-7173-928E-689E-53860B0ACFC4}.Release-DLL|x64.ActiveCfg = Release|x64 + {62B25398-7173-928E-689E-53860B0ACFC4}.Release-DLL|x64.Build.0 = Release|x64 {A7747106-A6BC-62D4-2A21-04A4F0CC2683}.Debug|Win32.ActiveCfg = Debug|Win32 {A7747106-A6BC-62D4-2A21-04A4F0CC2683}.Debug|x64.ActiveCfg = Debug|x64 {A7747106-A6BC-62D4-2A21-04A4F0CC2683}.Release|Win32.ActiveCfg = Release|Win32 diff --git a/vsprojects/vcxproj/test/secure_channel_create_test/secure_channel_create_test.vcxproj b/vsprojects/vcxproj/test/secure_channel_create_test/secure_channel_create_test.vcxproj new file mode 100644 index 0000000000..183168ef9d --- /dev/null +++ b/vsprojects/vcxproj/test/secure_channel_create_test/secure_channel_create_test.vcxproj @@ -0,0 +1,184 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {62B25398-7173-928E-689E-53860B0ACFC4} + + + + v100 + + + v110 + + + v120 + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + secure_channel_create_test + static + Debug + Debug + + + secure_channel_create_test + static + Debug + Debug + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + + + Console + true + false + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + + + Console + true + false + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) + true + MultiThreaded + true + None + + + Console + true + false + true + true + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreaded + true + None + + + Console + true + false + true + true + + + + + + + + + {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} + + + {29D16885-7228-4C31-81ED-5F9187C7F2A9} + + + {EAB0A629-17A9-44DB-B5FF-E91A721FE037} + + + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + diff --git a/vsprojects/vcxproj/test/secure_channel_create_test/secure_channel_create_test.vcxproj.filters b/vsprojects/vcxproj/test/secure_channel_create_test/secure_channel_create_test.vcxproj.filters new file mode 100644 index 0000000000..3b016bee30 --- /dev/null +++ b/vsprojects/vcxproj/test/secure_channel_create_test/secure_channel_create_test.vcxproj.filters @@ -0,0 +1,21 @@ + + + + + test\core\surface + + + + + + {d8e20b8b-50bc-458b-48c2-661874410760} + + + {96fd1a22-522a-1535-4d66-9005d106375f} + + + {4acd30f5-eb6e-f414-9f72-bb4af1ae128c} + + + + -- cgit v1.2.3 From d47a44d8ad170d78aa675c3aa7d3b2af19f63e3b Mon Sep 17 00:00:00 2001 From: yang-g Date: Thu, 10 Dec 2015 15:44:25 -0800 Subject: cleanup a bit --- src/core/surface/secure_channel_create.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'src/core/surface/secure_channel_create.c') diff --git a/src/core/surface/secure_channel_create.c b/src/core/surface/secure_channel_create.c index c0a53e9cc0..88cddf4316 100644 --- a/src/core/surface/secure_channel_create.c +++ b/src/core/surface/secure_channel_create.c @@ -305,29 +305,22 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds, f->master = channel; GRPC_CHANNEL_INTERNAL_REF(channel, "subchannel_factory"); resolver = grpc_resolver_create(target, &f->base); - if (!resolver) { - grpc_subchannel_factory_unref(&exec_ctx, &f->base); - GRPC_SECURITY_CONNECTOR_UNREF(&security_connector->base, "channel_create"); - grpc_channel_args_destroy(args_copy); - if (new_args_from_connector != NULL) { - grpc_channel_args_destroy(new_args_from_connector); - } - GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, channel, "subchannel_factory"); - grpc_exec_ctx_finish(&exec_ctx); - return NULL; + if (resolver) { + grpc_client_channel_set_resolver( + &exec_ctx, grpc_channel_get_channel_stack(channel), resolver); + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "create"); } - - grpc_client_channel_set_resolver( - &exec_ctx, grpc_channel_get_channel_stack(channel), resolver); - GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "create"); grpc_subchannel_factory_unref(&exec_ctx, &f->base); GRPC_SECURITY_CONNECTOR_UNREF(&security_connector->base, "channel_create"); - grpc_channel_args_destroy(args_copy); if (new_args_from_connector != NULL) { grpc_channel_args_destroy(new_args_from_connector); } + if (!resolver) { + GRPC_CHANNEL_INTERNAL_UNREF(&exec_ctx, channel, "subchannel_factory"); + channel = NULL; + } grpc_exec_ctx_finish(&exec_ctx); return channel; -- cgit v1.2.3