Skip to content

Commit 663431f

Browse files
authored
Allow following of 302 redirects in generic camera (home-assistant#154308)
1 parent 610183c commit 663431f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

homeassistant/components/generic/config_flow.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ async def async_test_still(
191191
try:
192192
async_client = get_async_client(hass, verify_ssl=verify_ssl)
193193
async with asyncio.timeout(GET_IMAGE_TIMEOUT):
194-
response = await async_client.get(url, auth=auth, timeout=GET_IMAGE_TIMEOUT)
194+
response = await async_client.get(
195+
url, auth=auth, timeout=GET_IMAGE_TIMEOUT, follow_redirects=True
196+
)
195197
response.raise_for_status()
196198
image = response.content
197199
except (

tests/components/generic/test_config_flow.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,31 @@ async def test_form_image_http_exceptions(
505505
assert result2["errors"] == expected_message
506506

507507

508+
@respx.mock
509+
async def test_form_image_http_302(
510+
hass: HomeAssistant,
511+
user_flow: ConfigFlowResult,
512+
mock_create_stream: _patch[MagicMock],
513+
fakeimgbytes_png: bytes,
514+
) -> None:
515+
"""Test we handle image http 302 (temporary redirect)."""
516+
respx.get("http://127.0.0.1/testurl/1").side_effect = [
517+
httpx.Response(
518+
status_code=302, headers={"Location": "http://127.0.0.1/testurl2/1"}
519+
)
520+
]
521+
respx.get("http://127.0.0.1/testurl2/1", name="fake_img2").respond(
522+
stream=fakeimgbytes_png
523+
)
524+
result2 = await hass.config_entries.flow.async_configure(
525+
user_flow["flow_id"],
526+
TESTDATA,
527+
)
528+
529+
assert result2["type"] is FlowResultType.FORM
530+
assert result2["step_id"] == "user_confirm"
531+
532+
508533
@respx.mock
509534
async def test_form_stream_invalidimage(
510535
hass: HomeAssistant,

0 commit comments

Comments
 (0)