feat: 完善系统配置审计通知功能并优化异常处理
- 新增异常处理体系(BaseException及其子类) - 优化密码、邮箱、用户名等基础类型 - 添加字典管理、登录日志、操作日志的E2E测试 - 完善API集成测试和安全测试 - 添加性能测试配置和脚本 - 优化OpenAPI配置和全局异常处理器
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
import http from 'k6/http';
|
||||
import { check, sleep } from 'k6';
|
||||
|
||||
const BASE_URL = 'http://localhost:8084';
|
||||
|
||||
export const options = {
|
||||
stages: [
|
||||
{ duration: '2m', target: 10 }, // 2分钟内增加到10用户
|
||||
{ duration: '5m', target: 10 }, // 保持10用户5分钟
|
||||
{ duration: '2m', target: 50 }, // 2分钟内增加到50用户
|
||||
{ duration: '5m', target: 50 }, // 保持50用户5分钟
|
||||
{ duration: '2m', target: 100 }, // 2分钟内增加到100用户
|
||||
{ duration: '5m', target: 100 }, // 保持100用户5分钟
|
||||
{ duration: '2m', target: 0 }, // 2分钟内降到0用户
|
||||
],
|
||||
thresholds: {
|
||||
http_req_duration: ['p(95)<500'], // 95%的请求响应时间<500ms
|
||||
http_req_failed: ['rate<0.01'], // 错误率<1%
|
||||
},
|
||||
};
|
||||
|
||||
export default function () {
|
||||
// 测试1: 健康检查
|
||||
let healthRes = http.get(`${BASE_URL}/actuator/health`);
|
||||
check(healthRes, {
|
||||
'健康检查状态码200': (r) => r.status === 200,
|
||||
'健康检查响应时间<100ms': (r) => r.timings.duration < 100,
|
||||
});
|
||||
|
||||
// 测试2: 登录
|
||||
let loginRes = http.post(
|
||||
`${BASE_URL}/api/auth/login`,
|
||||
JSON.stringify({
|
||||
username: 'admin',
|
||||
password: 'admin123',
|
||||
}),
|
||||
{
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}
|
||||
);
|
||||
check(loginRes, {
|
||||
'登录状态码200': (r) => r.status === 200,
|
||||
'登录响应时间<500ms': (r) => r.timings.duration < 500,
|
||||
'登录返回token': (r) => JSON.parse(r.body).token !== undefined,
|
||||
});
|
||||
|
||||
// 测试3: 获取用户列表
|
||||
const token = JSON.parse(loginRes.body).token;
|
||||
let usersRes = http.get(
|
||||
`${BASE_URL}/api/users?page=0&size=10`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
check(usersRes, {
|
||||
'用户列表状态码200': (r) => r.status === 200,
|
||||
'用户列表响应时间<300ms': (r) => r.timings.duration < 300,
|
||||
'用户列表返回数据': (r) => JSON.parse(r.body).content !== undefined,
|
||||
});
|
||||
|
||||
// 测试4: 获取角色列表
|
||||
let rolesRes = http.get(
|
||||
`${BASE_URL}/api/roles?page=0&size=10`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
check(rolesRes, {
|
||||
'角色列表状态码200': (r) => r.status === 200,
|
||||
'角色列表响应时间<300ms': (r) => r.timings.duration < 300,
|
||||
'角色列表返回数据': (r) => JSON.parse(r.body).content !== undefined,
|
||||
});
|
||||
|
||||
// 测试5: 获取字典列表
|
||||
let dictRes = http.get(
|
||||
`${BASE_URL}/api/dicts?page=0&size=10`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
check(dictRes, {
|
||||
'字典列表状态码200': (r) => r.status === 200,
|
||||
'字典列表响应时间<300ms': (r) => r.timings.duration < 300,
|
||||
'字典列表返回数据': (r) => JSON.parse(r.body).content !== undefined,
|
||||
});
|
||||
|
||||
// 测试6: 获取系统配置
|
||||
let configRes = http.get(
|
||||
`${BASE_URL}/api/configs?page=0&size=10`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
check(configRes, {
|
||||
'系统配置状态码200': (r) => r.status === 200,
|
||||
'系统配置响应时间<300ms': (r) => r.timings.duration < 300,
|
||||
'系统配置返回数据': (r) => JSON.parse(r.body).content !== undefined,
|
||||
});
|
||||
|
||||
// 测试7: 获取通知列表
|
||||
let noticeRes = http.get(
|
||||
`${BASE_URL}/api/notices?page=0&size=10`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
check(noticeRes, {
|
||||
'通知列表状态码200': (r) => r.status === 200,
|
||||
'通知列表响应时间<300ms': (r) => r.timings.duration < 300,
|
||||
'通知列表返回数据': (r) => JSON.parse(r.body).content !== undefined,
|
||||
});
|
||||
|
||||
// 测试8: 获取操作日志
|
||||
let opLogRes = http.get(
|
||||
`${BASE_URL}/api/operation-logs?page=0&size=10`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
check(opLogRes, {
|
||||
'操作日志状态码200': (r) => r.status === 200,
|
||||
'操作日志响应时间<300ms': (r) => r.timings.duration < 300,
|
||||
'操作日志返回数据': (r) => JSON.parse(r.body).content !== undefined,
|
||||
});
|
||||
|
||||
sleep(1); // 每个虚拟用户之间间隔1秒
|
||||
}
|
||||
Reference in New Issue
Block a user