fix(matrix): block outbound media when maxMediaBytes is zero
This commit is contained in:
@@ -496,7 +496,15 @@ class MatrixChannel(BaseChannel):
|
|||||||
)
|
)
|
||||||
return MATRIX_ATTACHMENT_UPLOAD_FAILED_TEMPLATE.format(filename)
|
return MATRIX_ATTACHMENT_UPLOAD_FAILED_TEMPLATE.format(filename)
|
||||||
|
|
||||||
if limit_bytes and size_bytes > limit_bytes:
|
if limit_bytes <= 0:
|
||||||
|
logger.warning(
|
||||||
|
"Matrix outbound attachment skipped: media limit {} blocks all uploads for {}",
|
||||||
|
limit_bytes,
|
||||||
|
resolved,
|
||||||
|
)
|
||||||
|
return MATRIX_ATTACHMENT_TOO_LARGE_TEMPLATE.format(filename)
|
||||||
|
|
||||||
|
if size_bytes > limit_bytes:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Matrix outbound attachment skipped: {} bytes exceeds limit {} for {}",
|
"Matrix outbound attachment skipped: {} bytes exceeds limit {} for {}",
|
||||||
size_bytes,
|
size_bytes,
|
||||||
|
|||||||
@@ -857,6 +857,29 @@ async def test_send_uses_server_upload_limit_when_smaller_than_local_limit(tmp_p
|
|||||||
assert client.room_send_calls[0]["content"]["body"] == "[attachment: tiny.txt - too large]"
|
assert client.room_send_calls[0]["content"]["body"] == "[attachment: tiny.txt - too large]"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_send_blocks_all_outbound_media_when_limit_is_zero(tmp_path) -> None:
|
||||||
|
channel = MatrixChannel(_make_config(max_media_bytes=0), MessageBus())
|
||||||
|
client = _FakeAsyncClient("", "", "", None)
|
||||||
|
channel.client = client
|
||||||
|
|
||||||
|
file_path = tmp_path / "empty.txt"
|
||||||
|
file_path.write_bytes(b"")
|
||||||
|
|
||||||
|
await channel.send(
|
||||||
|
OutboundMessage(
|
||||||
|
channel="matrix",
|
||||||
|
chat_id="!room:matrix.org",
|
||||||
|
content="",
|
||||||
|
media=[str(file_path)],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert client.upload_calls == []
|
||||||
|
assert len(client.room_send_calls) == 1
|
||||||
|
assert client.room_send_calls[0]["content"]["body"] == "[attachment: empty.txt - too large]"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_send_omits_ignore_unverified_devices_when_e2ee_disabled() -> None:
|
async def test_send_omits_ignore_unverified_devices_when_e2ee_disabled() -> None:
|
||||||
channel = MatrixChannel(_make_config(e2ee_enabled=False), MessageBus())
|
channel = MatrixChannel(_make_config(e2ee_enabled=False), MessageBus())
|
||||||
|
|||||||
Reference in New Issue
Block a user