Files
VLoop/test/auth.json

129 lines
3.0 KiB
JSON
Raw Normal View History

{
"info": {
"_postman_id": "2a6b02fb-7ab2-4f4c-a1c6-6e19e7d9f2ba",
"name": "feedsystem auth flow",
"description": "使用 Postman 验证 /auth/login 与 /auth/logout 接口。先运行 Login 请求以保存 token再运行 Logout 请求Logout 会自动把 token 放到 Authorization 头里。",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Login",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"username\": \"{{username}}\",\n \"password\": \"{{password}}\"\n}"
},
"url": {
"raw": "{{baseUrl}}/auth/login",
"host": [
"{{baseUrl}}"
],
"path": [
"auth",
"login"
]
}
},
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"pm.test(\"登录成功\", function () {",
" pm.response.to.have.status(200);",
" var data = pm.response.json();",
" pm.expect(data.token).to.exist;",
" pm.collectionVariables.set(\"jwt_token\", data.token);",
"});"
]
}
}
]
},
{
"name": "Logout",
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
"if (!pm.collectionVariables.get(\"jwt_token\")) {",
" throw new Error(\"请先运行 Login 请求以获取 token\");",
"}"
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"pm.test(\"登出成功\", function () {",
" pm.response.to.have.status(200);",
"});"
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt_token}}"
}
],
"body": {
"mode": "raw",
2025-12-05 14:27:26 +08:00
"raw": "{\n \"id\": {{accountId}}\n}"
},
"url": {
"raw": "{{baseUrl}}/auth/logout",
"host": [
"{{baseUrl}}"
],
"path": [
"auth",
"logout"
]
}
}
}
],
"variable": [
{
"key": "baseUrl",
"value": "http://localhost:8080"
},
{
"key": "username",
"value": "demo"
},
{
"key": "password",
"value": "demo123"
},
{
2025-12-05 14:27:26 +08:00
"key": "accountId",
"value": "1"
},
{
"key": "jwt_token",
"value": ""
}
]
}