@@ -135,6 +135,54 @@ async def test_make_request_5xx_raises_admin_api_error(client):
135135 await client ._make_request ("GET" , "/test/endpoint" )
136136
137137
138+ async def test_make_request_4xx_error_does_not_leak_request_url (client ):
139+ internal_url = (
140+ "http://dbt-cloud-app.dbt-cloud.svc.cluster.local:8003"
141+ "/api/v3/accounts/12345/projects/1/environments/?state=1"
142+ )
143+ mock_response = MagicMock ()
144+ mock_response .raise_for_status .side_effect = httpx .HTTPStatusError (
145+ f"Client error '404 Not Found' for url '{ internal_url } '" ,
146+ request = MagicMock (),
147+ response = MagicMock (status_code = 404 ),
148+ )
149+
150+ mock_client = create_mock_httpx_client (mock_response )
151+
152+ with patch ("httpx.AsyncClient" , return_value = mock_client ):
153+ with pytest .raises (InvalidParameterError ) as exc_info :
154+ await client ._make_request (
155+ "GET" , "/api/v3/accounts/12345/projects/1/environments/?state=1"
156+ )
157+
158+ message = str (exc_info .value )
159+ assert "dbt-cloud-app.dbt-cloud.svc.cluster.local" not in message
160+ assert internal_url not in message
161+ assert "404" in message
162+
163+
164+ async def test_make_request_5xx_error_does_not_leak_request_url (client ):
165+ internal_url = (
166+ "http://dbt-cloud-app.dbt-cloud.svc.cluster.local:8003/api/v2/accounts/12345/"
167+ )
168+ mock_response = MagicMock ()
169+ mock_response .raise_for_status .side_effect = httpx .HTTPStatusError (
170+ f"Server error '500 Internal Server Error' for url '{ internal_url } '" ,
171+ request = MagicMock (),
172+ response = MagicMock (status_code = 500 ),
173+ )
174+
175+ mock_client = create_mock_httpx_client (mock_response )
176+
177+ with patch ("httpx.AsyncClient" , return_value = mock_client ):
178+ with pytest .raises (AdminAPIError ) as exc_info :
179+ await client ._make_request ("GET" , "/api/v2/accounts/12345/" )
180+
181+ message = str (exc_info .value )
182+ assert "dbt-cloud-app.dbt-cloud.svc.cluster.local" not in message
183+ assert internal_url not in message
184+
185+
138186async def test_list_jobs (client ):
139187 mock_response = MagicMock ()
140188 mock_response .json .return_value = {
0 commit comments