Skip to content

Commit c0435e5

Browse files
committed
Redact vin from logging
1 parent 42bb8f0 commit c0435e5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/volvocarsapi/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ async def _async_request(
376376
body: dict[str, Any] | None = None,
377377
vin: str = "",
378378
) -> dict[str, Any]:
379+
vin = vin or self.vin
379380
access_token = await self.async_get_access_token()
380381

381382
headers = {

tests/test_api.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""API tests."""
22

33
from datetime import UTC, datetime
4+
import logging
45
from unittest.mock import AsyncMock
56

67
from aiohttp import ClientResponseError, ClientSession, RequestInfo
@@ -117,6 +118,22 @@ async def test_access_token_raises_api_exception(
117118
await api.async_get_access_token()
118119

119120

121+
async def test_redacted_url(
122+
mock_client_session: ClientSession, mock_token_manager: VolvoCarsAuth, caplog: pytest.LogCaptureFixture
123+
) -> None:
124+
"""Test if request url is redacted in logs."""
125+
odometer_json = load_json_fixture("odometer")
126+
_mock_response(mock_client_session, odometer_json)
127+
128+
vin = "YV1ABCDEFG1234567"
129+
api = VolvoCarsApi(mock_client_session, mock_token_manager, "secretapikey", vin)
130+
131+
with caplog.at_level(logging.DEBUG):
132+
await api.async_get_odometer()
133+
assert "Request [odometer]:" in caplog.text
134+
assert vin not in caplog.text
135+
136+
120137
def _mock_response(mock_client_session: ClientSession, json: dict) -> None:
121138
mock_response = AsyncMock()
122139
mock_response.__aenter__.return_value.json = AsyncMock(return_value=json)

0 commit comments

Comments
 (0)