fix: accept any well-formed uuid so unknown ids return 404

This commit is contained in:
2026-11-05 17:55:22 +03:00
parent 9141873b04
commit 487da7dc9f
2 changed files with 18 additions and 1 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
const UUID_PATTERN =
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
export function validate(value: string): boolean {
return UUID_PATTERN.test(value);
+17
View File
@@ -106,6 +106,23 @@ describe('Скачивание и привязка вложений (e2e)', () =
}
});
it.each([
['nil', '00000000-0000-0000-0000-000000000000'],
['v7', '018f6f3a-7b1c-7def-8abc-0123456789ab'],
])('UUID %s корректного формата — 404, а не 400', async (_name, id) => {
await get(`/api/v1/attachments/${id}`).expect(404);
await get(`/api/v1/attachments/${id}/content`).expect(404);
await get(`/api/v1/chats/${id}`, alice).expect(404);
await send({ text: 'x', attachment_ids: [id] }).expect(404);
await send({ text: 'x' }, { chat: id }).expect(404);
await request(server)
.post(`/api/v1/chats/${id}/attachments?filename=a.png`)
.set('Authorization', bearer(alice))
.set('Content-Type', 'image/png')
.send(SAMPLE_PNG)
.expect(404);
});
it('без токена 401, неверный UUID 400', async () => {
const attachment = await upload();
for (const suffix of ['', '/content']) {