Skip to content

Commit bf3b321

Browse files
authored
Add an option to disable PII masking in get_diagnostic_data (enabled by default) (#1975)
This pull request updates the `get_diagnostic_data` method in the `pyoverkiz` client to allow users to optionally retrieve unmasked diagnostic data, and adds comprehensive tests to ensure the new behavior works as intended. By default, sensitive data is still masked, but users can now explicitly request the raw data if needed. **Enhancements to diagnostic data retrieval:** * The `get_diagnostic_data` method in `pyoverkiz/client.py` now accepts a `mask_sensitive_data` parameter (defaulting to `True`), allowing callers to choose whether to receive masked (redacted) or raw diagnostic data. The method's docstring has been updated to reflect this new behavior. **Testing improvements:** * Added `test_get_diagnostic_data_redacted_by_default` to verify that diagnostic data is masked by default and that the obfuscation function is called. * Added `test_get_diagnostic_data_without_masking` to ensure that when `mask_sensitive_data=False` is passed, the raw diagnostic data is returned and the obfuscation function is not called.
1 parent 137563c commit bf3b321

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

pyoverkiz/client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,19 +333,23 @@ async def get_setup(self, refresh: bool = False) -> Setup:
333333
return setup
334334

335335
@retry_on_auth_error
336-
async def get_diagnostic_data(self) -> JSON:
336+
async def get_diagnostic_data(self, mask_sensitive_data: bool = True) -> JSON:
337337
"""Get all data about the connected user setup.
338338
339339
-> gateways data (serial number, activation state, ...): <gateways/gateway>
340340
-> setup location: <location>
341341
-> house places (rooms and floors): <place>
342342
-> setup devices: <devices>.
343343
344-
This data will be masked to not return any confidential or PII data.
344+
By default, this data is masked to not return confidential or PII data.
345+
Set `mask_sensitive_data` to `False` to return the raw setup payload.
345346
"""
346347
response = await self._get("setup")
347348

348-
return obfuscate_sensitive_data(response)
349+
if mask_sensitive_data:
350+
return obfuscate_sensitive_data(response)
351+
352+
return response
349353

350354
@retry_on_auth_error
351355
async def get_devices(self, refresh: bool = False) -> list[Device]:

tests/test_client.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,44 @@ async def test_get_diagnostic_data(self, client: OverkizClient, fixture_name: st
325325
diagnostics = await client.get_diagnostic_data()
326326
assert diagnostics
327327

328+
@pytest.mark.asyncio
329+
async def test_get_diagnostic_data_redacted_by_default(self, client: OverkizClient):
330+
"""Ensure diagnostics are redacted when no argument is provided."""
331+
with open(
332+
os.path.join(CURRENT_DIR, "fixtures/setup/setup_tahoma_1.json"),
333+
encoding="utf-8",
334+
) as setup_mock:
335+
resp = MockResponse(setup_mock.read())
336+
337+
with (
338+
patch.object(aiohttp.ClientSession, "get", return_value=resp),
339+
patch(
340+
"pyoverkiz.client.obfuscate_sensitive_data",
341+
return_value={"masked": True},
342+
) as obfuscate,
343+
):
344+
diagnostics = await client.get_diagnostic_data()
345+
assert diagnostics == {"masked": True}
346+
obfuscate.assert_called_once()
347+
348+
@pytest.mark.asyncio
349+
async def test_get_diagnostic_data_without_masking(self, client: OverkizClient):
350+
"""Ensure diagnostics can be returned without masking when requested."""
351+
with open(
352+
os.path.join(CURRENT_DIR, "fixtures/setup/setup_tahoma_1.json"),
353+
encoding="utf-8",
354+
) as setup_mock:
355+
raw_setup = setup_mock.read()
356+
resp = MockResponse(raw_setup)
357+
358+
with (
359+
patch.object(aiohttp.ClientSession, "get", return_value=resp),
360+
patch("pyoverkiz.client.obfuscate_sensitive_data") as obfuscate,
361+
):
362+
diagnostics = await client.get_diagnostic_data(mask_sensitive_data=False)
363+
assert diagnostics == json.loads(raw_setup)
364+
obfuscate.assert_not_called()
365+
328366
@pytest.mark.parametrize(
329367
"fixture_name, exception, status_code",
330368
[

0 commit comments

Comments
 (0)