diff options
author | Tim Emiola <temiola@google.com> | 2015-01-26 19:05:16 -0800 |
---|---|---|
committer | Tim Emiola <temiola@google.com> | 2015-01-26 19:05:16 -0800 |
commit | 9cae580877947652f6a3edcfd4ec1a043556f4df (patch) | |
tree | 3229c772ca48931ddf60087eee5ca43d45cca222 /src/ruby | |
parent | 671778ef6b4d9169dee966492f130fa7b194a6af (diff) |
Added the use_tls flag toggle connecting securely
Diffstat (limited to 'src/ruby')
-rwxr-xr-x | src/ruby/bin/interop/interop_client.rb | 25 | ||||
-rwxr-xr-x | src/ruby/bin/interop/interop_server.rb | 20 |
2 files changed, 32 insertions, 13 deletions
diff --git a/src/ruby/bin/interop/interop_client.rb b/src/ruby/bin/interop/interop_client.rb index 0ea7f376be..a23d8067f5 100755 --- a/src/ruby/bin/interop/interop_client.rb +++ b/src/ruby/bin/interop/interop_client.rb @@ -69,14 +69,19 @@ def test_creds end # creates a test stub that accesses host:port securely. -def create_stub(host, port) +def create_stub(host, port, is_secure) address = "#{host}:#{port}" - stub_opts = { - :creds => test_creds, - GRPC::Core::Channel::SSL_TARGET => 'foo.test.google.com' - } - logger.info("... connecting securely to #{address}") - Grpc::Testing::TestService::Stub.new(address, **stub_opts) + if is_secure + stub_opts = { + :creds => test_creds, + GRPC::Core::Channel::SSL_TARGET => 'foo.test.google.com' + } + logger.info("... connecting securely to #{address}") + Grpc::Testing::TestService::Stub.new(address, **stub_opts) + else + logger.info("... connecting insecurely to #{address}") + Grpc::Testing::TestService::Stub.new(address) + end end # produces a string of null chars (\0) of length l. @@ -216,6 +221,7 @@ end # validates the the command line options, returning them as a Hash. def parse_options options = { + 'secure' => false, 'server_host' => nil, 'server_port' => nil, 'test_case' => nil @@ -235,6 +241,9 @@ def parse_options " (#{test_case_list})") do |v| options['test_case'] = v end + opts.on('-u', '--use_tls', 'access using test creds') do |v| + options['secure'] = v + end end.parse! %w(server_host server_port test_case).each do |arg| @@ -247,7 +256,7 @@ end def main opts = parse_options - stub = create_stub(opts['server_host'], opts['server_port']) + stub = create_stub(opts['server_host'], opts['server_port'], opts['secure']) NamedTests.new(stub).method(opts['test_case']).call end diff --git a/src/ruby/bin/interop/interop_server.rb b/src/ruby/bin/interop/interop_server.rb index 83212823f6..441f609713 100755 --- a/src/ruby/bin/interop/interop_server.rb +++ b/src/ruby/bin/interop/interop_server.rb @@ -154,13 +154,18 @@ end # validates the the command line options, returning them as a Hash. def parse_options options = { - 'port' => nil + 'port' => nil, + 'secure' => false } OptionParser.new do |opts| opts.banner = 'Usage: --port port' opts.on('--port PORT', 'server port') do |v| options['port'] = v end + opts.on('-u', '--use_tls', 'access using test creds') do |v| + options['secure'] = v + end + end.parse! if options['port'].nil? @@ -172,10 +177,15 @@ end def main opts = parse_options host = "0.0.0.0:#{opts['port']}" - s = GRPC::RpcServer.new(creds: test_server_creds) - s.add_http2_port(host, true) - logger.info("... running securely on #{host}") - + if opts['secure'] + s = GRPC::RpcServer.new(creds: test_server_creds) + s.add_http2_port(host, true) + logger.info("... running securely on #{host}") + else + s = GRPC::RpcServer.new + s.add_http2_port(host) + logger.info("... running insecurely on #{host}") + end s.handle(TestTarget) s.run end |