package apis import ( "net/http/httptest" "strings" "testing" "git.ilapage.cn/ila/yovision/Sense/server/app/sense/device/service/dto" "github.com/gin-gonic/gin" ) func TestBindStrictJSONRejectsUnknownDeviceField(t *testing.T) { gin.SetMode(gin.TestMode) recorder := httptest.NewRecorder() ctx, _ := gin.CreateTestContext(recorder) ctx.Request = httptest.NewRequest("POST", "/api/v1/devices", strings.NewReader(`{"name":"测试设备","location":"东门","modality":"video","capabilities":["video"],"password":"must-not-be-accepted"}`)) ctx.Request.Header.Set("Content-Type", "application/json") var req dto.CreateReq if err := bindStrictJSON(ctx, &req); err == nil { t.Fatal("unknown credential-like field was accepted") } }