Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Fixed silliness + coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
elibixby committed Mar 29, 2016
1 parent 3f70a0e commit d2f1bbb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
26 changes: 11 additions & 15 deletions oauth2client/contrib/gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class AppAssertionCredentials(AssertionCredentials):

@util.positional(3)
def __init__(self,
scope='',
scope=None,
service_account_email='default',
service_account_info=None,
**kwargs):
Expand All @@ -137,21 +137,25 @@ def __init__(self,
service_account_info:
Deserialized JSON object, returned by self.service_account_info
"""

self._service_account_info = service_account_info or {
'email': service_account_email
}
self._project_id = None
self._partial = service_account_info is None

if scope:
if self.has_scopes(scope):
warnings.warn(_SCOPES_WARNING)
else:
raise ValueError(_SCOPES_WARNING)

self.kwargs = kwargs

# Assertion type is no longer used, but still in the
# parent class signature.
super(AppAssertionCredentials, self).__init__(None)

if scope:
self.scopes = scope

@property
def service_account_info(self):
return self._get_service_account_info()
Expand All @@ -162,14 +166,7 @@ def scopes(self):

@scopes.setter
def scopes(self, value):
""" Scopes on metadata service account are immutable.
We should fail harder in the case that a user sets scopes
which are not available on the instance
"""
if self.has_scopes(value):
warnings.warn(_SCOPES_WARNING)
else:
raise ValueError(_SCOPES_WARNING)
pass

@property
def service_account_email(self):
Expand Down Expand Up @@ -235,11 +232,10 @@ def _refresh(self, http_request):
raise HttpAccessTokenRefreshError(str(e))

def create_scoped(self, scopes):
new = AppAssertionCredentials(
return AppAssertionCredentials(
scope=scopes,
service_account_info=self.service_account_info
)
new.scopes = scopes
return new

def sign_blob(self, blob):
"""Cryptographically sign a blob (of bytes).
Expand Down
6 changes: 3 additions & 3 deletions tests/contrib/test_gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_constructor(self):
@mock.patch('warnings.warn')
@mock.patch(METADATA_SERVER, return_value=A_SERVICE_ACCOUNT)
def test_constructor_with_matching_scopes(self, get_metadata, warn_mock):
scope = 'http://www.googleapis.com/auth/cloud-platform'
scope = 'https://www.googleapis.com/auth/cloud-platform'
AppAssertionCredentials(scope=scope)
warn_mock.assert_called_once_with(_SCOPES_WARNING)

Expand Down Expand Up @@ -159,9 +159,9 @@ def test_serialize_deserialize(self, get_metadata):
@mock.patch('warnings.warn')
@mock.patch(METADATA_SERVER, return_value=A_SERVICE_ACCOUNT)
def test_create_scoped_valid(self, get_metadata, warn_mock):
scope = 'http://www.googleapis.com/auth/cloud-platform'
scope = 'https://www.googleapis.com/auth/cloud-platform'
credentials = AppAssertionCredentials()
credentials.create_scoped(scope=scope)
credentials.create_scoped(scope)
warn_mock.assert_called_once_with(_SCOPES_WARNING)

# ERROR TESTS
Expand Down

0 comments on commit d2f1bbb

Please sign in to comment.