@@ -1799,7 +1799,8 @@ async def test_google_auth_async_transport_handle_request(self):
17991799 "GET" , "https://example.com/api" , headers = {"x-test" : "value" }
18001800 )
18011801
1802- response = await transport .handle_async_request (request )
1802+ with patch .dict ("os.environ" , {}, clear = True ):
1803+ response = await transport .handle_async_request (request )
18031804
18041805 assert response .status_code == 200
18051806 assert response .headers ["content-type" ] == "application/json"
@@ -1810,6 +1811,79 @@ async def test_google_auth_async_transport_handle_request(self):
18101811 data = None ,
18111812 headers = {"x-test" : "value" , "host" : "example.com" },
18121813 timeout = 30.0 ,
1814+ proxy = None ,
1815+ proxy_auth = None ,
1816+ )
1817+
1818+ @pytest .mark .asyncio
1819+ @pytest .mark .skipif (not AIO_SUPPORTED , reason = "google.auth.aio not supported" )
1820+ async def test_google_auth_async_transport_forwards_env_proxy (self ):
1821+ """Test that _GoogleAuthAsyncTransport resolves HTTPS_PROXY and passes proxy and proxy_auth per request."""
1822+ import aiohttp
1823+ from google .adk .tools .mcp_tool .mcp_session_manager import _GoogleAuthAsyncTransport
1824+ import yarl
1825+
1826+ mock_session = AsyncMock ()
1827+ mock_auth_response = AsyncMock ()
1828+ mock_auth_response .status_code = 200
1829+ mock_auth_response .headers = {"content-type" : "application/json" }
1830+ mock_auth_response .content = AsyncMock ()
1831+ mock_session .request .return_value = mock_auth_response
1832+
1833+ transport = _GoogleAuthAsyncTransport (mock_session )
1834+ request = httpx .Request ("GET" , "https://example.com/api" )
1835+
1836+ with patch .dict (
1837+ "os.environ" ,
1838+ {
"HTTPS_PROXY" :
"http://user:[email protected] :8080" },
1839+ clear = True ,
1840+ ):
1841+ await transport .handle_async_request (request )
1842+
1843+ mock_session .request .assert_called_once_with (
1844+ method = "GET" ,
1845+ url = "https://example.com/api" ,
1846+ data = None ,
1847+ headers = {"host" : "example.com" },
1848+ timeout = 30.0 ,
1849+ proxy = yarl .URL ("http://proxy.example.com:8080" ),
1850+ proxy_auth = aiohttp .BasicAuth ("user" , "pass" ),
1851+ )
1852+
1853+ @pytest .mark .asyncio
1854+ @pytest .mark .skipif (not AIO_SUPPORTED , reason = "google.auth.aio not supported" )
1855+ async def test_google_auth_async_transport_respects_no_proxy (self ):
1856+ """Test that _GoogleAuthAsyncTransport passes proxy=None when host matches NO_PROXY."""
1857+ from google .adk .tools .mcp_tool .mcp_session_manager import _GoogleAuthAsyncTransport
1858+
1859+ mock_session = AsyncMock ()
1860+ mock_auth_response = AsyncMock ()
1861+ mock_auth_response .status_code = 200
1862+ mock_auth_response .headers = {"content-type" : "application/json" }
1863+ mock_auth_response .content = AsyncMock ()
1864+ mock_session .request .return_value = mock_auth_response
1865+
1866+ transport = _GoogleAuthAsyncTransport (mock_session )
1867+ request = httpx .Request ("GET" , "https://example.com/api" )
1868+
1869+ with patch .dict (
1870+ "os.environ" ,
1871+ {
1872+ "HTTPS_PROXY" : "http://proxy.example.com:8080" ,
1873+ "NO_PROXY" : "example.com" ,
1874+ },
1875+ clear = True ,
1876+ ):
1877+ await transport .handle_async_request (request )
1878+
1879+ mock_session .request .assert_called_once_with (
1880+ method = "GET" ,
1881+ url = "https://example.com/api" ,
1882+ data = None ,
1883+ headers = {"host" : "example.com" },
1884+ timeout = 30.0 ,
1885+ proxy = None ,
1886+ proxy_auth = None ,
18131887 )
18141888
18151889
0 commit comments