Fix diagnostics export for generic camera (#75665)
Fix url redaction and add tests Co-authored-by: Dave T <davet2001@users.noreply.github.com>
This commit is contained in:
parent
82c92b5634
commit
7075032bf7
2 changed files with 37 additions and 3 deletions
|
@ -21,12 +21,12 @@ TO_REDACT = {
|
||||||
# A very similar redact function is in components.sql. Possible to be made common.
|
# A very similar redact function is in components.sql. Possible to be made common.
|
||||||
def redact_url(data: str) -> str:
|
def redact_url(data: str) -> str:
|
||||||
"""Redact credentials from string url."""
|
"""Redact credentials from string url."""
|
||||||
url_in = yarl.URL(data)
|
url = url_in = yarl.URL(data)
|
||||||
if url_in.user:
|
if url_in.user:
|
||||||
url = url_in.with_user("****")
|
url = url.with_user("****")
|
||||||
if url_in.password:
|
if url_in.password:
|
||||||
url = url.with_password("****")
|
url = url.with_password("****")
|
||||||
if url_in.path:
|
if url_in.path != "/":
|
||||||
url = url.with_path("****")
|
url = url.with_path("****")
|
||||||
if url_in.query_string:
|
if url_in.query_string:
|
||||||
url = url.with_query("****=****")
|
url = url.with_query("****=****")
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
"""Test generic (IP camera) diagnostics."""
|
"""Test generic (IP camera) diagnostics."""
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.diagnostics import REDACTED
|
from homeassistant.components.diagnostics import REDACTED
|
||||||
|
from homeassistant.components.generic.diagnostics import redact_url
|
||||||
|
|
||||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
|
||||||
|
@ -22,3 +25,34 @@ async def test_entry_diagnostics(hass, hass_client, setup_entry):
|
||||||
"content_type": "image/jpeg",
|
"content_type": "image/jpeg",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("url_in", "url_out_expected"),
|
||||||
|
[
|
||||||
|
(
|
||||||
|
"http://www.example.com",
|
||||||
|
"http://www.example.com",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"http://fred:letmein1@www.example.com/image.php?key=secret2",
|
||||||
|
"http://****:****@www.example.com/****?****=****",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"http://fred@www.example.com/image.php?key=secret2",
|
||||||
|
"http://****@www.example.com/****?****=****",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"http://fred@www.example.com/image.php",
|
||||||
|
"http://****@www.example.com/****",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"http://:letmein1@www.example.com",
|
||||||
|
"http://:****@www.example.com",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_redact_url(url_in, url_out_expected):
|
||||||
|
"""Test url redaction."""
|
||||||
|
url_out = redact_url(url_in)
|
||||||
|
assert url_out == url_out_expected
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue