|
|
|
@ -48,6 +48,7 @@ require 'minitest' |
|
|
|
|
require 'minitest/assertions' |
|
|
|
|
|
|
|
|
|
require 'grpc' |
|
|
|
|
require 'googleauth' |
|
|
|
|
require 'google/protobuf' |
|
|
|
|
|
|
|
|
|
require 'test/cpp/interop/test_services' |
|
|
|
@ -56,7 +57,7 @@ require 'test/cpp/interop/empty' |
|
|
|
|
|
|
|
|
|
require 'signet/ssl_config' |
|
|
|
|
|
|
|
|
|
include GRPC::Auth |
|
|
|
|
AUTH_ENV = Google::Auth::ServiceAccountCredentials::ENV_VAR |
|
|
|
|
|
|
|
|
|
# loads the certificates used to access the test server securely. |
|
|
|
|
def load_test_certs |
|
|
|
@ -101,22 +102,14 @@ def create_stub(opts) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# Add service account creds if specified |
|
|
|
|
if %w(all service_account_creds).include?(opts.test_case) |
|
|
|
|
wants_creds = %w(all compute_engine_creds service_account_creds) |
|
|
|
|
if wants_creds.include?(opts.test_case) |
|
|
|
|
unless opts.oauth_scope.nil? |
|
|
|
|
fd = StringIO.new(File.read(opts.oauth_key_file)) |
|
|
|
|
logger.info("loading oauth certs from #{opts.oauth_key_file}") |
|
|
|
|
auth_creds = ServiceAccountCredentials.new(opts.oauth_scope, fd) |
|
|
|
|
auth_creds = Google::Auth.get_application_default(opts.oauth_scope) |
|
|
|
|
stub_opts[:update_metadata] = auth_creds.updater_proc |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# Add compute engine creds if specified |
|
|
|
|
if %w(all compute_engine_creds).include?(opts.test_case) |
|
|
|
|
unless opts.oauth_scope.nil? |
|
|
|
|
stub_opts[:update_metadata] = GCECredentials.new.update_proc |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
logger.info("... connecting securely to #{address}") |
|
|
|
|
Grpc::Testing::TestService::Stub.new(address, **stub_opts) |
|
|
|
|
else |
|
|
|
@ -193,11 +186,11 @@ class NamedTests |
|
|
|
|
|
|
|
|
|
def service_account_creds |
|
|
|
|
# ignore this test if the oauth options are not set |
|
|
|
|
if @args.oauth_scope.nil? || @args.oauth_key_file.nil? |
|
|
|
|
if @args.oauth_scope.nil? |
|
|
|
|
p 'NOT RUN: service_account_creds; no service_account settings' |
|
|
|
|
return |
|
|
|
|
end |
|
|
|
|
json_key = File.read(@args.oauth_key_file) |
|
|
|
|
json_key = File.read(ENV[AUTH_ENV]) |
|
|
|
|
wanted_email = MultiJson.load(json_key)['client_email'] |
|
|
|
|
resp = perform_large_unary(fill_username: true, |
|
|
|
|
fill_oauth_scope: true) |
|
|
|
@ -285,7 +278,7 @@ end |
|
|
|
|
|
|
|
|
|
# Args is used to hold the command line info. |
|
|
|
|
Args = Struct.new(:default_service_account, :host, :host_override, |
|
|
|
|
:oauth_scope, :oauth_key_file, :port, :secure, :test_case, |
|
|
|
|
:oauth_scope, :port, :secure, :test_case, |
|
|
|
|
:use_test_ca) |
|
|
|
|
|
|
|
|
|
# validates the the command line options, returning them as a Hash. |
|
|
|
@ -302,10 +295,6 @@ def parse_args |
|
|
|
|
'email address of the default service account') do |v| |
|
|
|
|
args['default_service_account'] = v |
|
|
|
|
end |
|
|
|
|
opts.on('--service_account_key_file PATH', |
|
|
|
|
'Path to the service account json key file') do |v| |
|
|
|
|
args['oauth_key_file'] = v |
|
|
|
|
end |
|
|
|
|
opts.on('--server_host_override HOST_OVERRIDE', |
|
|
|
|
'override host via a HTTP header') do |v| |
|
|
|
|
args['host_override'] = v |
|
|
|
@ -333,10 +322,6 @@ def _check_args(args) |
|
|
|
|
fail(OptionParser::MissingArgument, "please specify --#{arg}") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
if args['oauth_key_file'].nil? ^ args['oauth_scope'].nil? |
|
|
|
|
fail(OptionParser::MissingArgument, |
|
|
|
|
'please specify both of --service_account_key_file and --oauth_scope') |
|
|
|
|
end |
|
|
|
|
args |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|