Only handle shell commands output when return_response requested (#97777)

This commit is contained in:
RoboMagus 2023-08-10 18:11:15 +02:00 committed by GitHub
parent 07a701551b
commit f0e9dccb58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 9 deletions

View file

@ -174,6 +174,40 @@ async def test_stdout_captured(mock_output, hass: HomeAssistant) -> None:
assert response["returncode"] == 0
@patch("homeassistant.components.shell_command._LOGGER.debug")
async def test_non_text_stdout_capture(
mock_output, hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test handling of non-text output."""
assert await async_setup_component(
hass,
shell_command.DOMAIN,
{
shell_command.DOMAIN: {
"output_image": "curl -o - https://raw.githubusercontent.com/home-assistant/assets/master/misc/loading-screen.gif"
}
},
)
# No problem without 'return_response'
response = await hass.services.async_call(
"shell_command", "output_image", blocking=True
)
await hass.async_block_till_done()
assert not response
# Non-text output throws with 'return_response'
with pytest.raises(UnicodeDecodeError):
response = await hass.services.async_call(
"shell_command", "output_image", blocking=True, return_response=True
)
await hass.async_block_till_done()
assert not response
assert "Unable to handle non-utf8 output of command" in caplog.text
@patch("homeassistant.components.shell_command._LOGGER.debug")
async def test_stderr_captured(mock_output, hass: HomeAssistant) -> None:
"""Test subprocess that has stderr."""