Skip to content
Snippets Groups Projects
Commit 937d96d0 authored by Ken Payson's avatar Ken Payson
Browse files

Update Python interop tests to use google-auth package

The oauth2client test dependency is still needed as it used by
the beta API unit tests.
parent f8ca8e65
No related branches found
No related tags found
No related merge requests found
...@@ -56,7 +56,8 @@ INSTALL_REQUIRES = ( ...@@ -56,7 +56,8 @@ INSTALL_REQUIRES = (
'grpcio>={version}'.format(version=grpc_version.VERSION), 'grpcio>={version}'.format(version=grpc_version.VERSION),
'grpcio-tools>={version}'.format(version=grpc_version.VERSION), 'grpcio-tools>={version}'.format(version=grpc_version.VERSION),
'grpcio-health-checking>={version}'.format(version=grpc_version.VERSION), 'grpcio-health-checking>={version}'.format(version=grpc_version.VERSION),
'oauth2client>=1.4.7', 'protobuf>=3.3.0', 'six>=1.10',) 'oauth2client>=1.4.7', 'protobuf>=3.3.0', 'six>=1.10', 'google-auth>=1.0.0',
'requests>=2.14.2')
COMMAND_CLASS = { COMMAND_CLASS = {
# Run `preprocess` *before* doing any packaging! # Run `preprocess` *before* doing any packaging!
......
...@@ -29,10 +29,11 @@ ...@@ -29,10 +29,11 @@
"""The Python implementation of the GRPC interoperability test client.""" """The Python implementation of the GRPC interoperability test client."""
import argparse import argparse
from oauth2client import client as oauth2client_client import os
from google import auth as google_auth
from google.auth import jwt as google_auth_jwt
import grpc import grpc
from grpc.beta import implementations
from src.proto.grpc.testing import test_pb2 from src.proto.grpc.testing import test_pb2
from tests.interop import methods from tests.interop import methods
...@@ -84,25 +85,24 @@ def _application_default_credentials(): ...@@ -84,25 +85,24 @@ def _application_default_credentials():
def _stub(args): def _stub(args):
target = '{}:{}'.format(args.server_host, args.server_port) target = '{}:{}'.format(args.server_host, args.server_port)
if args.test_case == 'oauth2_auth_token': if args.test_case == 'oauth2_auth_token':
google_credentials = _application_default_credentials() google_credentials, unused_project_id = google_auth.default(
scoped_credentials = google_credentials.create_scoped( scopes=[args.oauth_scope])
[args.oauth_scope]) google_credentials.refresh(google_auth.transport.requests.Request())
access_token = scoped_credentials.get_access_token().access_token call_credentials = grpc.access_token_call_credentials(
call_credentials = grpc.access_token_call_credentials(access_token) google_credentials.token)
elif args.test_case == 'compute_engine_creds': elif args.test_case == 'compute_engine_creds':
google_credentials = _application_default_credentials() google_credentials, unused_project_id = google_auth.default(
scoped_credentials = google_credentials.create_scoped( scopes=[args.oauth_scope])
[args.oauth_scope]) call_credentials = grpc.metadata_call_credentials(
# TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last google_auth.transport.grpc.AuthMetadataPlugin(
# remaining use of the Beta API. credentials=google_credentials,
call_credentials = implementations.google_call_credentials( request=google_auth.transport.requests.Request()))
scoped_credentials)
elif args.test_case == 'jwt_token_creds': elif args.test_case == 'jwt_token_creds':
google_credentials = _application_default_credentials() google_credentials = google_auth_jwt.OnDemandCredentials.from_service_account_file(
# TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last os.environ[google_auth.environment_vars.CREDENTIALS])
# remaining use of the Beta API. call_credentials = grpc.metadata_call_credentials(
call_credentials = implementations.google_call_credentials( google_auth.transport.grpc.AuthMetadataPlugin(
google_credentials) credentials=google_credentials, request=None))
else: else:
call_credentials = None call_credentials = None
if args.use_tls: if args.use_tls:
......
...@@ -33,8 +33,10 @@ import json ...@@ -33,8 +33,10 @@ import json
import os import os
import threading import threading
from oauth2client import client as oauth2client_client from google import auth as google_auth
from google.auth import environment_vars as google_auth_environment_vars
from google.auth.transport import grpc as google_auth_transport_grpc
from google.auth.transport import requests as google_auth_transport_requests
import grpc import grpc
from grpc.beta import implementations from grpc.beta import implementations
...@@ -401,8 +403,7 @@ def _compute_engine_creds(stub, args): ...@@ -401,8 +403,7 @@ def _compute_engine_creds(stub, args):
def _oauth2_auth_token(stub, args): def _oauth2_auth_token(stub, args):
json_key_filename = os.environ[ json_key_filename = os.environ[google_auth_environment_vars.CREDENTIALS]
oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS]
wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] wanted_email = json.load(open(json_key_filename, 'rb'))['client_email']
response = _large_unary_common_behavior(stub, True, True, None) response = _large_unary_common_behavior(stub, True, True, None)
if wanted_email != response.username: if wanted_email != response.username:
...@@ -414,8 +415,7 @@ def _oauth2_auth_token(stub, args): ...@@ -414,8 +415,7 @@ def _oauth2_auth_token(stub, args):
def _jwt_token_creds(stub, args): def _jwt_token_creds(stub, args):
json_key_filename = os.environ[ json_key_filename = os.environ[google_auth_environment_vars.CREDENTIALS]
oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS]
wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] wanted_email = json.load(open(json_key_filename, 'rb'))['client_email']
response = _large_unary_common_behavior(stub, True, False, None) response = _large_unary_common_behavior(stub, True, False, None)
if wanted_email != response.username: if wanted_email != response.username:
...@@ -424,15 +424,14 @@ def _jwt_token_creds(stub, args): ...@@ -424,15 +424,14 @@ def _jwt_token_creds(stub, args):
def _per_rpc_creds(stub, args): def _per_rpc_creds(stub, args):
json_key_filename = os.environ[ json_key_filename = os.environ[google_auth_environment_vars.CREDENTIALS]
oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS]
wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] wanted_email = json.load(open(json_key_filename, 'rb'))['client_email']
credentials = oauth2client_client.GoogleCredentials.get_application_default() google_credentials, unused_project_id = google_auth.default(
scoped_credentials = credentials.create_scoped([args.oauth_scope]) scopes=[args.oauth_scope])
# TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last call_credentials = grpc.metadata_call_credentials(
# remaining use of the Beta API. google_auth_transport_grpc.AuthMetadataPlugin(
call_credentials = implementations.google_call_credentials( credentials=google_credentials,
scoped_credentials) request=google_auth_transport_requests.Request()))
response = _large_unary_common_behavior(stub, True, False, call_credentials) response = _large_unary_common_behavior(stub, True, False, call_credentials)
if wanted_email != response.username: if wanted_email != response.username:
raise ValueError('expected username %s, got %s' % raise ValueError('expected username %s, got %s' %
......
...@@ -187,7 +187,8 @@ $VENV_PYTHON $ROOT/src/python/grpcio_reflection/setup.py build_package_protos ...@@ -187,7 +187,8 @@ $VENV_PYTHON $ROOT/src/python/grpcio_reflection/setup.py build_package_protos
pip_install_dir $ROOT/src/python/grpcio_reflection pip_install_dir $ROOT/src/python/grpcio_reflection
# Build/install tests # Build/install tests
$VENV_PYTHON -m pip install coverage oauth2client $VENV_PYTHON -m pip install coverage==4.4 oauth2client==4.1.0 \
google-auth==1.0.0 requests==2.14.2
$VENV_PYTHON $ROOT/src/python/grpcio_tests/setup.py preprocess $VENV_PYTHON $ROOT/src/python/grpcio_tests/setup.py preprocess
$VENV_PYTHON $ROOT/src/python/grpcio_tests/setup.py build_package_protos $VENV_PYTHON $ROOT/src/python/grpcio_tests/setup.py build_package_protos
pip_install_dir $ROOT/src/python/grpcio_tests pip_install_dir $ROOT/src/python/grpcio_tests
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment