aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby/bin/interop/interop_client.rb
diff options
context:
space:
mode:
authorGravatar Yang Gao <yangg@google.com>2015-01-27 11:39:14 -0800
committerGravatar Yang Gao <yangg@google.com>2015-01-27 11:39:14 -0800
commit3ed874c861765726b0a86ff610988f56e00db4a2 (patch)
tree59cd01424e74d37bdcc89d6c2a9bd3341aa3de81 /src/ruby/bin/interop/interop_client.rb
parentd785904d0a0bcd1b8c2a7dee7681131e8f9d3417 (diff)
parent9a9f4051203b4e8f38107d08c39b8a586e6a8dc9 (diff)
sync up with master
Diffstat (limited to 'src/ruby/bin/interop/interop_client.rb')
-rwxr-xr-xsrc/ruby/bin/interop/interop_client.rb99
1 files changed, 69 insertions, 30 deletions
diff --git a/src/ruby/bin/interop/interop_client.rb b/src/ruby/bin/interop/interop_client.rb
index 0ea7f376be..86739b7b67 100755
--- a/src/ruby/bin/interop/interop_client.rb
+++ b/src/ruby/bin/interop/interop_client.rb
@@ -54,6 +54,8 @@ require 'test/cpp/interop/test_services'
require 'test/cpp/interop/messages'
require 'test/cpp/interop/empty'
+require 'signet/ssl_config'
+
# loads the certificates used to access the test server securely.
def load_test_certs
this_dir = File.expand_path(File.dirname(__FILE__))
@@ -62,21 +64,49 @@ def load_test_certs
files.map { |f| File.open(File.join(data_dir, f)).read }
end
+# loads the certificates used to access the test server securely.
+def load_prod_cert
+ fail 'could not find a production cert' if ENV['SSL_CERT_FILE'].nil?
+ p "loading prod certs from #{ENV['SSL_CERT_FILE']}"
+ File.open(ENV['SSL_CERT_FILE']).read
+end
+
# creates a Credentials from the test certificates.
def test_creds
certs = load_test_certs
GRPC::Core::Credentials.new(certs[0])
end
+RX_CERT = /-----BEGIN CERTIFICATE-----\n.*?-----END CERTIFICATE-----\n/m
+
+
+# creates a Credentials from the production certificates.
+def prod_creds
+ cert_text = load_prod_cert
+ GRPC::Core::Credentials.new(cert_text)
+end
+
# creates a test stub that accesses host:port securely.
-def create_stub(host, port)
+def create_stub(host, port, is_secure, host_override, use_test_ca)
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
+ creds = nil
+ if use_test_ca
+ creds = test_creds
+ else
+ creds = prod_creds
+ end
+
+ stub_opts = {
+ :creds => creds,
+ GRPC::Core::Channel::SSL_TARGET => host_override
+ }
+ 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.
@@ -133,20 +163,12 @@ class NamedTests
@stub = stub
end
- # TESTING
- # PASSED
- # FAIL
- # ruby server: fails protobuf-ruby can't pass an empty message
def empty_unary
resp = @stub.empty_call(Empty.new)
assert resp.is_a?(Empty), 'empty_unary: invalid response'
p 'OK: empty_unary'
end
- # TESTING
- # PASSED
- # ruby server
- # FAILED
def large_unary
req_size, wanted_response_size = 271_828, 314_159
payload = Payload.new(type: :COMPRESSABLE, body: nulls(req_size))
@@ -163,10 +185,6 @@ class NamedTests
p 'OK: large_unary'
end
- # TESTING:
- # PASSED
- # ruby server
- # FAILED
def client_streaming
msg_sizes = [27_182, 8, 1828, 45_904]
wanted_aggregate_size = 74_922
@@ -180,10 +198,6 @@ class NamedTests
p 'OK: client_streaming'
end
- # TESTING:
- # PASSED
- # ruby server
- # FAILED
def server_streaming
msg_sizes = [31_415, 9, 2653, 58_979]
response_spec = msg_sizes.map { |s| ResponseParameters.new(size: s) }
@@ -200,10 +214,6 @@ class NamedTests
p 'OK: server_streaming'
end
- # TESTING:
- # PASSED
- # ruby server
- # FAILED
def ping_pong
msg_sizes = [[27_182, 31_415], [8, 9], [1828, 2653], [45_904, 58_979]]
ppp = PingPongPlayer.new(msg_sizes)
@@ -211,12 +221,23 @@ class NamedTests
resps.each { |r| ppp.queue.push(r) }
p 'OK: ping_pong'
end
+
+ def all
+ all_methods = NamedTests.instance_methods(false).map(&:to_s)
+ all_methods.each do |m|
+ next if m == 'all' || m.start_with?('assert')
+ p "TESTCASE: #{m}"
+ method(m).call
+ end
+ end
end
# validates the the command line options, returning them as a Hash.
def parse_options
options = {
+ 'secure' => false,
'server_host' => nil,
+ 'server_host_override' => nil,
'server_port' => nil,
'test_case' => nil
}
@@ -225,6 +246,10 @@ def parse_options
opts.on('--server_host SERVER_HOST', 'server hostname') do |v|
options['server_host'] = v
end
+ opts.on('--server_host_override HOST_OVERRIDE',
+ 'override host via a HTTP header') do |v|
+ options['server_host_override'] = v
+ end
opts.on('--server_port SERVER_PORT', 'server port') do |v|
options['server_port'] = v
end
@@ -235,19 +260,33 @@ def parse_options
" (#{test_case_list})") do |v|
options['test_case'] = v
end
+ opts.on('-s', '--use_tls', 'require a secure connection?') do |v|
+ options['secure'] = v
+ end
+ opts.on('-t', '--use_test_ca',
+ 'if secure, use the test certificate?') do |v|
+ options['use_test_ca'] = v
+ end
end.parse!
+ _check_options(options)
+end
+def _check_options(opts)
%w(server_host server_port test_case).each do |arg|
- if options[arg].nil?
+ if opts[arg].nil?
fail(OptionParser::MissingArgument, "please specify --#{arg}")
end
end
- options
+ if opts['server_host_override'].nil?
+ opts['server_host_override'] = opts['server_host']
+ end
+ opts
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'],
+ opts['server_host_override'], opts['use_test_ca'])
NamedTests.new(stub).method(opts['test_case']).call
end