Fix relative allowed local media paths (#45263)
This commit is contained in:
@@ -152,6 +152,23 @@ async def test_fetch_image_local_files(image_url: str):
|
|||||||
connector.fetch_image(f"file://{temp_dir}/../{os.path.basename(image_url)}")
|
connector.fetch_image(f"file://{temp_dir}/../{os.path.basename(image_url)}")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_fetch_image_local_files_relative_allowed_path(tmp_path, monkeypatch):
|
||||||
|
media_dir = tmp_path / "media"
|
||||||
|
media_dir.mkdir()
|
||||||
|
image_path = media_dir / "image.png"
|
||||||
|
Image.new("RGB", (1, 1), color=(255, 0, 0)).save(image_path)
|
||||||
|
|
||||||
|
monkeypatch.chdir(tmp_path)
|
||||||
|
local_connector = MediaConnector(allowed_local_media_path="media")
|
||||||
|
|
||||||
|
image_sync = local_connector.fetch_image(image_path.as_uri())
|
||||||
|
image_async = await local_connector.fetch_image_async(image_path.as_uri())
|
||||||
|
|
||||||
|
assert image_sync.size == (1, 1)
|
||||||
|
assert not ImageChops.difference(image_sync, image_async).getbbox()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.parametrize("image_url", [TEST_IMAGE_ASSETS[0]], indirect=True)
|
@pytest.mark.parametrize("image_url", [TEST_IMAGE_ASSETS[0]], indirect=True)
|
||||||
async def test_fetch_image_local_files_with_space_in_name(image_url: str):
|
async def test_fetch_image_local_files_with_space_in_name(image_url: str):
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class MediaConnector:
|
|||||||
self.connection = connection
|
self.connection = connection
|
||||||
|
|
||||||
if allowed_local_media_path:
|
if allowed_local_media_path:
|
||||||
allowed_local_media_path_ = Path(allowed_local_media_path)
|
allowed_local_media_path_ = Path(allowed_local_media_path).resolve()
|
||||||
|
|
||||||
if not allowed_local_media_path_.exists():
|
if not allowed_local_media_path_.exists():
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|||||||
Reference in New Issue
Block a user