Merge branch 'master' of https://git.zhangdeman.cn/zhangdeman/ginframework
Verify / verify (push) Canceled after 0s
Verify / verify (push) Canceled after 0s
This commit is contained in:
commit
72f80b6ca0
6 files changed
+307
-17
No files matched your search
@@ -8,6 +8,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/ginframework/logger/storagevalue"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -90,3 +92,33 @@ func TestDefaultPoliciesAndDisabledCollector(t *testing.T) {
|
||||
engine.GET("/api", func(ctx *gin.Context) { ctx.Status(204) })
|
||||
engine.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest("GET", "/api", nil))
|
||||
}
|
||||
|
||||
// TestDisabledSensitiveDetectionKeepsFixedPolicies 验证关闭敏感检测后正文保留原值,固定忽略的凭据头仍然隐藏。
|
||||
func TestDisabledSensitiveDetectionKeepsFixedPolicies(t *testing.T) {
|
||||
storagevalue.SetSensitiveDetection(false)
|
||||
defer storagevalue.SetSensitiveDetection(true)
|
||||
records := []Record{}
|
||||
engine := gin.New()
|
||||
engine.Use(New(Config{}, Options{
|
||||
RequestBody: func(*gin.Context) any { return map[string]any{"password": "private-password"} },
|
||||
Emit: func(_ *gin.Context, r Record) { records = append(records, r) },
|
||||
}))
|
||||
engine.POST("/api", func(ctx *gin.Context) { ctx.Status(204) })
|
||||
req := httptest.NewRequest("POST", "/api", strings.NewReader("{}"))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", "private-header")
|
||||
engine.ServeHTTP(httptest.NewRecorder(), req)
|
||||
if len(records) != 1 {
|
||||
t.Fatalf("records=%+v", records)
|
||||
}
|
||||
if records[0].Header.Get("Authorization") != "" {
|
||||
t.Fatal("fixed credential header policy was disabled")
|
||||
}
|
||||
body, err := json.Marshal(records[0].Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(body), "private-password") {
|
||||
t.Fatal("disabled detection still hid the body field")
|
||||
}
|
||||
}
|
||||