Serve attachment upload, metadata and download through the API
Add the adapters behind the attachments ports: PostgreSQL for the pending and ready rows, with a foreign key violation on the chat member turned into 404; Pillow that opens only PNG and JPEG, refuses a type that differs from Content-Type, checks the pixel count from the header before any decoding, verifies PNG chunks and decodes JPEG at 1/8 scale in a worker thread under a semaphore; and S3 on aiobotocore with path style, SigV4, short timeouts and checksums only when required. botocore sends Expect: 100-continue for streamed bodies and RustFS behind the Docker port proxy never answers it, so the PUT hung until the read timeout; the handler that adds the header is unregistered. The HTTP layer streams the raw body into the use case, returns the contract Attachment and streams the original back with its content type and length and no redirect. The request pipeline takes a body limit per route, so uploads may carry 10 MiB while JSON stays at 1 MiB. main.py wires the zone and answers its membership port from the messaging chat directory. Tests run the API with an in-memory object store: download by another member, 404 for strangers, the exact 10 MiB limit and one byte over it with Content-Length and chunked, 40 MP and above, spoofed and truncated images, unsupported types, dangerous names, the variant, a failing store and a lost object. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
76c9673ab3
commit
00826a40d3
@@ -12,16 +12,16 @@
|
||||
|
||||
## 3. Зона `attachments`: инфраструктура и HTTP
|
||||
|
||||
- [ ] 3.1 Адаптер PostgreSQL: `add`, `save`, `get` готового; нарушение FK членства → `404`
|
||||
- [ ] 3.2 Адаптер `PillowImageInspector`: открытие только PNG/JPEG, подмена MIME, пиксели по заголовку, PNG `verify`, JPEG `draft` + `load`, `to_thread` под семафором
|
||||
- [ ] 3.3 Адаптер `S3ObjectStorage` на aiobotocore (path-style, SigV4, таймауты, checksum `when_required`), отображение ошибок в `ObjectMissing`/`Unavailable`; зависимости aiobotocore и Pillow в `uv.lock`
|
||||
- [ ] 3.4 Настройки зоны (`S3_*`, `MAX_UPLOAD_BYTES`, `MAX_IMAGE_PIXELS`, таймауты, параллелизм проверки), провайдер dishka, схемы `AttachmentOut`, роутер upload/метаданных/скачивания, реестр ошибок, журнал
|
||||
- [x] 3.1 Адаптер PostgreSQL: `add`, `save`, `get` готового; нарушение FK членства → `404`
|
||||
- [x] 3.2 Адаптер `PillowImageInspector`: открытие только PNG/JPEG, подмена MIME, пиксели по заголовку, PNG `verify`, JPEG `draft` + `load`, `to_thread` под семафором
|
||||
- [x] 3.3 Адаптер `S3ObjectStorage` на aiobotocore (path-style, SigV4, таймауты, checksum `when_required`), отображение ошибок в `ObjectMissing`/`Unavailable`; зависимости aiobotocore и Pillow в `uv.lock`
|
||||
- [x] 3.4 Настройки зоны (`S3_*`, `MAX_UPLOAD_BYTES`, `MAX_IMAGE_PIXELS`, таймауты, параллелизм проверки), провайдер dishka, схемы `AttachmentOut`, роутер upload/метаданных/скачивания, реестр ошибок, журнал
|
||||
- [ ] 3.5 Проверка группы: тест адаптера S3 против одноразового RustFS (put/open/delete, пропавший объект, недоступный endpoint → `Unavailable` за ограниченное время)
|
||||
|
||||
## 4. Связь зон и платформа
|
||||
|
||||
- [ ] 4.1 Платформа: лимит тела по шаблону маршрута в конвейере
|
||||
- [ ] 4.2 `main.py`: зона `attachments`, адаптер `MessagingMembership` для порта `ChatMembership`, лимит upload, поля журнала, реестр ошибок; `create_app` принимает дополнительные провайдеры для тестов
|
||||
- [x] 4.1 Платформа: лимит тела по шаблону маршрута в конвейере
|
||||
- [x] 4.2 `main.py`: зона `attachments`, адаптер `MessagingMembership` для порта `ChatMembership`, лимит upload, поля журнала, реестр ошибок; `create_app` принимает дополнительные провайдеры для тестов
|
||||
- [ ] 4.3 Проверка группы: тест графа импортов — `attachments` не импортирует `identity`/`messaging`, `messaging` не импортирует `attachments`, `shared` не знает зон
|
||||
|
||||
## 5. Зона `messaging`: `attachment_ids`
|
||||
@@ -33,8 +33,8 @@
|
||||
|
||||
## 6. API-тесты вложений
|
||||
|
||||
- [ ] 6.1 Генераторы тестовых PNG (произвольный размер в пикселях и байтах) и JPEG, фейковое `ObjectStorage` в `student-tests`
|
||||
- [ ] 6.2 Тесты: fixture `201` и побайтное скачивание вторым участником, посторонний `404` на метаданных и `/content`, ровно 10 MiB `201`, +1 байт `413` с `Content-Length` и chunked, 40 MP `201` и 40 MP+ `413`, подмена MIME, обрезанные PNG/JPEG, иной и пустой `Content-Type` `415`, опасные и пустые `filename` `400`, `variant=thumbnail` `400`, сбой хранилища `503` без готового вложения, пропавший объект `404`, заголовки на бинарном ответе
|
||||
- [x] 6.1 Генераторы тестовых PNG (произвольный размер в пикселях и байтах) и JPEG, фейковое `ObjectStorage` в `student-tests`
|
||||
- [x] 6.2 Тесты: fixture `201` и побайтное скачивание вторым участником, посторонний `404` на метаданных и `/content`, ровно 10 MiB `201`, +1 байт `413` с `Content-Length` и chunked, 40 MP `201` и 40 MP+ `413`, подмена MIME, обрезанные PNG/JPEG, иной и пустой `Content-Type` `415`, опасные и пустые `filename` `400`, `variant=thumbnail` `400`, сбой хранилища `503` без готового вложения, пропавший объект `404`, заголовки на бинарном ответе
|
||||
|
||||
## 7. Стенд
|
||||
|
||||
|
||||
Reference in New Issue
Block a user