Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
arithmetic1728 committed Mar 17, 2020
1 parent 8b4fb7a commit f931cbb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion google/auth/compute_engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from google.auth.compute_engine.credentials import Credentials
from google.auth.compute_engine.credentials import IDTokenCredentials
from google.auth.compute_engine.credentials import IDTokenCredentialsFromMetadata


__all__ = ["Credentials", "IDTokenCredentials"]
__all__ = ["Credentials", "IDTokenCredentials", "IDTokenCredentialsFromMetadata"]
4 changes: 2 additions & 2 deletions google/auth/compute_engine/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def signer_email(self):
return self._service_account_email


class IDTokenCredentialsFromMetadataServer(credentials.Credentials):
class IDTokenCredentialsFromMetadata(credentials.Credentials):
"""Identity token credentials associated with the instance.
These credentials use the Google Compute Engine metadata server to obtain
Expand All @@ -274,7 +274,7 @@ def __init__(self, audience):
used when requesting the ID Token. The ID Token's ``aud`` claim
will be set to this string.
"""
super(IDTokenCredentialsFromMetadataServer, self).__init__()
super(IDTokenCredentialsFromMetadata, self).__init__()
self._audience = audience

def refresh(self, request):
Expand Down
4 changes: 2 additions & 2 deletions system_tests/test_compute_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def test_default(verify_refresh):
verify_refresh(credentials)


def test_id_token_from_metadata_server(http_request):
credentials = compute_engine.IDTokenCredentialsFromMetadataServer("target_audience")
def test_id_token_from_metadata(http_request):
credentials = compute_engine.IDTokenCredentialsFromMetadata("target_audience")
credentials.refresh(http_request)

_, payload, _, _ = jwt._unverified_decode(credentials.token)
Expand Down
8 changes: 4 additions & 4 deletions tests/compute_engine/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def test_sign_bytes(self, sign, get):
assert signature == b"signature"


class TestIDTokenCredentialsFromMetadataServer(object):
class TestIDTokenCredentialsFromMetadata(object):
def create_sample_id_token(self):
data_dir = os.path.join(os.path.dirname(__file__), "../data")
with open(os.path.join(data_dir, "privatekey.pem"), "rb") as fh:
Expand All @@ -494,23 +494,23 @@ def create_sample_id_token(self):
def test_success(self, get):
id_token = self.create_sample_id_token()
get.return_value = id_token
cred = credentials.IDTokenCredentialsFromMetadataServer("audience")
cred = credentials.IDTokenCredentialsFromMetadata("audience")
cred.refresh(request=mock.Mock())
assert cred.token == id_token
assert cred.expiry == 1584393400

@mock.patch("google.auth.compute_engine._metadata.get", autospec=True)
def test_invalid_token(self, get):
get.return_value = "invalid_id_token"
cred = credentials.IDTokenCredentialsFromMetadataServer("audience")
cred = credentials.IDTokenCredentialsFromMetadata("audience")
with pytest.raises(ValueError) as excinfo:
cred.refresh(request=mock.Mock())
assert excinfo.match(r"Wrong number of segments")

@mock.patch("google.auth.compute_engine._metadata.get", autospec=True)
def test_transport_error(self, get):
get.side_effect = exceptions.TransportError("transport error")
cred = credentials.IDTokenCredentialsFromMetadataServer("audience")
cred = credentials.IDTokenCredentialsFromMetadata("audience")
with pytest.raises(exceptions.RefreshError) as excinfo:
cred.refresh(request=mock.Mock())
assert excinfo.match(r"transport error")

0 comments on commit f931cbb

Please sign in to comment.