Files
mtusi2026lab2/postman/lab2.postman_collection.json
T

861 lines
22 KiB
JSON

{
"info": {
"name": "ЛР 2 — Крайкин БВТ2303 — PostgreSQL и сессии",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"description": "Запустите make up. Run выполняет 23 запроса сверху вниз, сохраняет ID и токены только в локальные переменные Postman. Новый run_id позволяет повторять сценарий. Для ручной проверки persistence остановитесь после 17, выполните scripts/restart.sh, повторите 09 и 15 с прежним Bearer, затем 22 и 23. Никаких реальных паролей; demo_password синтетический. Для localhost нужен настольный Postman/Desktop Agent. Перед экспортом коллекции очистите значения токенов."
},
"variable": [
{
"key": "base_url",
"value": "http://localhost:8082",
"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"
}
],
"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));"
]
}
}
],
"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));"
]
}
}
],
"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);"
]
}
}
],
"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);"
]
}
}
],
"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);"
]
}
}
],
"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);",
"}"
]
}
}
],
"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);",
"}"
]
}
}
],
"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);",
"}"
]
}
}
],
"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));"
]
}
}
],
"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\": \"Защита лабораторной 2\",\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);"
]
}
}
],
"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));"
]
}
}
],
"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));"
]
}
}
],
"response": []
},
{
"name": "13 — Сообщение Глеба",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"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));"
]
}
}
],
"response": []
},
{
"name": "14 — Сообщение Боба",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"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));"
]
}
}
],
"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));"
]
}
}
],
"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 || \"\"));",
"}"
]
}
}
],
"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));"
]
}
}
],
"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));"
]
}
}
],
"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));"
]
}
}
],
"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));"
]
}
}
],
"response": []
},
{
"name": "21 — Пустое сообщение получает 400",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"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));"
]
}
}
],
"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));"
]
}
}
],
"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));"
]
}
}
],
"response": []
}
]
}