Skip to content

Commit dac7cc3

Browse files
fix: misc fixes (#1316)
* fix: misc fixes * update
1 parent 2a71f7b commit dac7cc3

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

google/oauth2/reauth.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ def refresh_grant(
334334
response_status_ok, response_data, retryable_error = _client._token_endpoint_request_no_throw(
335335
request, token_uri, body, headers=metrics_header
336336
)
337+
338+
if not response_status_ok and isinstance(response_data, str):
339+
raise exceptions.RefreshError(response_data, retryable=False)
340+
337341
if (
338342
not response_status_ok
339343
and response_data.get("error") == _REAUTH_NEEDED_ERROR

samples/cloud-client/snippets/idtoken_from_metadata_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def idtoken_from_metadata_server(url: str):
2828
2929
Args:
3030
url: The url or target audience to obtain the ID token for.
31-
Examples: http://www.abc.com
31+
Examples: http://www.example.com
3232
"""
3333

3434
request = google.auth.transport.requests.Request()

tests/compute_engine/test_credentials.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ def test_with_token_uri(self, sign, get, utcnow):
525525
token_uri="http://xyz.com",
526526
)
527527
assert self.credentials._token_uri == "http://xyz.com"
528-
creds_with_token_uri = self.credentials.with_token_uri("http://abc.com")
529-
assert creds_with_token_uri._token_uri == "http://abc.com"
528+
creds_with_token_uri = self.credentials.with_token_uri("http://example.com")
529+
assert creds_with_token_uri._token_uri == "http://example.com"
530530

531531
@mock.patch(
532532
"google.auth._helpers.utcnow",
@@ -548,7 +548,7 @@ def test_with_token_uri_exception(self, sign, get, utcnow):
548548
)
549549
assert self.credentials._token_uri is None
550550
with pytest.raises(ValueError):
551-
self.credentials.with_token_uri("http://abc.com")
551+
self.credentials.with_token_uri("http://example.com")
552552

553553
@responses.activate
554554
def test_with_quota_project_integration(self):

tests/oauth2/test_reauth.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,26 @@ def test_refresh_grant_failed(mock_metrics_header_value):
326326
)
327327

328328

329+
def test_refresh_grant_failed_with_string_type_response():
330+
with mock.patch(
331+
"google.oauth2._client._token_endpoint_request_no_throw"
332+
) as mock_token_request:
333+
mock_token_request.return_value = (False, "string type error", False)
334+
with pytest.raises(exceptions.RefreshError) as excinfo:
335+
reauth.refresh_grant(
336+
MOCK_REQUEST,
337+
"token_uri",
338+
"refresh_token",
339+
"client_id",
340+
"client_secret",
341+
scopes=["foo", "bar"],
342+
rapt_token="rapt_token",
343+
enable_reauth_refresh=True,
344+
)
345+
assert excinfo.match(r"string type error")
346+
assert not excinfo.value.retryable
347+
348+
329349
def test_refresh_grant_success():
330350
with mock.patch(
331351
"google.oauth2._client._token_endpoint_request_no_throw"

0 commit comments

Comments
 (0)