|
1 | 1 | """Tests for OAuth proxy token endpoint and handling.""" |
2 | 2 |
|
| 3 | +import logging |
3 | 4 | import time |
4 | 5 | from unittest.mock import AsyncMock, Mock, patch |
5 | 6 |
|
@@ -1883,3 +1884,30 @@ async def test_proactive_refresh_when_validated_but_within_threshold( |
1883 | 1884 | assert result is not None |
1884 | 1885 | assert result.token == "refreshed-upstream-access" |
1885 | 1886 | mock_oauth_client.refresh_token.assert_called_once() |
| 1887 | + |
| 1888 | + |
| 1889 | +class TestRefreshTokenMissLogging: |
| 1890 | + """A refresh-token miss forces a user-visible reconnect, so it must not be silent.""" |
| 1891 | + |
| 1892 | + async def test_unknown_refresh_token_logs_warning(self, oauth_proxy, caplog): |
| 1893 | + client = OAuthClientInformationFull( |
| 1894 | + client_id="test-client", |
| 1895 | + client_secret="test-secret", |
| 1896 | + redirect_uris=[AnyUrl("http://localhost:12345/callback")], |
| 1897 | + ) |
| 1898 | + |
| 1899 | + proxy_logger = logging.getLogger("fastmcp.server.auth.oauth_proxy.proxy") |
| 1900 | + caplog.set_level(logging.WARNING) |
| 1901 | + proxy_logger.addHandler(caplog.handler) |
| 1902 | + try: |
| 1903 | + result = await oauth_proxy.load_refresh_token(client, "nonexistent-token") |
| 1904 | + finally: |
| 1905 | + proxy_logger.removeHandler(caplog.handler) |
| 1906 | + |
| 1907 | + assert result is None |
| 1908 | + assert any( |
| 1909 | + record.levelno == logging.WARNING |
| 1910 | + and "Refresh token not found" in record.getMessage() |
| 1911 | + and "test-client" in record.getMessage() |
| 1912 | + for record in caplog.records |
| 1913 | + ) |
0 commit comments