Added the use_tls flag toggle connecting securely

pull/236/head
Tim Emiola 10 years ago
parent 671778ef6b
commit 9cae580877
  1. 25
      src/ruby/bin/interop/interop_client.rb
  2. 20
      src/ruby/bin/interop/interop_server.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

@ -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

Loading…
Cancel
Save