fix: accept any well-formed uuid so unknown ids return 404
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
const UUID_PATTERN =
|
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 {
|
export function validate(value: string): boolean {
|
||||||
return UUID_PATTERN.test(value);
|
return UUID_PATTERN.test(value);
|
||||||
|
|||||||
@@ -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 () => {
|
it('без токена 401, неверный UUID 400', async () => {
|
||||||
const attachment = await upload();
|
const attachment = await upload();
|
||||||
for (const suffix of ['', '/content']) {
|
for (const suffix of ['', '/content']) {
|
||||||
|
|||||||
Reference in New Issue
Block a user