{ "info": { "name": "ЛР 3 — Крайкин БВТ2303 — мессенджер", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", "description": "Запустить lab3: make up. Run выполняет сценарий, значения синтетические. Idempotency-Key создаётся один раз для первого запроса и повторно используется для проверки 201/409. Перед экспортом очистить токены. В ЛР4 бинарный файл tests/fixtures/sample.png выбирается вручную для запроса upload, Collection Runner должен иметь доступ к файлу." }, "variable": [ { "key": "base_url", "value": "http://localhost:8083", "type": "string" }, { "key": "demo_password", "value": "Synthetic-Postman-Demo-123", "type": "string" }, { "key": "run_id", "value": "", "type": "string" }, { "key": "alice_id", "value": "", "type": "string" }, { "key": "bob_id", "value": "", "type": "string" }, { "key": "eve_id", "value": "", "type": "string" }, { "key": "alice_token", "value": "", "type": "string" }, { "key": "bob_token", "value": "", "type": "string" }, { "key": "eve_token", "value": "", "type": "string" }, { "key": "alice_expires_at", "value": "", "type": "string" }, { "key": "bob_expires_at", "value": "", "type": "string" }, { "key": "eve_expires_at", "value": "", "type": "string" }, { "key": "chat_id", "value": "", "type": "string" }, { "key": "next_cursor", "value": "", "type": "string" }, { "key": "attachment_id", "value": "" }, { "key": "repeat_id", "value": "" } ], "item": [ { "name": "01 — Процесс жив", "request": { "method": "GET", "header": [], "url": "{{base_url}}/health/live" }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "02 — БД готова", "request": { "method": "GET", "header": [], "url": "{{base_url}}/health/ready" }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "03 — Создать Глеб", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "url": "{{base_url}}/api/v1/users", "body": { "mode": "raw", "raw": "{\n \"username\": \"alice_{{run_id}}\",\n \"display_name\": \"Глеб\",\n \"password\": \"{{demo_password}}\"\n}", "options": { "raw": { "language": "json" } } } }, "event": [ { "listen": "prerequest", "script": { "type": "text/javascript", "exec": [ "pm.collectionVariables.set(\"run_id\", pm.variables.replaceIn(\"{{$guid}}\").replace(/-/g, \"\").slice(0,16));", "[\"alice_token\",\"bob_token\",\"eve_token\",\"chat_id\",\"next_cursor\"].forEach(k => pm.collectionVariables.set(k, \"\"));" ] } }, { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 201\", () => pm.response.to.have.status(201));", "if (pm.response.code === 201) pm.collectionVariables.set(\"alice_id\", pm.response.json().id);", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "04 — Создать Боб", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "url": "{{base_url}}/api/v1/users", "body": { "mode": "raw", "raw": "{\n \"username\": \"bob_{{run_id}}\",\n \"display_name\": \"Боб\",\n \"password\": \"{{demo_password}}\"\n}", "options": { "raw": { "language": "json" } } } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 201\", () => pm.response.to.have.status(201));", "if (pm.response.code === 201) pm.collectionVariables.set(\"bob_id\", pm.response.json().id);", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "05 — Создать Посторонний", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "url": "{{base_url}}/api/v1/users", "body": { "mode": "raw", "raw": "{\n \"username\": \"eve_{{run_id}}\",\n \"display_name\": \"Посторонний\",\n \"password\": \"{{demo_password}}\"\n}", "options": { "raw": { "language": "json" } } } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 201\", () => pm.response.to.have.status(201));", "if (pm.response.code === 201) pm.collectionVariables.set(\"eve_id\", pm.response.json().id);", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "06 — Вход alice через Basic", "request": { "method": "POST", "header": [], "url": "{{base_url}}/api/v1/auth/sessions", "auth": { "type": "basic", "basic": [ { "key": "username", "value": "alice_{{run_id}}", "type": "string" }, { "key": "password", "value": "{{demo_password}}", "type": "string" } ] } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 201\", () => pm.response.to.have.status(201));", "if (pm.response.code === 201) {", " pm.collectionVariables.set(\"alice_token\", pm.response.json().token);", " pm.collectionVariables.set(\"alice_expires_at\", pm.response.json().expires_at);", "}", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "07 — Вход bob через Basic", "request": { "method": "POST", "header": [], "url": "{{base_url}}/api/v1/auth/sessions", "auth": { "type": "basic", "basic": [ { "key": "username", "value": "bob_{{run_id}}", "type": "string" }, { "key": "password", "value": "{{demo_password}}", "type": "string" } ] } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 201\", () => pm.response.to.have.status(201));", "if (pm.response.code === 201) {", " pm.collectionVariables.set(\"bob_token\", pm.response.json().token);", " pm.collectionVariables.set(\"bob_expires_at\", pm.response.json().expires_at);", "}", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "08 — Вход eve через Basic", "request": { "method": "POST", "header": [], "url": "{{base_url}}/api/v1/auth/sessions", "auth": { "type": "basic", "basic": [ { "key": "username", "value": "eve_{{run_id}}", "type": "string" }, { "key": "password", "value": "{{demo_password}}", "type": "string" } ] } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 201\", () => pm.response.to.have.status(201));", "if (pm.response.code === 201) {", " pm.collectionVariables.set(\"eve_token\", pm.response.json().token);", " pm.collectionVariables.set(\"eve_expires_at\", pm.response.json().expires_at);", "}", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "09 — Кто я через Bearer", "request": { "method": "GET", "header": [], "url": "{{base_url}}/api/v1/users/me", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{alice_token}}", "type": "string" } ] } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "10 — Создать чат", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "url": "{{base_url}}/api/v1/chats", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{alice_token}}", "type": "string" } ] }, "body": { "mode": "raw", "raw": "{\n \"title\": \"Защита лабораторной 3\",\n \"member_ids\": [\n \"{{alice_id}}\",\n \"{{bob_id}}\"\n ]\n}", "options": { "raw": { "language": "json" } } } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 201\", () => pm.response.to.have.status(201));", "if (pm.response.code === 201) pm.collectionVariables.set(\"chat_id\", pm.response.json().id);", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "11 — Мои чаты", "request": { "method": "GET", "header": [], "url": "{{base_url}}/api/v1/chats?limit=50", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{bob_token}}", "type": "string" } ] } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "12 — Чат участника", "request": { "method": "GET", "header": [], "url": "{{base_url}}/api/v1/chats/{{chat_id}}", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{bob_token}}", "type": "string" } ] } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "13 — Сообщение Глеба", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" }, { "key": "Idempotency-Key", "value": "{{$guid}}" } ], "url": "{{base_url}}/api/v1/chats/{{chat_id}}/messages", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{alice_token}}", "type": "string" } ] }, "body": { "mode": "raw", "raw": "{\n \"text\": \"Привет, мир 👋\"\n}", "options": { "raw": { "language": "json" } } } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 201\", () => pm.response.to.have.status(201));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "14 — Сообщение Боба", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" }, { "key": "Idempotency-Key", "value": "{{$guid}}" } ], "url": "{{base_url}}/api/v1/chats/{{chat_id}}/messages", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{bob_token}}", "type": "string" } ] }, "body": { "mode": "raw", "raw": "{\n \"text\": \"Данные теперь в PostgreSQL\"\n}", "options": { "raw": { "language": "json" } } } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 201\", () => pm.response.to.have.status(201));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "15 — История", "request": { "method": "GET", "header": [], "url": "{{base_url}}/api/v1/chats/{{chat_id}}/messages?limit=50", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{alice_token}}", "type": "string" } ] } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "16 — Первая страница", "request": { "method": "GET", "header": [], "url": "{{base_url}}/api/v1/chats/{{chat_id}}/messages?limit=1", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{alice_token}}", "type": "string" } ] } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));", "if (pm.response.code === 200) {", " pm.test(\"Есть следующая страница\", () => pm.expect(pm.response.json().next_cursor).to.be.a(\"string\"));", " pm.collectionVariables.set(\"next_cursor\", encodeURIComponent(pm.response.json().next_cursor || \"\"));", "}", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "17 — Следующая страница", "request": { "method": "GET", "header": [], "url": "{{base_url}}/api/v1/chats/{{chat_id}}/messages?limit=1&cursor={{next_cursor}}", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{bob_token}}", "type": "string" } ] } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));", "if (pm.response.code === 200) pm.test(\"История закончилась\", () => pm.expect(pm.response.json().next_cursor).to.equal(null));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "18 — Посторонний получает 404", "request": { "method": "GET", "header": [], "url": "{{base_url}}/api/v1/chats/{{chat_id}}/messages", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{eve_token}}", "type": "string" } ] } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 404\", () => pm.response.to.have.status(404));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "19 — Аноним получает 401", "request": { "method": "GET", "header": [], "url": "{{base_url}}/api/v1/users/me" }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 401\", () => pm.response.to.have.status(401));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "20 — Basic не подходит для бизнес-запроса", "request": { "method": "GET", "header": [], "url": "{{base_url}}/api/v1/users/me", "auth": { "type": "basic", "basic": [ { "key": "username", "value": "alice_{{run_id}}", "type": "string" }, { "key": "password", "value": "{{demo_password}}", "type": "string" } ] } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 401\", () => pm.response.to.have.status(401));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "21 — Пустое сообщение получает 400", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" }, { "key": "Idempotency-Key", "value": "{{$guid}}" } ], "url": "{{base_url}}/api/v1/chats/{{chat_id}}/messages", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{alice_token}}", "type": "string" } ] }, "body": { "mode": "raw", "raw": "{\n \"text\": \"\"\n}", "options": { "raw": { "language": "json" } } } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 400\", () => pm.response.to.have.status(400));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "Идемпотентность — первая отправка", "request": { "method": "POST", "url": "{{base_url}}/api/v1/chats/{{chat_id}}/messages", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{alice_token}}", "type": "string" } ] }, "header": [ { "key": "Idempotency-Key", "value": "demo-{{run_id}}" }, { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\"text\": \"Повторяем безопасно\"}", "options": { "raw": { "language": "json" } } } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 201\", () => pm.response.to.have.status(201));", "if(pm.response.code===201) pm.collectionVariables.set(\"repeat_id\",pm.response.json().id);" ] } } ], "response": [] }, { "name": "Идемпотентность — повтор, тот же id", "request": { "method": "POST", "url": "{{base_url}}/api/v1/chats/{{chat_id}}/messages", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{alice_token}}", "type": "string" } ] }, "header": [ { "key": "Idempotency-Key", "value": "demo-{{run_id}}" }, { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\"text\": \"Повторяем безопасно\"}", "options": { "raw": { "language": "json" } } } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 201\", () => pm.response.to.have.status(201));", "pm.test(\"Same message\",()=>pm.expect(pm.response.json().id).to.equal(pm.collectionVariables.get(\"repeat_id\")));" ] } } ], "response": [] }, { "name": "Идемпотентность — другой текст 409", "request": { "method": "POST", "url": "{{base_url}}/api/v1/chats/{{chat_id}}/messages", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{alice_token}}", "type": "string" } ] }, "header": [ { "key": "Idempotency-Key", "value": "demo-{{run_id}}" }, { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\"text\": \"Изменённый текст\"}", "options": { "raw": { "language": "json" } } } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 409\", () => pm.response.to.have.status(409));" ] } } ], "response": [] }, { "name": "22 — Logout текущего токена", "request": { "method": "DELETE", "header": [], "url": "{{base_url}}/api/v1/auth/sessions/current", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{alice_token}}", "type": "string" } ] } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 204\", () => pm.response.to.have.status(204));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] }, { "name": "23 — Отозванный токен получает 401", "request": { "method": "GET", "header": [], "url": "{{base_url}}/api/v1/users/me", "auth": { "type": "bearer", "bearer": [ { "key": "token", "value": "{{alice_token}}", "type": "string" } ] } }, "event": [ { "listen": "test", "script": { "type": "text/javascript", "exec": [ "pm.test(\"HTTP 401\", () => pm.response.to.have.status(401));", "pm.test(\"API instance and request id\", () => { pm.expect(pm.response.headers.get(\"X-Instance-Id\")).to.be.a(\"string\").and.not.empty; pm.expect(pm.response.headers.get(\"X-Request-Id\")).to.be.a(\"string\").and.not.empty; });" ] } } ], "response": [] } ] }