Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

chore: support string type response.data for gcloud #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions 8 google/auth/impersonated_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,17 @@ def _make_iam_token_request(request, principal, headers, body):

response = request(url=iam_endpoint, method="POST", headers=headers, body=body)

response_body = response.data.decode("utf-8")
response_body = (
response.data.decode("utf-8")
if hasattr(response.data, "decode")
else response.data
)

if response.status != http_client.OK:
exceptions.RefreshError(_REFRESH_ERROR, response_body)

try:
token_response = json.loads(response.data.decode("utf-8"))
token_response = json.loads(response_body)
token = token_response["accessToken"]
expiry = datetime.strptime(token_response["expireTime"], "%Y-%m-%dT%H:%M:%SZ")

Expand Down
18 changes: 14 additions & 4 deletions 18 tests/test_impersonated_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,17 @@ def test_default_state(self):
assert not credentials.valid
assert credentials.expired

def make_request(self, data, status=http_client.OK, headers=None, side_effect=None):
def make_request(
self,
data,
status=http_client.OK,
headers=None,
side_effect=None,
use_data_bytes=True,
):
response = mock.create_autospec(transport.Response, instance=False)
response.status = status
response.data = _helpers.to_bytes(data)
response.data = _helpers.to_bytes(data) if use_data_bytes else data
response.headers = headers or {}

request = mock.create_autospec(transport.Request, instance=False)
Expand All @@ -144,7 +151,8 @@ def make_request(self, data, status=http_client.OK, headers=None, side_effect=No

return request

def test_refresh_success(self, mock_donor_credentials):
@pytest.mark.parametrize("use_data_bytes", [True, False])
def test_refresh_success(self, use_data_bytes, mock_donor_credentials):
credentials = self.make_credentials(lifetime=None)
token = "token"

Expand All @@ -154,7 +162,9 @@ def test_refresh_success(self, mock_donor_credentials):
response_body = {"accessToken": token, "expireTime": expire_time}

request = self.make_request(
data=json.dumps(response_body), status=http_client.OK
data=json.dumps(response_body),
status=http_client.OK,
use_data_bytes=use_data_bytes,
)

credentials.refresh(request)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.