Skip to content

Commit 150eb5f

Browse files
test: handle invalid_grant in default creds system tests
This change updates the system tests for default credentials to explicitly allow "invalid_grant" errors when running with `authorized_user.json` credentials. This is because the CI environment uses credentials that frequently expire, and the server response for expired credentials has changed to return "invalid_grant", causing tests to fail instead of being suppressed as intended. This ensures the tests verify the library correctly handles the expiration error rather than failing. References: #1882
1 parent 94d04e0 commit 150eb5f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

system_tests/system_tests_async/test_default.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,12 @@ async def test_application_default_credentials(verify_refresh):
3434
except RefreshError as e:
3535
# allow expired credentials for explicit_authorized_user tests
3636
# TODO: https://github.com/googleapis/google-auth-library-python/issues/1882
37-
if not CREDENTIALS.endswith("authorized_user.json") or "Token has been expired or revoked" not in str(e):
37+
if not CREDENTIALS.endswith("authorized_user.json"):
38+
raise
39+
40+
error_message = str(e)
41+
if (
42+
"Token has been expired or revoked" not in error_message
43+
and "invalid_grant" not in error_message
44+
):
3845
raise

system_tests/system_tests_sync/test_default.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,12 @@ def test_application_default_credentials(verify_refresh):
3232
except RefreshError as e:
3333
# allow expired credentials for explicit_authorized_user tests
3434
# TODO: https://github.com/googleapis/google-auth-library-python/issues/1882
35-
if not CREDENTIALS.endswith("authorized_user.json") or "Token has been expired or revoked" not in str(e):
35+
if not CREDENTIALS.endswith("authorized_user.json"):
36+
raise
37+
38+
error_message = str(e)
39+
if (
40+
"Token has been expired or revoked" not in error_message
41+
and "invalid_grant" not in error_message
42+
):
3643
raise

0 commit comments

Comments
 (0)