Clean up whitespace
This commit is contained in:
@@ -1193,7 +1193,7 @@ class GoogleCredentials(OAuth2Credentials):
|
|||||||
print(response)
|
print(response)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
NON_SERIALIZED_MEMBERS = (
|
NON_SERIALIZED_MEMBERS = (
|
||||||
frozenset(['_private_key']) |
|
frozenset(['_private_key']) |
|
||||||
OAuth2Credentials.NON_SERIALIZED_MEMBERS)
|
OAuth2Credentials.NON_SERIALIZED_MEMBERS)
|
||||||
"""Members that aren't serialized when object is converted to JSON."""
|
"""Members that aren't serialized when object is converted to JSON."""
|
||||||
@@ -1251,13 +1251,12 @@ class GoogleCredentials(OAuth2Credentials):
|
|||||||
# We handle service_account.ServiceAccountCredentials since it is a
|
# We handle service_account.ServiceAccountCredentials since it is a
|
||||||
# possible return type of GoogleCredentials.get_application_default()
|
# possible return type of GoogleCredentials.get_application_default()
|
||||||
if (data['_module'] == 'oauth2client.service_account' and
|
if (data['_module'] == 'oauth2client.service_account' and
|
||||||
data['_class'] == 'ServiceAccountCredentials'):
|
data['_class'] == 'ServiceAccountCredentials'):
|
||||||
return ServiceAccountCredentials.from_json(data)
|
return ServiceAccountCredentials.from_json(data)
|
||||||
elif (data['_module'] == 'oauth2client.service_account' and
|
elif (data['_module'] == 'oauth2client.service_account' and
|
||||||
data['_class'] == '_JWTAccessCredentials'):
|
data['_class'] == '_JWTAccessCredentials'):
|
||||||
return _JWTAccessCredentials.from_json(data)
|
return _JWTAccessCredentials.from_json(data)
|
||||||
|
|
||||||
|
|
||||||
token_expiry = _parse_expiry(data.get('token_expiry'))
|
token_expiry = _parse_expiry(data.get('token_expiry'))
|
||||||
google_credentials = cls(
|
google_credentials = cls(
|
||||||
data['access_token'],
|
data['access_token'],
|
||||||
@@ -1466,8 +1465,7 @@ def save_to_well_known_file(credentials, well_known_file=None):
|
|||||||
|
|
||||||
def _get_environment_variable_file():
|
def _get_environment_variable_file():
|
||||||
application_default_credential_filename = (
|
application_default_credential_filename = (
|
||||||
os.environ.get(GOOGLE_APPLICATION_CREDENTIALS,
|
os.environ.get(GOOGLE_APPLICATION_CREDENTIALS, None))
|
||||||
None))
|
|
||||||
|
|
||||||
if application_default_credential_filename:
|
if application_default_credential_filename:
|
||||||
if os.path.isfile(application_default_credential_filename):
|
if os.path.isfile(application_default_credential_filename):
|
||||||
@@ -1550,8 +1548,8 @@ def _raise_exception_for_reading_json(credential_file,
|
|||||||
extra_help,
|
extra_help,
|
||||||
error):
|
error):
|
||||||
raise ApplicationDefaultCredentialsError(
|
raise ApplicationDefaultCredentialsError(
|
||||||
'An error was encountered while reading json file: ' +
|
'An error was encountered while reading json file: ' +
|
||||||
credential_file + extra_help + ': ' + str(error))
|
credential_file + extra_help + ': ' + str(error))
|
||||||
|
|
||||||
|
|
||||||
def _get_application_default_credential_GAE():
|
def _get_application_default_credential_GAE():
|
||||||
|
|||||||
@@ -290,8 +290,8 @@ class UserOAuth2(object):
|
|||||||
def has_credentials(self):
|
def has_credentials(self):
|
||||||
"""Returns True if there are valid credentials for the current user
|
"""Returns True if there are valid credentials for the current user
|
||||||
and required scopes."""
|
and required scopes."""
|
||||||
return (self.credentials and not self.credentials.invalid
|
return (self.credentials and not self.credentials.invalid and
|
||||||
and self.credentials.has_scopes(self.scopes))
|
self.credentials.has_scopes(self.scopes))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def credentials(self):
|
def credentials(self):
|
||||||
|
|||||||
@@ -446,8 +446,8 @@ class UserOAuth2(object):
|
|||||||
if not self.credentials:
|
if not self.credentials:
|
||||||
return False
|
return False
|
||||||
# Is the access token expired? If so, do we have an refresh token?
|
# Is the access token expired? If so, do we have an refresh token?
|
||||||
elif (self.credentials.access_token_expired
|
elif (self.credentials.access_token_expired and
|
||||||
and not self.credentials.refresh_token):
|
not self.credentials.refresh_token):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class ServiceAccountCredentials(AssertionCredentials):
|
|||||||
MAX_TOKEN_LIFETIME_SECS = 3600
|
MAX_TOKEN_LIFETIME_SECS = 3600
|
||||||
"""Max lifetime of the token (one hour, in seconds)."""
|
"""Max lifetime of the token (one hour, in seconds)."""
|
||||||
|
|
||||||
NON_SERIALIZED_MEMBERS = (
|
NON_SERIALIZED_MEMBERS = (
|
||||||
frozenset(['_signer']) |
|
frozenset(['_signer']) |
|
||||||
AssertionCredentials.NON_SERIALIZED_MEMBERS)
|
AssertionCredentials.NON_SERIALIZED_MEMBERS)
|
||||||
"""Members that aren't serialized when object is converted to JSON."""
|
"""Members that aren't serialized when object is converted to JSON."""
|
||||||
@@ -548,11 +548,11 @@ class ServiceAccountCredentials(AssertionCredentials):
|
|||||||
|
|
||||||
|
|
||||||
def _datetime_to_secs(utc_time):
|
def _datetime_to_secs(utc_time):
|
||||||
# TODO(issue 298): use time_delta.total_seconds()
|
# TODO(issue 298): use time_delta.total_seconds()
|
||||||
# time_delta.total_seconds() not supported in Python 2.6
|
# time_delta.total_seconds() not supported in Python 2.6
|
||||||
epoch = datetime.datetime(1970, 1, 1)
|
epoch = datetime.datetime(1970, 1, 1)
|
||||||
time_delta = utc_time - epoch
|
time_delta = utc_time - epoch
|
||||||
return time_delta.days * 86400 + time_delta.seconds
|
return time_delta.days * 86400 + time_delta.seconds
|
||||||
|
|
||||||
|
|
||||||
class _JWTAccessCredentials(ServiceAccountCredentials):
|
class _JWTAccessCredentials(ServiceAccountCredentials):
|
||||||
|
|||||||
@@ -242,9 +242,8 @@ class Oauth2AuthorizeTest(TestWithSession):
|
|||||||
self.assertTrue(isinstance(response, http.HttpResponseRedirect))
|
self.assertTrue(isinstance(response, http.HttpResponseRedirect))
|
||||||
|
|
||||||
def test_authorize_works_explicit_return_url(self):
|
def test_authorize_works_explicit_return_url(self):
|
||||||
request = self.factory.get('oauth2/oauth2authorize', data={
|
request = self.factory.get('oauth2/oauth2authorize',
|
||||||
'return_url': '/return_endpoint'
|
data={'return_url': '/return_endpoint'})
|
||||||
})
|
|
||||||
request.session = self.session
|
request.session = self.session
|
||||||
response = views.oauth2_authorize(request)
|
response = views.oauth2_authorize(request)
|
||||||
self.assertTrue(isinstance(response, http.HttpResponseRedirect))
|
self.assertTrue(isinstance(response, http.HttpResponseRedirect))
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ SERVICE_ACCOUNT_INFO = {
|
|||||||
'aliases': ['default']
|
'aliases': ['default']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class AppAssertionCredentialsTests(unittest2.TestCase):
|
class AppAssertionCredentialsTests(unittest2.TestCase):
|
||||||
|
|
||||||
def test_constructor(self):
|
def test_constructor(self):
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class TestMetadata(unittest2.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
expiry, datetime.datetime.min + datetime.timedelta(seconds=100))
|
expiry, datetime.datetime.min + datetime.timedelta(seconds=100))
|
||||||
http_request.assert_called_once_with(
|
http_request.assert_called_once_with(
|
||||||
EXPECTED_URL+'/token',
|
EXPECTED_URL + '/token',
|
||||||
**EXPECTED_KWARGS
|
**EXPECTED_KWARGS
|
||||||
)
|
)
|
||||||
now.assert_called_once_with()
|
now.assert_called_once_with()
|
||||||
@@ -92,6 +92,6 @@ class TestMetadata(unittest2.TestCase):
|
|||||||
info = _metadata.get_service_account_info(http_request)
|
info = _metadata.get_service_account_info(http_request)
|
||||||
self.assertEqual(info, DATA)
|
self.assertEqual(info, DATA)
|
||||||
http_request.assert_called_once_with(
|
http_request.assert_called_once_with(
|
||||||
EXPECTED_URL+'/?recursive=True',
|
EXPECTED_URL + '/?recursive=True',
|
||||||
**EXPECTED_KWARGS
|
**EXPECTED_KWARGS
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class TestRsaVerifier(unittest2.TestCase):
|
|||||||
PUBLIC_KEY_FILENAME = os.path.join(os.path.dirname(__file__),
|
PUBLIC_KEY_FILENAME = os.path.join(os.path.dirname(__file__),
|
||||||
'data', 'privatekey.pub')
|
'data', 'privatekey.pub')
|
||||||
PUBLIC_CERT_FILENAME = os.path.join(os.path.dirname(__file__),
|
PUBLIC_CERT_FILENAME = os.path.join(os.path.dirname(__file__),
|
||||||
'data', 'public_cert.pem')
|
'data', 'public_cert.pem')
|
||||||
PRIVATE_KEY_FILENAME = os.path.join(os.path.dirname(__file__),
|
PRIVATE_KEY_FILENAME = os.path.join(os.path.dirname(__file__),
|
||||||
'data', 'privatekey.pem')
|
'data', 'privatekey.pem')
|
||||||
|
|
||||||
|
|||||||
@@ -457,7 +457,7 @@ class GoogleCredentialsTests(unittest2.TestCase):
|
|||||||
client._METADATA_FLAVOR_HEADER)
|
client._METADATA_FLAVOR_HEADER)
|
||||||
else:
|
else:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
http_client_module.HTTPConnection.mock_calls, [])
|
http_client_module.HTTPConnection.mock_calls, [])
|
||||||
self.assertEqual(connection.getresponse.mock_calls, [])
|
self.assertEqual(connection.getresponse.mock_calls, [])
|
||||||
# Remaining calls are not "getresponse"
|
# Remaining calls are not "getresponse"
|
||||||
self.assertEqual(connection.method_calls, [])
|
self.assertEqual(connection.method_calls, [])
|
||||||
|
|||||||
@@ -121,11 +121,11 @@ class Test__validate_clientsecrets(unittest2.TestCase):
|
|||||||
|
|
||||||
def test_success_type_web(self):
|
def test_success_type_web(self):
|
||||||
client_info = {
|
client_info = {
|
||||||
'client_id': 'eye-dee',
|
'client_id': 'eye-dee',
|
||||||
'client_secret': 'seekrit',
|
'client_secret': 'seekrit',
|
||||||
'redirect_uris': None,
|
'redirect_uris': None,
|
||||||
'auth_uri': None,
|
'auth_uri': None,
|
||||||
'token_uri': None,
|
'token_uri': None,
|
||||||
}
|
}
|
||||||
clientsecrets_dict = {
|
clientsecrets_dict = {
|
||||||
clientsecrets.TYPE_WEB: client_info,
|
clientsecrets.TYPE_WEB: client_info,
|
||||||
@@ -135,11 +135,11 @@ class Test__validate_clientsecrets(unittest2.TestCase):
|
|||||||
|
|
||||||
def test_success_type_installed(self):
|
def test_success_type_installed(self):
|
||||||
client_info = {
|
client_info = {
|
||||||
'client_id': 'eye-dee',
|
'client_id': 'eye-dee',
|
||||||
'client_secret': 'seekrit',
|
'client_secret': 'seekrit',
|
||||||
'redirect_uris': None,
|
'redirect_uris': None,
|
||||||
'auth_uri': None,
|
'auth_uri': None,
|
||||||
'token_uri': None,
|
'token_uri': None,
|
||||||
}
|
}
|
||||||
clientsecrets_dict = {
|
clientsecrets_dict = {
|
||||||
clientsecrets.TYPE_INSTALLED: client_info,
|
clientsecrets.TYPE_INSTALLED: client_info,
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class Test_pkcs12_key_as_pem(unittest2.TestCase):
|
|||||||
'some_account@example.com',
|
'some_account@example.com',
|
||||||
filename,
|
filename,
|
||||||
scopes='read+write')
|
scopes='read+write')
|
||||||
credentials._kwargs['sub'] ='joe@example.org'
|
credentials._kwargs['sub'] = 'joe@example.org'
|
||||||
return credentials
|
return credentials
|
||||||
|
|
||||||
def _succeeds_helper(self, password=None):
|
def _succeeds_helper(self, password=None):
|
||||||
@@ -171,6 +171,7 @@ class Test__check_audience(unittest2.TestCase):
|
|||||||
with self.assertRaises(crypt.AppIdentityError):
|
with self.assertRaises(crypt.AppIdentityError):
|
||||||
crypt._check_audience(payload_dict, audience2)
|
crypt._check_audience(payload_dict, audience2)
|
||||||
|
|
||||||
|
|
||||||
class Test__verify_time_range(unittest2.TestCase):
|
class Test__verify_time_range(unittest2.TestCase):
|
||||||
|
|
||||||
def _exception_helper(self, payload_dict):
|
def _exception_helper(self, payload_dict):
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ class ServiceAccountCredentialsTests(unittest2.TestCase):
|
|||||||
return_value=object())
|
return_value=object())
|
||||||
def test_from_json_keyfile_name_factory(self, signer_factory):
|
def test_from_json_keyfile_name_factory(self, signer_factory):
|
||||||
client_id = 'id123'
|
client_id = 'id123'
|
||||||
client_email= 'foo@bar.com'
|
client_email = 'foo@bar.com'
|
||||||
private_key_id = 'pkid456'
|
private_key_id = 'pkid456'
|
||||||
private_key = 's3kr3tz'
|
private_key = 's3kr3tz'
|
||||||
payload = {
|
payload = {
|
||||||
@@ -435,13 +435,13 @@ class JWTAccessCredentialsTests(unittest2.TestCase):
|
|||||||
utcnow.return_value = T1_DATE
|
utcnow.return_value = T1_DATE
|
||||||
time.return_value = T1
|
time.return_value = T1
|
||||||
|
|
||||||
token_info = self.jwt.get_access_token(additional_claims=
|
token_info = self.jwt.get_access_token(
|
||||||
{'aud': 'https://test2.url.com',
|
additional_claims={'aud': 'https://test2.url.com',
|
||||||
'sub': 'dummy2@google.com'
|
'sub': 'dummy2@google.com'
|
||||||
})
|
})
|
||||||
payload = crypt.verify_signed_jwt_with_certs(
|
payload = crypt.verify_signed_jwt_with_certs(
|
||||||
token_info.access_token,
|
token_info.access_token,
|
||||||
{'key' : datafile('public_cert.pem')},
|
{'key': datafile('public_cert.pem')},
|
||||||
audience='https://test2.url.com')
|
audience='https://test2.url.com')
|
||||||
expires_in = token_info.expires_in
|
expires_in = token_info.expires_in
|
||||||
self.assertEqual(payload['iss'], self.service_account_email)
|
self.assertEqual(payload['iss'], self.service_account_email)
|
||||||
|
|||||||
@@ -68,11 +68,10 @@ class TestRunFlow(unittest2.TestCase):
|
|||||||
self.server_flags = argparse.Namespace(
|
self.server_flags = argparse.Namespace(
|
||||||
noauth_local_webserver=False,
|
noauth_local_webserver=False,
|
||||||
logging_level='INFO',
|
logging_level='INFO',
|
||||||
auth_host_port=[8080,],
|
auth_host_port=[8080, ],
|
||||||
auth_host_name='localhost')
|
auth_host_name='localhost')
|
||||||
|
|
||||||
@mock.patch.object(sys, 'argv',
|
@mock.patch.object(sys, 'argv', ['ignored', '--noauth_local_webserver'])
|
||||||
['ignored', '--noauth_local_webserver'])
|
|
||||||
@mock.patch('oauth2client.tools.logging')
|
@mock.patch('oauth2client.tools.logging')
|
||||||
@mock.patch('oauth2client.tools.input')
|
@mock.patch('oauth2client.tools.input')
|
||||||
def test_run_flow_no_webserver(self, input_mock, logging_mock):
|
def test_run_flow_no_webserver(self, input_mock, logging_mock):
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from oauth2client import util
|
|||||||
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PositionalTests(unittest2.TestCase):
|
class PositionalTests(unittest2.TestCase):
|
||||||
|
|
||||||
def test_usage(self):
|
def test_usage(self):
|
||||||
@@ -45,7 +44,6 @@ class PositionalTests(unittest2.TestCase):
|
|||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
fn3(1, 2)
|
fn3(1, 2)
|
||||||
|
|
||||||
|
|
||||||
@mock.patch('oauth2client.util.logger')
|
@mock.patch('oauth2client.util.logger')
|
||||||
def test_enforcement_warning(self, mock_logger):
|
def test_enforcement_warning(self, mock_logger):
|
||||||
util.positional_parameters_enforcement = util.POSITIONAL_WARNING
|
util.positional_parameters_enforcement = util.POSITIONAL_WARNING
|
||||||
@@ -57,7 +55,6 @@ class PositionalTests(unittest2.TestCase):
|
|||||||
self.assertTrue(fn(1, 2))
|
self.assertTrue(fn(1, 2))
|
||||||
self.assertTrue(mock_logger.warning.called)
|
self.assertTrue(mock_logger.warning.called)
|
||||||
|
|
||||||
|
|
||||||
@mock.patch('oauth2client.util.logger')
|
@mock.patch('oauth2client.util.logger')
|
||||||
def test_enforcement_ignore(self, mock_logger):
|
def test_enforcement_ignore(self, mock_logger):
|
||||||
util.positional_parameters_enforcement = util.POSITIONAL_IGNORE
|
util.positional_parameters_enforcement = util.POSITIONAL_IGNORE
|
||||||
@@ -104,7 +101,6 @@ class StringToScopeTests(unittest2.TestCase):
|
|||||||
self.assertEqual(expected, util.string_to_scopes(case))
|
self.assertEqual(expected, util.string_to_scopes(case))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AddQueryParameterTests(unittest2.TestCase):
|
class AddQueryParameterTests(unittest2.TestCase):
|
||||||
|
|
||||||
def test__add_query_parameter(self):
|
def test__add_query_parameter(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user