Skip to content

Commit f0a907a

Browse files
committed
test: cover _refresh_error_code's malformed-body branches (repo enforces 100% coverage)
1 parent 69bfdbb commit f0a907a

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

tests/client/test_auth.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,14 @@ def _prepare_expired_session(self, oauth_provider: OAuthClientProvider) -> httpx
845845
oauth_provider.context.token_expiry_time = time.time() - 3600
846846
return httpx2.Request("GET", "https://api.example.com/mcp", headers={"mcp-protocol-version": "2025-06-18"})
847847

848+
def test_refresh_error_code_tolerates_malformed_bodies(self):
849+
from mcp.client.auth.oauth2 import _refresh_error_code
850+
851+
assert _refresh_error_code(b'{"error": "invalid_grant"}') == "invalid_grant"
852+
assert _refresh_error_code(b"Bad Request") is None
853+
assert _refresh_error_code(b"[1, 2]") is None
854+
assert _refresh_error_code(b'{"error": 42}') is None
855+
848856
@pytest.mark.anyio
849857
async def test_refresh_retries_without_resource_on_400(self, oauth_provider: OAuthClientProvider):
850858
test_request = self._prepare_expired_session(oauth_provider)

0 commit comments

Comments
 (0)