[优化] 添加自动 IP 组功能,支持按 Expr 规则聚合请求日志并更新 IP 列表

This commit is contained in:
ryan
2026-06-01 09:33:04 +08:00
parent dfb3972b15
commit bc1b861841
17 changed files with 665 additions and 41 deletions
@@ -172,6 +172,38 @@ describe('WAF IP groups', () => {
await waitFor(() => expect(groups).toHaveLength(1));
});
it('adds automatic Expr preset rules', async () => {
vi.stubGlobal(
'fetch',
vi.fn((input: RequestInfo | URL) => {
const url = String(input);
if (url.includes('/waf/ip-groups')) {
return Promise.resolve(
new Response(
JSON.stringify({ success: true, message: '', data: [] }),
),
);
}
return Promise.reject(new Error(`Unhandled fetch: ${url}`));
}),
);
renderWithProviders(<WAFIPGroupsPage />);
await screen.findByText('暂无 IP 组');
await userEvent.click(screen.getByRole('button', { name: /新建 IP 组/ }));
await userEvent.selectOptions(screen.getByLabelText('类型'), 'automatic');
await userEvent.click(screen.getByText('单 IP 404 高频扫描'));
await userEvent.click(screen.getByText('单 IP 直连访问异常'));
const textarea = screen.getByLabelText(/自动配置 JSON/);
const value = (textarea as HTMLTextAreaElement).value;
expect(value).toContain('request_count > 100 && status_404_ratio >= 0.8');
expect(value).toContain('ip_host_count > 50 && ip_host_ratio > 0.5');
});
it('opens IP group management from WAF page and references an IP group', async () => {
vi.stubGlobal(
'fetch',