166 lines
9.1 KiB
Plaintext
166 lines
9.1 KiB
Plaintext
F.F [100%]
|
|
=================================== FAILURES ===================================
|
|
__________ test_duplicate_ihdr_cannot_disagree_with_pixel_validation ___________
|
|
|
|
async def test_duplicate_ihdr_cannot_disagree_with_pixel_validation() -> None:
|
|
assert len(DUPLICATE_IHDR_PNG) == 94
|
|
with Image.open(BytesIO(DUPLICATE_IHDR_PNG)) as image:
|
|
assert image.size == (2, 2)
|
|
image.verify()
|
|
with Image.open(BytesIO(DUPLICATE_IHDR_PNG)) as image, pytest.raises(OSError):
|
|
image.load()
|
|
> with pytest.raises(UnsupportedImage):
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
E Failed: DID NOT RAISE UnsupportedImage
|
|
|
|
student-tests/unit/test_image_inspection.py:77: Failed
|
|
_____ test_broken_png_returns_415_before_any_storage_write[duplicate-ihdr] _____
|
|
|
|
data = b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\rIHDR\...\x00\x00\x00\xfd\xd4\x9as\x00\x00\x00\x0cIDATx\x9cc```\x00\x00\x00\x04\x00\x01\xf6\x178U\x00\x00\x00\x00IEND\xaeB`\x82'
|
|
|
|
@pytest.mark.parametrize("data", [BROKEN_PNG, DUPLICATE_IHDR_PNG], ids=["bad-zlib", "duplicate-ihdr"])
|
|
async def test_broken_png_returns_415_before_any_storage_write(data: bytes) -> None:
|
|
uow = Mock(spec=AttachmentsUnitOfWork)
|
|
uow.attachments = AsyncMock(spec=AttachmentRepository)
|
|
uow.collect_new_events.return_value = []
|
|
storage = AsyncMock(spec=ObjectStorage)
|
|
membership = AsyncMock(spec=ChatMembership)
|
|
membership.is_member.return_value = True
|
|
logger = NullLogger()
|
|
publisher = RecordingPublisher()
|
|
handler = UploadAttachmentHandler(
|
|
uow,
|
|
membership,
|
|
PillowImageInspector(40_000_000, 1),
|
|
storage,
|
|
clock=Mock(spec=Clock),
|
|
ids=Mock(spec=IdGenerator),
|
|
limit=10_485_760,
|
|
slots=UploadSlots(1),
|
|
logger=logger,
|
|
)
|
|
bus = AttachmentsCommandBus({UploadAttachment: handler}, uow, publisher)
|
|
container = SimpleNamespace(get=AsyncMock(return_value=bus))
|
|
owner, chat = uuid4(), uuid4()
|
|
|
|
async def guard(scope: Scope) -> None:
|
|
scope["state"].update(actor=owner, dishka_container=container)
|
|
|
|
app = FastAPI()
|
|
app.include_router(uploads_router)
|
|
install(app, logger, ERROR_CODES, lambda _: "Bearer", "offline-test")
|
|
transport = ASGITransport(
|
|
app=RequestPipeline(app, logger, 10_485_760, 5, guard, "offline-test")
|
|
)
|
|
async with AsyncClient(transport=transport, base_url="http://testserver") as http:
|
|
> response = await http.post(
|
|
f"/api/v1/chats/{chat}/attachments?filename=broken.png",
|
|
headers={"Content-Type": "image/png", "X-Request-Id": "png-regression"},
|
|
content=data,
|
|
)
|
|
|
|
student-tests/unit/test_png_upload.py:64:
|
|
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|
|
.venv/lib/python3.14/site-packages/httpx/_client.py:1859: in post
|
|
return await self.request(
|
|
.venv/lib/python3.14/site-packages/httpx/_client.py:1540: in request
|
|
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
.venv/lib/python3.14/site-packages/httpx/_client.py:1629: in send
|
|
response = await self._send_handling_auth(
|
|
.venv/lib/python3.14/site-packages/httpx/_client.py:1657: in _send_handling_auth
|
|
response = await self._send_handling_redirects(
|
|
.venv/lib/python3.14/site-packages/httpx/_client.py:1694: in _send_handling_redirects
|
|
response = await self._send_single_request(request)
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
.venv/lib/python3.14/site-packages/httpx/_client.py:1730: in _send_single_request
|
|
response = await transport.handle_async_request(request)
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
.venv/lib/python3.14/site-packages/httpx/_transports/asgi.py:170: in handle_async_request
|
|
await self.app(scope, receive, send)
|
|
src/messenger/shared/entrypoints/pipeline.py:162: in __call__
|
|
await self._app(scope, *pace.around(limited_receive, wrapped_send))
|
|
.venv/lib/python3.14/site-packages/fastapi/applications.py:1163: in __call__
|
|
await super().__call__(scope, receive, send)
|
|
.venv/lib/python3.14/site-packages/starlette/applications.py:96: in __call__
|
|
await self.middleware_stack(scope, receive, send)
|
|
.venv/lib/python3.14/site-packages/starlette/middleware/errors.py:186: in __call__
|
|
raise exc
|
|
.venv/lib/python3.14/site-packages/starlette/middleware/errors.py:164: in __call__
|
|
await self.app(scope, receive, _send)
|
|
.venv/lib/python3.14/site-packages/starlette/middleware/exceptions.py:63: in __call__
|
|
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
|
|
.venv/lib/python3.14/site-packages/starlette/_exception_handler.py:53: in wrapped_app
|
|
raise exc
|
|
.venv/lib/python3.14/site-packages/starlette/_exception_handler.py:42: in wrapped_app
|
|
await app(scope, receive, sender)
|
|
.venv/lib/python3.14/site-packages/fastapi/middleware/asyncexitstack.py:18: in __call__
|
|
await self.app(scope, receive, send)
|
|
.venv/lib/python3.14/site-packages/starlette/routing.py:676: in __call__
|
|
await self.middleware_stack(scope, receive, send)
|
|
.venv/lib/python3.14/site-packages/fastapi/routing.py:2734: in app
|
|
await route.handle(scope, receive, send)
|
|
.venv/lib/python3.14/site-packages/fastapi/routing.py:1780: in handle
|
|
await self.original_router.handle(scope, receive, send)
|
|
.venv/lib/python3.14/site-packages/fastapi/routing.py:2789: in handle
|
|
await included_router._handle_selected(scope, receive, send)
|
|
.venv/lib/python3.14/site-packages/fastapi/routing.py:1800: in _handle_selected
|
|
await original_route.handle(scope, receive, send)
|
|
.venv/lib/python3.14/site-packages/fastapi/routing.py:1279: in handle
|
|
await app(scope, receive, send)
|
|
.venv/lib/python3.14/site-packages/fastapi/routing.py:158: in app
|
|
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
|
|
.venv/lib/python3.14/site-packages/starlette/_exception_handler.py:53: in wrapped_app
|
|
raise exc
|
|
.venv/lib/python3.14/site-packages/starlette/_exception_handler.py:42: in wrapped_app
|
|
await app(scope, receive, sender)
|
|
.venv/lib/python3.14/site-packages/fastapi/routing.py:144: in app
|
|
response = await f(request)
|
|
^^^^^^^^^^^^^^^^
|
|
.venv/lib/python3.14/site-packages/fastapi/routing.py:706: in app
|
|
raw_response = await run_endpoint_function(
|
|
.venv/lib/python3.14/site-packages/fastapi/routing.py:352: in run_endpoint_function
|
|
return await dependant.call(**values)
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
<dishka_func_upload_attachment>:3: in dishka_func_upload_attachment
|
|
return await func_upload_attachment(*args, **kwargs, bus=await container.get(AttachmentsCommandBus, ''))
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
src/messenger/attachments/entrypoints/http.py:42: in upload_attachment
|
|
attachment = await bus.execute(
|
|
src/messenger/shared/application/messagebus.py:32: in execute
|
|
return await handler(command)
|
|
^^^^^^^^^^^^^^^^^^^^^^
|
|
src/messenger/attachments/application/handlers.py:86: in __call__
|
|
attachment = await self._write(command, filename, declared)
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|
|
|
|
self = <messenger.attachments.application.handlers.UploadAttachmentHandler object at 0x1071417e0>
|
|
command = UploadAttachment(owner_id=UUID('c6753b91-81b7-4b38-8940-beb79af87481'), chat_id=UUID('38a84a73-25f2-4ff2-8381-2d63f6f2a205'), filename='broken.png', content_type='image/png', body=<async_generator object body_of at 0x10712d8c0>)
|
|
filename = Filename(value='broken.png'), declared = <ImageKind.PNG: 'image/png'>
|
|
|
|
async def _write(
|
|
self, command: UploadAttachment, filename: Filename, declared: ImageKind
|
|
) -> Attachment:
|
|
data, digest = await read_limited(command.body, self._limit)
|
|
image = await self._images.inspect(data, declared)
|
|
attachment = Attachment.stage(
|
|
attachment_id=self._ids.new_id(),
|
|
chat_id=command.chat_id,
|
|
owner_id=command.owner_id,
|
|
filename=filename,
|
|
image=image,
|
|
size_bytes=len(data),
|
|
sha256=digest,
|
|
now=self._clock.now(),
|
|
)
|
|
> async with self._uow.transaction():
|
|
^^^^^^^^^^^^^^^^^^^^^^^
|
|
E TypeError: 'unittest.mock.Mock' object does not support the asynchronous context manager protocol (missed __aexit__ method)
|
|
|
|
src/messenger/attachments/application/handlers.py:112: TypeError
|
|
=========================== short test summary info ============================
|
|
FAILED student-tests/unit/test_image_inspection.py::test_duplicate_ihdr_cannot_disagree_with_pixel_validation
|
|
FAILED student-tests/unit/test_png_upload.py::test_broken_png_returns_415_before_any_storage_write[duplicate-ihdr]
|
|
2 failed, 1 passed in 0.29s
|