mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2026-11-03 19:52:14 +08:00
Merge pull request #766 from samwafgo/fix_openapi_testcase
Fix openapi testcase
This commit is contained in:
+54
-28
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type WafSensitiveApi struct {
|
||||
@@ -26,25 +27,36 @@ type WafSensitiveApi struct {
|
||||
func (w *WafSensitiveApi) AddApi(c *gin.Context) {
|
||||
var req request.WafSensitiveAddReq
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err == nil {
|
||||
err = wafSensitiveService.CheckIsExistApi(req)
|
||||
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
err = wafSensitiveService.AddApi(req)
|
||||
if err == nil {
|
||||
w.NotifyWaf()
|
||||
response.OkWithMessage("添加成功", c)
|
||||
} else {
|
||||
|
||||
response.FailWithMessage("添加失败", c)
|
||||
}
|
||||
return
|
||||
} else {
|
||||
response.FailWithMessage("当前敏感词已经存在", c)
|
||||
return
|
||||
}
|
||||
|
||||
} else {
|
||||
if err != nil {
|
||||
response.FailWithMessage("解析失败", c)
|
||||
return
|
||||
}
|
||||
req.Content = strings.TrimSpace(req.Content)
|
||||
req.CheckDirection = strings.TrimSpace(req.CheckDirection)
|
||||
req.Action = strings.TrimSpace(req.Action)
|
||||
if req.Content == "" {
|
||||
response.FailWithMessage("敏感词内容不能为空", c)
|
||||
return
|
||||
}
|
||||
if req.CheckDirection == "" {
|
||||
response.FailWithMessage("检测方向不能为空", c)
|
||||
return
|
||||
}
|
||||
if req.Action == "" {
|
||||
response.FailWithMessage("检测动作不能为空", c)
|
||||
return
|
||||
}
|
||||
err = wafSensitiveService.CheckIsExistApi(req)
|
||||
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
err = wafSensitiveService.AddApi(req)
|
||||
if err == nil {
|
||||
w.NotifyWaf()
|
||||
response.OkWithMessage("添加成功", c)
|
||||
} else {
|
||||
response.FailWithMessage("添加失败", c)
|
||||
}
|
||||
} else {
|
||||
response.FailWithMessage("当前敏感词已经存在", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,17 +190,31 @@ func (w *WafSensitiveApi) DelAllSensitiveApi(c *gin.Context) {
|
||||
func (w *WafSensitiveApi) ModifySensitiveApi(c *gin.Context) {
|
||||
var req request.WafSensitiveEditReq
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err == nil {
|
||||
err = wafSensitiveService.ModifyApi(req)
|
||||
if err != nil {
|
||||
response.FailWithMessage("编辑发生错误", c)
|
||||
} else {
|
||||
w.NotifyWaf()
|
||||
response.OkWithMessage("编辑成功", c)
|
||||
}
|
||||
|
||||
} else {
|
||||
if err != nil {
|
||||
response.FailWithMessage("解析失败", c)
|
||||
return
|
||||
}
|
||||
req.Content = strings.TrimSpace(req.Content)
|
||||
req.CheckDirection = strings.TrimSpace(req.CheckDirection)
|
||||
req.Action = strings.TrimSpace(req.Action)
|
||||
if req.Content == "" {
|
||||
response.FailWithMessage("敏感词内容不能为空", c)
|
||||
return
|
||||
}
|
||||
if req.CheckDirection == "" {
|
||||
response.FailWithMessage("检测方向不能为空", c)
|
||||
return
|
||||
}
|
||||
if req.Action == "" {
|
||||
response.FailWithMessage("检测动作不能为空", c)
|
||||
return
|
||||
}
|
||||
err = wafSensitiveService.ModifyApi(req)
|
||||
if err != nil {
|
||||
response.FailWithMessage("编辑发生错误", c)
|
||||
} else {
|
||||
w.NotifyWaf()
|
||||
response.OkWithMessage("编辑成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -19,8 +19,12 @@ type WafStatApi struct {
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /statsysinfo [get]
|
||||
func (w *WafStatApi) StatSysinfoApi(c *gin.Context) {
|
||||
|
||||
response.OkWithDetailed(wafStatService.StatHomeSysinfo(c), "获取成功", c)
|
||||
data, err := wafStatService.StatHomeSysinfo(c)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(data, "获取成功", c)
|
||||
}
|
||||
|
||||
// StatRumtimeSysinfoApi 获取运行时系统基本信息
|
||||
|
||||
+44
-10
@@ -11,8 +11,10 @@ import (
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -34,17 +36,49 @@ type WafVpConfigApi struct {
|
||||
func (w *WafVpConfigApi) UpdateIpWhitelistApi(c *gin.Context) {
|
||||
var req request.WafVpConfigIpWhitelistUpdateReq
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err == nil {
|
||||
|
||||
// 调用配置文件更新函数
|
||||
err = wafconfig.UpdateIpWhitelist(req.IpWhitelist)
|
||||
if err != nil {
|
||||
response.FailWithMessage("更新IP白名单失败: "+err.Error(), c)
|
||||
} else {
|
||||
response.OkWithMessage("更新IP白名单成功", c)
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
response.FailWithMessage("解析请求失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 防护1:不允许提交空白名单,避免所有人被锁在外面
|
||||
if strings.TrimSpace(req.IpWhitelist) == "" {
|
||||
response.FailWithMessage("IP白名单不能为空,否则将无法访问管理端", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 防护2:新白名单必须包含当前请求方的 IP,防止把自己锁在外面
|
||||
clientIP := c.ClientIP()
|
||||
entries := strings.Split(req.IpWhitelist, ",")
|
||||
selfIncluded := false
|
||||
for _, entry := range entries {
|
||||
entry = strings.TrimSpace(entry)
|
||||
if entry == "" {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(entry, "/") {
|
||||
// CIDR 格式
|
||||
_, ipNet, cidrErr := net.ParseCIDR(entry)
|
||||
if cidrErr == nil && ipNet.Contains(net.ParseIP(clientIP)) {
|
||||
selfIncluded = true
|
||||
break
|
||||
}
|
||||
} else if entry == clientIP {
|
||||
selfIncluded = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !selfIncluded {
|
||||
response.FailWithMessage(fmt.Sprintf("当前访问IP(%s)不在新白名单中,保存后将无法访问管理端,请先将自己的IP加入白名单", clientIP), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 调用配置文件更新函数
|
||||
err = wafconfig.UpdateIpWhitelist(req.IpWhitelist)
|
||||
if err != nil {
|
||||
response.FailWithMessage("更新IP白名单失败: "+err.Error(), c)
|
||||
} else {
|
||||
response.OkWithMessage("更新IP白名单成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package request
|
||||
import "SamWaf/model/common/request"
|
||||
|
||||
type WafAllowIpAddReq struct {
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Ip string `json:"ip"` //白名单ip
|
||||
Remarks string `json:"remarks"` //备注
|
||||
HostCode string `json:"host_code" binding:"required"` //网站唯一码(主要键)
|
||||
Ip string `json:"ip" binding:"required"` //白名单ip
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
type WafAllowIpDelReq struct {
|
||||
Id string `json:"id" form:"id"` //白名单IP唯一键
|
||||
@@ -15,10 +15,10 @@ type WafAllowIpDetailReq struct {
|
||||
}
|
||||
|
||||
type WafAllowIpEditReq struct {
|
||||
Id string `json:"id"` //白名单IP唯一键
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Ip string `json:"ip"` //白名单ip
|
||||
Remarks string `json:"remarks"` //备注
|
||||
Id string `json:"id" binding:"required"` //白名单IP唯一键
|
||||
HostCode string `json:"host_code" binding:"required"` //网站唯一码(主要键)
|
||||
Ip string `json:"ip" binding:"required"` //白名单ip
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
type WafAllowIpSearchReq struct {
|
||||
HostCode string `json:"host_code" ` //主机码
|
||||
|
||||
@@ -3,10 +3,10 @@ package request
|
||||
import "SamWaf/model/common/request"
|
||||
|
||||
type WafAllowUrlAddReq struct {
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
CompareType string `json:"compare_type" form:"compare_type"` //对比方式
|
||||
Url string `json:"url"` //白名单url
|
||||
Remarks string `json:"remarks"` //备注
|
||||
HostCode string `json:"host_code" binding:"required"` //网站唯一码(主要键)
|
||||
CompareType string `json:"compare_type" form:"compare_type" binding:"required"` //对比方式
|
||||
Url string `json:"url" binding:"required"` //白名单url
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
type WafAllowUrlDelReq struct {
|
||||
Id string `json:"id" form:"id"` //白名单url唯一键
|
||||
@@ -16,11 +16,11 @@ type WafAllowUrlDetailReq struct {
|
||||
Id string `json:"id" form:"id"` //白名单Url唯一键
|
||||
}
|
||||
type WafAllowUrlEditReq struct {
|
||||
Id string `json:"id"` //白名单url唯一键
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
CompareType string `json:"compare_type" form:"compare_type"` //对比方式
|
||||
Url string `json:"url"` //白名单url
|
||||
Remarks string `json:"remarks"` //备注
|
||||
Id string `json:"id" binding:"required"` //白名单url唯一键
|
||||
HostCode string `json:"host_code" binding:"required"` //网站唯一码(主要键)
|
||||
CompareType string `json:"compare_type" form:"compare_type" binding:"required"` //对比方式
|
||||
Url string `json:"url" binding:"required"` //白名单url
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
|
||||
type WafAllowUrlSearchReq struct {
|
||||
|
||||
@@ -3,15 +3,15 @@ package request
|
||||
import "SamWaf/model/common/request"
|
||||
|
||||
type WafAntiCCAddReq struct {
|
||||
HostCode string `json:"host_code" form:"host_code"` //网站唯一码(主要键)
|
||||
Url string `json:"url" form:"url"` //白名单url
|
||||
Rate int `json:"rate" form:"rate"` //速率
|
||||
Limit int `json:"limit" form:"limit"` //限制
|
||||
LockIPMinutes int `json:"lock_ip_minutes" form:"lock_ip_minutes"` //封禁分钟
|
||||
LimitMode string `json:"limit_mode" form:"limit_mode"` // "rate" 或 "window"
|
||||
IsEnableRule bool `json:"is_enable_rule" form:"is_enable_rule"` //是否启动规则
|
||||
RuleContent string `json:"rule_content" form:"rule_content"` //规则内容
|
||||
Remarks string `json:"remarks" form:"remarks"` //备注
|
||||
HostCode string `json:"host_code" form:"host_code" binding:"required"` //网站唯一码(主要键)
|
||||
Url string `json:"url" form:"url" binding:"required"` //白名单url
|
||||
Rate int `json:"rate" form:"rate" binding:"required"` //速率
|
||||
Limit int `json:"limit" form:"limit" binding:"required"` //限制
|
||||
LockIPMinutes int `json:"lock_ip_minutes" form:"lock_ip_minutes" binding:"required"` //封禁分钟
|
||||
LimitMode string `json:"limit_mode" form:"limit_mode" binding:"required"` // "rate" 或 "window"
|
||||
IsEnableRule bool `json:"is_enable_rule" form:"is_enable_rule" binding:"required"` //是否启动规则
|
||||
RuleContent string `json:"rule_content" form:"rule_content"` //规则内容
|
||||
Remarks string `json:"remarks" form:"remarks"` //备注
|
||||
}
|
||||
type WafAntiCCSearchReq struct {
|
||||
HostCode string `json:"host_code" ` //主机码
|
||||
@@ -24,16 +24,16 @@ type WafAntiCCDetailReq struct {
|
||||
Id string `json:"id" form:"id"` //白名单Url唯一键
|
||||
}
|
||||
type WafAntiCCEditReq struct {
|
||||
Id string `json:"id"` //白名单url唯一键
|
||||
HostCode string `json:"host_code" form:"host_code"` //网站唯一码(主要键)
|
||||
Url string `json:"url" form:"url"` //白名单url
|
||||
Rate int `json:"rate" form:"rate"` //速率
|
||||
Limit int `json:"limit" form:"limit"` //限制
|
||||
LockIPMinutes int `json:"lock_ip_minutes" form:"lock_ip_minutes"` //封禁分钟
|
||||
LimitMode string `json:"limit_mode" form:"limit_mode"` // "rate" 或 "window"
|
||||
IsEnableRule bool `json:"is_enable_rule" form:"is_enable_rule"` //是否启动规则
|
||||
RuleContent string `json:"rule_content" form:"rule_content"` //规则内容
|
||||
Remarks string `json:"remarks" form:"remarks"` //备注
|
||||
Id string `json:"id" binding:"required"` //白名单url唯一键
|
||||
HostCode string `json:"host_code" form:"host_code" binding:"required"` //网站唯一码(主要键)
|
||||
Url string `json:"url" form:"url" binding:"required"` //白名单url
|
||||
Rate int `json:"rate" form:"rate" binding:"required"` //速率
|
||||
Limit int `json:"limit" form:"limit" binding:"required"` //限制
|
||||
LockIPMinutes int `json:"lock_ip_minutes" form:"lock_ip_minutes" binding:"required"` //封禁分钟
|
||||
LimitMode string `json:"limit_mode" form:"limit_mode" binding:"required"` // "rate" 或 "window"
|
||||
IsEnableRule bool `json:"is_enable_rule" form:"is_enable_rule" binding:"required"` //是否启动规则
|
||||
RuleContent string `json:"rule_content" form:"rule_content"` //规则内容
|
||||
Remarks string `json:"remarks" form:"remarks"` //备注
|
||||
}
|
||||
|
||||
// WafAntiCCRemoveBanIpReq 移除封禁ip
|
||||
|
||||
@@ -3,16 +3,16 @@ package request
|
||||
import "SamWaf/model/common/request"
|
||||
|
||||
type WafBlockIpAddReq struct {
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Ip string `json:"ip"` //Block ip
|
||||
Remarks string `json:"remarks"` //备注
|
||||
HostCode string `json:"host_code" binding:"required"` //网站唯一码(主要键)
|
||||
Ip string `json:"ip" binding:"required"` //Block ip
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
|
||||
type WafBlockIpEditReq struct {
|
||||
Id string `json:"id"` //Block IP唯一键
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Ip string `json:"ip"` //Block ip
|
||||
Remarks string `json:"remarks"` //备注
|
||||
Id string `json:"id" binding:"required"` //Block IP唯一键
|
||||
HostCode string `json:"host_code" binding:"required"` //网站唯一码(主要键)
|
||||
Ip string `json:"ip" binding:"required"` //Block ip
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
type WafBlockIpDelReq struct {
|
||||
Id string `json:"id" form:"id"` //Block IP唯一键
|
||||
|
||||
@@ -3,10 +3,10 @@ package request
|
||||
import "SamWaf/model/common/request"
|
||||
|
||||
type WafBlockUrlAddReq struct {
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
CompareType string `json:"compare_type" form:"compare_type"` //对比方式
|
||||
Url string `json:"url"` //Block url
|
||||
Remarks string `json:"remarks"` //备注
|
||||
HostCode string `json:"host_code" binding:"required"` //网站唯一码(主要键)
|
||||
CompareType string `json:"compare_type" form:"compare_type" binding:"required"` //对比方式
|
||||
Url string `json:"url" binding:"required"` //Block url
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
type WafBlockUrlSearchReq struct {
|
||||
HostCode string `json:"host_code" ` //主机码
|
||||
@@ -21,11 +21,11 @@ type WafBlockUrlDetailReq struct {
|
||||
Id string `json:"id" form:"id"` //Block Url唯一键
|
||||
}
|
||||
type WafBlockUrlEditReq struct {
|
||||
Id string `json:"id"` //Block url唯一键
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
CompareType string `json:"compare_type" form:"compare_type"` //对比方式
|
||||
Url string `json:"url"` //Block url
|
||||
Remarks string `json:"remarks"` //备注
|
||||
Id string `json:"id" binding:"required"` //Block url唯一键
|
||||
HostCode string `json:"host_code" binding:"required"` //网站唯一码(主要键)
|
||||
CompareType string `json:"compare_type" form:"compare_type" binding:"required"` //对比方式
|
||||
Url string `json:"url" binding:"required"` //Block url
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
|
||||
// 批量删除请求结构体
|
||||
|
||||
@@ -3,10 +3,10 @@ package waf_service
|
||||
import (
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/common/response"
|
||||
"SamWaf/model/request"
|
||||
response2 "SamWaf/model/response"
|
||||
"SamWaf/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/shirou/gopsutil/host"
|
||||
@@ -163,18 +163,17 @@ func (receiver *WafStatService) StatHomeSumDayTopIPRangeApi(req request.WafStats
|
||||
}
|
||||
|
||||
// 获取系统基本信息
|
||||
func (receiver *WafStatService) StatHomeSysinfo(c *gin.Context) response2.WafHomeSysinfoStat {
|
||||
func (receiver *WafStatService) StatHomeSysinfo(c *gin.Context) (response2.WafHomeSysinfoStat, error) {
|
||||
tokenStr := c.GetHeader("X-Token")
|
||||
tokenInfo := WafTokenInfoServiceApp.GetInfoByAccessToken(tokenStr)
|
||||
if tokenInfo.LoginAccount == "" {
|
||||
response.FailWithMessage("token可能已经失效", c)
|
||||
return response2.WafHomeSysinfoStat{}
|
||||
return response2.WafHomeSysinfoStat{}, errors.New("token可能已经失效")
|
||||
}
|
||||
return response2.WafHomeSysinfoStat{
|
||||
IsDefaultAccount: WafAccountServiceApp.IsExistDefaultAccount(),
|
||||
IsEmptyHost: WafHostServiceApp.IsEmptyHost(),
|
||||
IsEmptyOtp: WafOtpServiceApp.IsEmptyOtp(tokenInfo.LoginAccount),
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetTodaySiteStatsByHostCodes 获取指定站点今天的 PV/UV/拦截数/吞吐量
|
||||
|
||||
@@ -12,7 +12,9 @@ package apicheck
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -24,8 +26,8 @@ import (
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
const (
|
||||
baseURL = "http://127.0.0.1:26666" // 服务地址
|
||||
sk = "1111111" // X-Token 登录令牌,按实际值修改
|
||||
baseURL = "http://127.0.0.1:26666" // 服务地址
|
||||
sk = "sk-f4e7230617a118e8869a8089269e4b4b" // X-Token 登录令牌,按实际值修改
|
||||
)
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
@@ -279,7 +281,17 @@ func sendRequest(method, url string) (*http.Response, error) {
|
||||
return httpClient.Do(req)
|
||||
}
|
||||
|
||||
// TestAllRoutes 逐条验证 @Router 中的路由是否注册可达(非 404)
|
||||
// checkJSON 判断 body 是否为合法 JSON(允许对象或数组)
|
||||
func checkJSON(data []byte) bool {
|
||||
data = bytes.TrimSpace(data)
|
||||
if len(data) == 0 {
|
||||
return false
|
||||
}
|
||||
var v json.RawMessage
|
||||
return json.Unmarshal(data, &v) == nil
|
||||
}
|
||||
|
||||
// TestAllRoutes 逐条验证 @Router 中的路由是否注册可达(非 404)且响应为合法 JSON
|
||||
func TestAllRoutes(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("跳过集成测试(-short 模式)")
|
||||
@@ -287,9 +299,12 @@ func TestAllRoutes(t *testing.T) {
|
||||
|
||||
type result struct {
|
||||
route
|
||||
status int
|
||||
err string
|
||||
passed bool
|
||||
status int
|
||||
err string
|
||||
notFound bool // 路由不存在(404)
|
||||
notJSON bool // Content-Type 不含 application/json
|
||||
invalidJSON bool // body 无法解析为 JSON
|
||||
passed bool
|
||||
}
|
||||
|
||||
results := make([]result, 0, len(registeredRoutes))
|
||||
@@ -304,33 +319,55 @@ func TestAllRoutes(t *testing.T) {
|
||||
res.err = err.Error()
|
||||
res.passed = false
|
||||
} else {
|
||||
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
res.status = resp.StatusCode
|
||||
res.passed = resp.StatusCode != http.StatusNotFound
|
||||
res.notFound = resp.StatusCode == http.StatusNotFound
|
||||
|
||||
ct := resp.Header.Get("Content-Type")
|
||||
res.notJSON = !strings.Contains(ct, "application/json")
|
||||
res.invalidJSON = !checkJSON(bodyBytes)
|
||||
|
||||
res.passed = !res.notFound && !res.notJSON && !res.invalidJSON
|
||||
}
|
||||
results = append(results, res)
|
||||
|
||||
if !res.passed {
|
||||
failCount++
|
||||
}
|
||||
}
|
||||
|
||||
// ── 打印汇总 ──────────────────────────────────────────────────
|
||||
t.Log(strings.Repeat("─", 80))
|
||||
t.Logf("%-6s %-50s %-6s %s", "方法", "路径", "状态", "描述")
|
||||
t.Log(strings.Repeat("─", 80))
|
||||
t.Log(strings.Repeat("─", 90))
|
||||
t.Logf("%-6s %-50s %-6s %-16s %s", "方法", "路径", "状态", "问题", "描述")
|
||||
t.Log(strings.Repeat("─", 90))
|
||||
for _, res := range results {
|
||||
statusStr := fmt.Sprintf("%d", res.status)
|
||||
if res.err != "" {
|
||||
statusStr = "ERR"
|
||||
}
|
||||
mark := "✓"
|
||||
issue := "-"
|
||||
if !res.passed {
|
||||
mark = "✗"
|
||||
problems := []string{}
|
||||
if res.err != "" {
|
||||
problems = append(problems, "连接失败")
|
||||
}
|
||||
if res.notFound {
|
||||
problems = append(problems, "404")
|
||||
}
|
||||
if res.notJSON {
|
||||
problems = append(problems, "非JSON类型")
|
||||
}
|
||||
if res.invalidJSON {
|
||||
problems = append(problems, "JSON解析失败")
|
||||
}
|
||||
issue = strings.Join(problems, ",")
|
||||
}
|
||||
t.Logf("%s %-6s %-50s %-6s %s", mark, res.method, res.path, statusStr, res.desc)
|
||||
t.Logf("%s %-6s %-50s %-6s %-16s %s", mark, res.method, res.path, statusStr, issue, res.desc)
|
||||
}
|
||||
t.Log(strings.Repeat("─", 80))
|
||||
t.Log(strings.Repeat("─", 90))
|
||||
t.Logf("合计 %d 条,通过 %d 条,失败 %d 条", len(results), len(results)-failCount, failCount)
|
||||
|
||||
if failCount > 0 {
|
||||
@@ -352,10 +389,20 @@ func TestSingleRoute(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("请求失败: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
ct := resp.Header.Get("Content-Type")
|
||||
t.Logf("%s %s → HTTP %d Content-Type: %s", method, url, resp.StatusCode, ct)
|
||||
t.Logf("响应体: %s", string(bodyBytes))
|
||||
|
||||
t.Logf("%s %s → HTTP %d", method, url, resp.StatusCode)
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
t.Errorf("路由不存在 (404)")
|
||||
}
|
||||
if !strings.Contains(ct, "application/json") {
|
||||
t.Errorf("Content-Type 不是 application/json,实际: %s", ct)
|
||||
}
|
||||
if !checkJSON(bodyBytes) {
|
||||
t.Errorf("响应体不是合法 JSON")
|
||||
}
|
||||
}
|
||||
|
||||
+160
-158
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
```
|
||||
go test -v -run TestAllRoutes ./test/apicheck/
|
||||
go test -v -count=1 -run TestAllRoutes ./test/apicheck/ -timeout=30s
|
||||
|
||||
```
|
||||
|
||||
@@ -10,163 +10,165 @@ go test -v -run TestAllRoutes ./test/apicheck/
|
||||
|
||||
```
|
||||
|
||||
C:\huawei\goproject\SamWaf>go test -v -run TestAllRoutes ./test/apicheck/
|
||||
C:\huawei\goproject\SamWaf>go test -v -count=1 -run TestAllRoutes ./test/apicheck/ -timeout=30s
|
||||
=== RUN TestAllRoutes
|
||||
api_routes_test.go:317: ────────────────────────────────────────────────────────────────────────────────
|
||||
api_routes_test.go:318: 方法 路径 状态 描述
|
||||
api_routes_test.go:319: ────────────────────────────────────────────────────────────────────────────────
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/ipwhite/add 200 新增IP白名单
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/ipwhite/detail 200 获取IP白名单详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/ipwhite/list 200 获取IP白名单列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/ipwhite/del 200 删除IP白名单
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/ipwhite/edit 200 编辑IP白名单
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/urlwhite/add 200 新增URL白名单
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/urlwhite/detail 200 获取URL白名单详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/urlwhite/list 200 获取URL白名单列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/urlwhite/del 200 删除URL白名单
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/urlwhite/edit 200 编辑URL白名单
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/ipblock/add 200 新增IP黑名单
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/ipblock/detail 200 获取IP黑名单详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/ipblock/list 200 获取IP黑名单列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/ipblock/del 200 删除IP黑名单
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/ipblock/edit 200 编辑IP黑名单
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/urlblock/add 200 新增URL黑名单
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/urlblock/detail 200 获取URL黑名单详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/urlblock/list 200 获取URL黑名单列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/urlblock/del 200 删除URL黑名单
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/urlblock/edit 200 编辑URL黑名单
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/anticc/add 200 新增Anti-CC规则
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/anticc/detail 200 获取Anti-CC规则详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/anticc/list 200 获取Anti-CC规则列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/anticc/del 200 删除Anti-CC规则
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/anticc/edit 200 编辑Anti-CC规则
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/ipfailure/config 200 获取IP失败封禁配置
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/ipfailure/config 200 设置IP失败封禁配置
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/ipfailure/baniplist 200 获取IP失败封禁列表
|
||||
api_routes_test.go:329: ✓ POST /api/v1/firewall/ipblock/add 200 新增防火墙IP封禁
|
||||
api_routes_test.go:329: ✓ POST /api/v1/firewall/ipblock/list 200 获取防火墙IP封禁列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/firewall/ipblock/del 200 删除防火墙IP封禁
|
||||
api_routes_test.go:329: ✓ POST /api/v1/firewall/ipblock/edit 200 编辑防火墙IP封禁
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/rule/add 200 新增WAF规则
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/rule/detail 200 获取WAF规则详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/rule/list 200 获取WAF规则列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/rule/del 200 删除WAF规则
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/rule/edit 200 编辑WAF规则
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/rule/rulestatus 200 修改WAF规则状态
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/sensitive/add 200 新增敏感词
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/sensitive/detail 200 获取敏感词详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/sensitive/list 200 获取敏感词列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/sensitive/del 200 删除敏感词
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/sensitive/edit 200 编辑敏感词
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/cacherule/add 200 新增缓存规则
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/cacherule/detail 200 获取缓存规则详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/cacherule/list 200 获取缓存规则列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/cacherule/del 200 删除缓存规则
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/cacherule/edit 200 编辑缓存规则
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/loadbalance/add 200 新增负载均衡
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/loadbalance/detail 200 获取负载均衡详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/loadbalance/list 200 获取负载均衡列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/loadbalance/del 200 删除负载均衡
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/loadbalance/edit 200 编辑负载均衡
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/onekeymod/detail 200 获取一键修改详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/onekeymod/list 200 获取一键修改列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/onekeymod/del 200 删除一键修改
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/onekeymod/doModify 200 执行一键修改
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/onekeymod/restore 200 还原一键修改
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/task/add 200 新增任务
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/task/detail 200 获取任务详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/task/list 200 获取任务列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/task/del 200 删除任务
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/task/edit 200 编辑任务
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/task/manual_exec 200 手动执行任务
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/task/log 200 获取任务日志
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/task/log/clear 200 清空任务日志
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/dataretention/list 200 获取数据保留策略列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/dataretention/detail 200 获取数据保留策略详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/dataretention/edit 200 编辑数据保留策略
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/privateinfo/add 200 新增私有信息
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/privateinfo/detail 200 获取私有信息详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/privateinfo/list 200 获取私有信息列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/privateinfo/del 200 删除私有信息
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/privateinfo/edit 200 编辑私有信息
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/privategroup/add 200 新增私有分组
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/privategroup/detail 200 获取私有分组详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/privategroup/list 200 获取私有分组列表
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/privategroup/listbybelongcloud 200 按云获取私有分组列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/privategroup/del 200 删除私有分组
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/privategroup/edit 200 编辑私有分组
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/host/add 200 新增站点
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/host/detail 200 获取站点详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/host/list 200 获取站点列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/host/del 200 删除站点
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/host/edit 200 编辑站点
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/host/guardstatus 200 修改防护状态
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/host/startstatus 200 修改启动状态
|
||||
api_routes_test.go:329: ✓ POST /api/v1/sslconfig/add 200 新增SSL证书
|
||||
api_routes_test.go:329: ✓ GET /api/v1/sslconfig/detail 200 获取SSL证书详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/sslconfig/list 200 获取SSL证书列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/sslconfig/del 200 删除SSL证书
|
||||
api_routes_test.go:329: ✓ POST /api/v1/sslconfig/edit 200 编辑SSL证书
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/sslorder/add 200 新增SSL订单
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/sslorder/detail 200 获取SSL订单详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/sslorder/list 200 获取SSL订单列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/sslorder/del 200 删除SSL订单
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/sslorder/edit 200 编辑SSL订单
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/sslexpire/add 200 新增SSL到期监控
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/sslexpire/detail 200 获取SSL到期监控详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/sslexpire/list 200 获取SSL到期监控列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/sslexpire/del 200 删除SSL到期监控
|
||||
api_routes_test.go:329: ✓ POST /api/v1/wafhost/sslexpire/edit 200 编辑SSL到期监控
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/sslexpire/nowcheck 200 立即检测SSL到期
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafhost/sslexpire/sync_host 200 从站点同步SSL监控
|
||||
api_routes_test.go:329: ✓ POST /api/v1/tunnel/tunnel/add 200 新增隧道
|
||||
api_routes_test.go:329: ✓ GET /api/v1/tunnel/tunnel/detail 200 获取隧道详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/tunnel/tunnel/list 200 获取隧道列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/tunnel/tunnel/del 200 删除隧道
|
||||
api_routes_test.go:329: ✓ POST /api/v1/tunnel/tunnel/edit 200 编辑隧道
|
||||
api_routes_test.go:329: ✓ GET /api/v1/tunnel/tunnel/connections 200 获取隧道连接数
|
||||
api_routes_test.go:329: ✓ POST /api/v1/notify/channel/add 200 新增通知渠道
|
||||
api_routes_test.go:329: ✓ GET /api/v1/notify/channel/detail 200 获取通知渠道详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/notify/channel/list 200 获取通知渠道列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/notify/channel/del 200 删除通知渠道
|
||||
api_routes_test.go:329: ✓ POST /api/v1/notify/channel/edit 200 编辑通知渠道
|
||||
api_routes_test.go:329: ✓ POST /api/v1/notify/subscription/add 200 新增通知订阅
|
||||
api_routes_test.go:329: ✓ POST /api/v1/notify/subscription/list 200 获取通知订阅列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/notify/subscription/del 200 删除通知订阅
|
||||
api_routes_test.go:329: ✓ POST /api/v1/notify/log/list 200 获取通知日志列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/notify/log/detail 200 获取通知日志详情
|
||||
api_routes_test.go:329: ✓ GET /api/v1/notify/log/del 200 删除通知日志
|
||||
api_routes_test.go:329: ✓ POST /api/v1/vipconfig/updateIpWhitelist 200 更新管理IP白名单
|
||||
api_routes_test.go:329: ✓ GET /api/v1/vipconfig/getIpWhitelist 200 获取管理IP白名单
|
||||
api_routes_test.go:329: ✓ POST /api/v1/vipconfig/updateSslEnable 200 更新SSL启用状态
|
||||
api_routes_test.go:329: ✓ GET /api/v1/vipconfig/getSslStatus 200 获取SSL启用状态
|
||||
api_routes_test.go:329: ✓ GET /api/v1/vipconfig/getSecurityEntry 200 获取安全入口
|
||||
api_routes_test.go:329: ✓ POST /api/v1/vipconfig/updateSecurityEntry 200 更新安全入口
|
||||
api_routes_test.go:329: ✓ POST /api/v1/systemconfig/list 200 获取系统配置列表
|
||||
api_routes_test.go:329: ✓ POST /api/v1/systemconfig/edit 200 更新系统配置
|
||||
api_routes_test.go:329: ✓ POST /api/v1/systemconfig/editByItem 200 通过item更新系统配置
|
||||
api_routes_test.go:329: ✓ GET /api/v1/monitor/system_info 200 获取系统监控信息
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafstatsumday 200 获取今日访问统计
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafstatsumdayrange 200 按日期范围统计访问量
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafstatsumdaytopiprange 200 统计攻击IP排行
|
||||
api_routes_test.go:329: ✓ GET /api/v1/statsysinfo 200 获取首页系统基本信息
|
||||
api_routes_test.go:329: ✓ GET /api/v1/statrumtimesysinfo 200 获取运行时系统基本信息
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafstatsiteoverview 200 站点综合概览统计
|
||||
api_routes_test.go:329: ✓ GET /api/v1/wafstatsitedetail 200 站点详情趋势查询
|
||||
api_routes_test.go:329: ✓ GET /api/v1/sysinfo/version 200 获取版本信息
|
||||
api_routes_test.go:329: ✓ GET /api/v1/sys_log/list 200 获取系统日志列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/sys_log/detail 200 获取系统日志详情
|
||||
api_routes_test.go:329: ✓ POST /api/v1/waflog/attack/list 200 获取攻击日志列表
|
||||
api_routes_test.go:329: ✓ GET /api/v1/waflog/attack/detail 200 获取攻击日志详情
|
||||
api_routes_test.go:329: ✓ GET /api/v1/logfilewrite/preview 200 预览日志文件
|
||||
api_routes_test.go:329: ✓ GET /api/v1/logfilewrite/currentfile 200 获取当前日志文件
|
||||
api_routes_test.go:329: ✓ GET /api/v1/logfilewrite/backupfiles 200 获取备份日志文件列表
|
||||
api_routes_test.go:329: ✓ POST /api/v1/logfilewrite/clear 200 清空日志文件
|
||||
api_routes_test.go:329: ✓ GET /api/v1/logfilewrite/variables 200 获取日志变量
|
||||
api_routes_test.go:329: ✓ GET /api/v1/resetWAF 200 重启WAF引擎
|
||||
api_routes_test.go:331: ────────────────────────────────────────────────────────────────────────────────
|
||||
api_routes_test.go:332: 合计 149 条,通过 149 条,失败 0 条
|
||||
--- PASS: TestAllRoutes (0.12s)
|
||||
api_routes_test.go:341: ──────────────────────────────────────────────────────────────────────────────────────────
|
||||
api_routes_test.go:342: 方法 路径 状态 问题 描述
|
||||
api_routes_test.go:343: ──────────────────────────────────────────────────────────────────────────────────────────
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/ipwhite/add 200 - 新增IP白名单
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/ipwhite/detail 200 - 获取IP白名单详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/ipwhite/list 200 - 获取IP白名单列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/ipwhite/del 200 - 删除IP白名单
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/ipwhite/edit 200 - 编辑IP白名单
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/urlwhite/add 200 - 新增URL白名单
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/urlwhite/detail 200 - 获取URL白名单详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/urlwhite/list 200 - 获取URL白名单列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/urlwhite/del 200 - 删除URL白名单
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/urlwhite/edit 200 - 编辑URL白名单
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/ipblock/add 200 - 新增IP黑名单
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/ipblock/detail 200 - 获取IP黑名单详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/ipblock/list 200 - 获取IP黑名单列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/ipblock/del 200 - 删除IP黑名单
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/ipblock/edit 200 - 编辑IP黑名单
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/urlblock/add 200 - 新增URL黑名单
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/urlblock/detail 200 - 获取URL黑名单详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/urlblock/list 200 - 获取URL黑名单列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/urlblock/del 200 - 删除URL黑名单
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/urlblock/edit 200 - 编辑URL黑名单
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/anticc/add 200 - 新增Anti-CC规则
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/anticc/detail 200 - 获取Anti-CC规则详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/anticc/list 200 - 获取Anti-CC规则列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/anticc/del 200 - 删除Anti-CC规则
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/anticc/edit 200 - 编辑Anti-CC规则
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/ipfailure/config 200 - 获取IP失败封禁配置
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/ipfailure/config 200 - 设置IP失败封禁配置
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/ipfailure/baniplist 200 - 获取IP失败封禁列表
|
||||
api_routes_test.go:368: ✓ POST /api/v1/firewall/ipblock/add 200 - 新增防火墙IP封禁
|
||||
api_routes_test.go:368: ✓ POST /api/v1/firewall/ipblock/list 200 - 获取防火墙IP封禁列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/firewall/ipblock/del 200 - 删除防火墙IP封禁
|
||||
api_routes_test.go:368: ✓ POST /api/v1/firewall/ipblock/edit 200 - 编辑防火墙IP封禁
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/rule/add 200 - 新增WAF规则
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/rule/detail 200 - 获取WAF规则详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/rule/list 200 - 获取WAF规则列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/rule/del 200 - 删除WAF规则
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/rule/edit 200 - 编辑WAF规则
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/rule/rulestatus 200 - 修改WAF规则状态
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/sensitive/add 200 - 新增敏感词
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/sensitive/detail 200 - 获取敏感词详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/sensitive/list 200 - 获取敏感词列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/sensitive/del 200 - 删除敏感词
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/sensitive/edit 200 - 编辑敏感词
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/cacherule/add 200 - 新增缓存规则
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/cacherule/detail 200 - 获取缓存规则详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/cacherule/list 200 - 获取缓存规则列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/cacherule/del 200 - 删除缓存规则
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/cacherule/edit 200 - 编辑缓存规则
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/loadbalance/add 200 - 新增负载均衡
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/loadbalance/detail 200 - 获取负载均衡详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/loadbalance/list 200 - 获取负载均衡列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/loadbalance/del 200 - 删除负载均衡
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/loadbalance/edit 200 - 编辑负载均衡
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/onekeymod/detail 200 - 获取一键修改详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/onekeymod/list 200 - 获取一键修改列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/onekeymod/del 200 - 删除一键修改
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/onekeymod/doModify 200 - 执行一键修改
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/onekeymod/restore 200 - 还原一键修改
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/task/add 200 - 新增任务
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/task/detail 200 - 获取任务详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/task/list 200 - 获取任务列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/task/del 200 - 删除任务
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/task/edit 200 - 编辑任务
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/task/manual_exec 200 - 手动执行任务
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/task/log 200 - 获取任务日志
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/task/log/clear 200 - 清空任务日志
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/dataretention/list 200 - 获取数据保留策略列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/dataretention/detail 200 - 获取数据保留策略详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/dataretention/edit 200 - 编辑数据保留策略
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/privateinfo/add 200 - 新增私有信息
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/privateinfo/detail 200 - 获取私有信息详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/privateinfo/list 200 - 获取私有信息列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/privateinfo/del 200 - 删除私有信息
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/privateinfo/edit 200 - 编辑私有信息
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/privategroup/add 200 - 新增私有分组
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/privategroup/detail 200 - 获取私有分组详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/privategroup/list 200 - 获取私有分组列表
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/privategroup/listbybelongcloud 200 - 按云获取私有分组列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/privategroup/del 200 - 删除私有分组
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/privategroup/edit 200 - 编辑私有分组
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/host/add 200 - 新增站点
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/host/detail 200 - 获取站点详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/host/list 200 - 获取站点列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/host/del 200 - 删除站点
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/host/edit 200 - 编辑站点
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/host/guardstatus 200 - 修改防护状态
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/host/startstatus 200 - 修改启动状态
|
||||
api_routes_test.go:368: ✓ POST /api/v1/sslconfig/add 200 - 新增SSL证书
|
||||
api_routes_test.go:368: ✓ GET /api/v1/sslconfig/detail 200 - 获取SSL证书详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/sslconfig/list 200 - 获取SSL证书列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/sslconfig/del 200 - 删除SSL证书
|
||||
api_routes_test.go:368: ✓ POST /api/v1/sslconfig/edit 200 - 编辑SSL证书
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/sslorder/add 200 - 新增SSL订单
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/sslorder/detail 200 - 获取SSL订单详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/sslorder/list 200 - 获取SSL订单列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/sslorder/del 200 - 删除SSL订单
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/sslorder/edit 200 - 编辑SSL订单
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/sslexpire/add 200 - 新增SSL到期监控
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/sslexpire/detail 200 - 获取SSL到期监控详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/sslexpire/list 200 - 获取SSL到期监控列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/sslexpire/del 200 - 删除SSL到期监控
|
||||
api_routes_test.go:368: ✓ POST /api/v1/wafhost/sslexpire/edit 200 - 编辑SSL到期监控
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/sslexpire/nowcheck 200 - 立即检测SSL到期
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafhost/sslexpire/sync_host 200 - 从站点同步SSL监控
|
||||
api_routes_test.go:368: ✓ POST /api/v1/tunnel/tunnel/add 200 - 新增隧道
|
||||
api_routes_test.go:368: ✓ GET /api/v1/tunnel/tunnel/detail 200 - 获取隧道详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/tunnel/tunnel/list 200 - 获取隧道列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/tunnel/tunnel/del 200 - 删除隧道
|
||||
api_routes_test.go:368: ✓ POST /api/v1/tunnel/tunnel/edit 200 - 编辑隧道
|
||||
api_routes_test.go:368: ✓ GET /api/v1/tunnel/tunnel/connections 200 - 获取隧道连接数
|
||||
api_routes_test.go:368: ✓ POST /api/v1/notify/channel/add 200 - 新增通知渠道
|
||||
api_routes_test.go:368: ✓ GET /api/v1/notify/channel/detail 200 - 获取通知渠道详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/notify/channel/list 200 - 获取通知渠道列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/notify/channel/del 200 - 删除通知渠道
|
||||
api_routes_test.go:368: ✓ POST /api/v1/notify/channel/edit 200 - 编辑通知渠道
|
||||
api_routes_test.go:368: ✓ POST /api/v1/notify/subscription/add 200 - 新增通知订阅
|
||||
api_routes_test.go:368: ✓ POST /api/v1/notify/subscription/list 200 - 获取通知订阅列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/notify/subscription/del 200 - 删除通知订阅
|
||||
api_routes_test.go:368: ✓ POST /api/v1/notify/log/list 200 - 获取通知日志列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/notify/log/detail 200 - 获取通知日志详情
|
||||
api_routes_test.go:368: ✓ GET /api/v1/notify/log/del 200 - 删除通知日志
|
||||
api_routes_test.go:368: ✓ POST /api/v1/vipconfig/updateIpWhitelist 200 - 更新管理IP白名单
|
||||
api_routes_test.go:368: ✓ GET /api/v1/vipconfig/getIpWhitelist 200 - 获取管理IP白名单
|
||||
api_routes_test.go:368: ✓ POST /api/v1/vipconfig/updateSslEnable 200 - 更新SSL启用状态
|
||||
api_routes_test.go:368: ✓ GET /api/v1/vipconfig/getSslStatus 200 - 获取SSL启用状态
|
||||
api_routes_test.go:368: ✓ GET /api/v1/vipconfig/getSecurityEntry 200 - 获取安全入口
|
||||
api_routes_test.go:368: ✓ POST /api/v1/vipconfig/updateSecurityEntry 200 - 更新安全入口
|
||||
api_routes_test.go:368: ✓ GET /api/v1/vipconfig/getNoticeTitle 200 - 获取通知标题前缀
|
||||
api_routes_test.go:368: ✓ POST /api/v1/vipconfig/updateNoticeTitle 200 - 更新通知标题前缀
|
||||
api_routes_test.go:368: ✓ POST /api/v1/systemconfig/list 200 - 获取系统配置列表
|
||||
api_routes_test.go:368: ✓ POST /api/v1/systemconfig/edit 200 - 更新系统配置
|
||||
api_routes_test.go:368: ✓ POST /api/v1/systemconfig/editByItem 200 - 通过item更新系统配置
|
||||
api_routes_test.go:368: ✓ GET /api/v1/monitor/system_info 200 - 获取系统监控信息
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafstatsumday 200 - 获取今日访问统计
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafstatsumdayrange 200 - 按日期范围统计访问量
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafstatsumdaytopiprange 200 - 统计攻击IP排行
|
||||
api_routes_test.go:368: ✓ GET /api/v1/statsysinfo 200 - 获取首页系统基本信息
|
||||
api_routes_test.go:368: ✓ GET /api/v1/statrumtimesysinfo 200 - 获取运行时系统基本信息
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafstatsiteoverview 200 - 站点综合概览统计
|
||||
api_routes_test.go:368: ✓ GET /api/v1/wafstatsitedetail 200 - 站点详情趋势查询
|
||||
api_routes_test.go:368: ✓ GET /api/v1/sysinfo/version 200 - 获取版本信息
|
||||
api_routes_test.go:368: ✓ GET /api/v1/sys_log/list 200 - 获取系统日志列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/sys_log/detail 200 - 获取系统日志详情
|
||||
api_routes_test.go:368: ✓ POST /api/v1/waflog/attack/list 200 - 获取攻击日志列表
|
||||
api_routes_test.go:368: ✓ GET /api/v1/waflog/attack/detail 200 - 获取攻击日志详情
|
||||
api_routes_test.go:368: ✓ GET /api/v1/logfilewrite/preview 200 - 预览日志文件
|
||||
api_routes_test.go:368: ✓ GET /api/v1/logfilewrite/currentfile 200 - 获取当前日志文件
|
||||
api_routes_test.go:368: ✓ GET /api/v1/logfilewrite/backupfiles 200 - 获取备份日志文件列表
|
||||
api_routes_test.go:368: ✓ POST /api/v1/logfilewrite/clear 200 - 清空日志文件
|
||||
api_routes_test.go:368: ✓ GET /api/v1/logfilewrite/variables 200 - 获取日志变量
|
||||
api_routes_test.go:368: ✓ GET /api/v1/resetWAF 200 - 重启WAF引擎
|
||||
api_routes_test.go:370: ──────────────────────────────────────────────────────────────────────────────────────────
|
||||
api_routes_test.go:371: 合计 151 条,通过 151 条,失败 0 条
|
||||
--- PASS: TestAllRoutes (1.73s)
|
||||
PASS
|
||||
ok SamWaf/test/apicheck 1.273s
|
||||
ok SamWaf/test/apicheck 1.756s
|
||||
```
|
||||
@@ -441,6 +441,10 @@ func (waf *WafEngine) ReLoadSensitive() {
|
||||
var customData map[string]interface{}
|
||||
customData = make(map[string]interface{})
|
||||
for _, sensitive := range waf.Sensitive {
|
||||
if len(sensitive.Content) == 0 {
|
||||
// ahocorasick 不支持空字符串模式,跳过以避免 index out of range [-1] panic
|
||||
continue
|
||||
}
|
||||
keywords = append(keywords, []rune(sensitive.Content))
|
||||
customData[sensitive.Content] = sensitive
|
||||
if sensitive.CheckDirection == "in" && waf.SensitiveDirectionMap["in"] == false {
|
||||
@@ -455,6 +459,9 @@ func (waf *WafEngine) ReLoadSensitive() {
|
||||
}
|
||||
}
|
||||
|
||||
if len(keywords) == 0 {
|
||||
return
|
||||
}
|
||||
m := new(goahocorasick.Machine)
|
||||
err := m.BuildByCustom(keywords, customData)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user