Catch dhcp setup permission errors sooner (#47639)
This solves an unexpected thread exception on macs when running as a user intead of root
This commit is contained in:
@@ -281,7 +281,7 @@ async def test_setup_and_stop(hass):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with patch("homeassistant.components.dhcp.AsyncSniffer.start") as start_call, patch(
|
||||
"homeassistant.components.dhcp._verify_l2socket_creation_permission",
|
||||
"homeassistant.components.dhcp._verify_l2socket_setup",
|
||||
), patch(
|
||||
"homeassistant.components.dhcp.compile_filter",
|
||||
):
|
||||
@@ -307,7 +307,7 @@ async def test_setup_fails_as_root(hass, caplog):
|
||||
wait_event = threading.Event()
|
||||
|
||||
with patch("os.geteuid", return_value=0), patch(
|
||||
"homeassistant.components.dhcp._verify_l2socket_creation_permission",
|
||||
"homeassistant.components.dhcp._verify_l2socket_setup",
|
||||
side_effect=Scapy_Exception,
|
||||
):
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||
@@ -330,7 +330,7 @@ async def test_setup_fails_non_root(hass, caplog):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with patch("os.geteuid", return_value=10), patch(
|
||||
"homeassistant.components.dhcp._verify_l2socket_creation_permission",
|
||||
"homeassistant.components.dhcp._verify_l2socket_setup",
|
||||
side_effect=Scapy_Exception,
|
||||
):
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||
@@ -351,9 +351,7 @@ async def test_setup_fails_with_broken_libpcap(hass, caplog):
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.dhcp._verify_l2socket_creation_permission",
|
||||
), patch(
|
||||
with patch("homeassistant.components.dhcp._verify_l2socket_setup",), patch(
|
||||
"homeassistant.components.dhcp.compile_filter",
|
||||
side_effect=ImportError,
|
||||
) as compile_filter, patch(
|
||||
|
||||
Reference in New Issue
Block a user