Skip to content

Commit

Permalink
fix: don't retry if error or error_description is not string (#1241)
Browse files Browse the repository at this point in the history
* fix: don't retry if error or error_description is not string

* chore: fix flaky sample test

* chore: update sys test cred
  • Loading branch information
arithmetic1728 authored Mar 1, 2023
1 parent a5b316f commit e2d263a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions google/oauth2/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ def _can_retry(status_code, response_data):
error_desc = response_data.get("error_description") or ""
error_code = response_data.get("error") or ""

if not isinstance(error_code, six.string_types) or not isinstance(
error_desc, six.string_types
):
return False

# Per Oauth 2.0 RFC https://www.rfc-editor.org/rfc/rfc6749.html#section-4.1.2.1
# This is needed because a redirect will not return a 500 status code.
retryable_error_descriptions = {
Expand Down
2 changes: 1 addition & 1 deletion samples/cloud-client/snippets/verify_google_idtoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def verify_google_idtoken(idtoken: str, audience="iap.googleapis.com",
request = google.auth.transport.requests.Request()
# Set the parameters and verify the token.
# Setting "certs_url" is optional. When verifying a Google ID token, this is set by default.
result = id_token.verify_token(idtoken, request, audience)
result = id_token.verify_token(idtoken, request, audience, clock_skew_in_seconds=10)

# Verify that the token contains subject and email claims.
# Get the User id.
Expand Down
Binary file modified system_tests/secrets.tar.enc
Binary file not shown.
9 changes: 8 additions & 1 deletion tests/oauth2/test__client.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ def test__can_retry_message(response_data):
assert _client._can_retry(http_client.OK, response_data)


@pytest.mark.parametrize("response_data", [{"error": "invalid_scope"}])
@pytest.mark.parametrize(
"response_data",
[
{"error": "invalid_scope"},
{"error": {"foo": "bar"}},
{"error_description": {"foo", "bar"}},
],
)
def test__can_retry_no_retry_message(response_data):
assert not _client._can_retry(http_client.OK, response_data)

Expand Down

0 comments on commit e2d263a

Please sign in to comment.