Commit 182540fb authored by 赵嘉慧's avatar 赵嘉慧 Committed by zhujf1989
Browse files

fix audit event name

parent aeb5622a
Showing with 8 additions and 17 deletions
+8 -17
......@@ -221,11 +221,11 @@ func getEventName(c *gin.Context, e Event) *Event {
break
}
}
e.EventName = methodStr + objectType
objectType = objectType[:len(objectType)-1]
e.EventName = methodStr + strings.Title(objectType)
e.Description = e.Description + audit.ResourceType[objectType]
e.ResourceReports = []Resource{{
ResourceType: objectType[:len(objectType)-1],
ResourceType: objectType,
ResourceName: objectName,
}}
return &e
......
......@@ -69,36 +69,27 @@ func TestSendEvent(t *testing.T) {
}
func TestGetEventName(t *testing.T) {
// check post method
e := &Event{}
router := gin.New()
// check get method
router.GET("/api/v1/cube/proxy/clusters/:cluster/apis/apps/v1/namespaces/:namespace/statefulsets/:name", func(c *gin.Context) {
e = getEventName(c, *e)
return
})
_ = performRequest(router, http.MethodGet, "/api/v1/cube/proxy/clusters/pivot-cluster/apis/apps/v1/namespaces/dev/statefulsets/stsA", []byte(""))
if e.EventName != "[KubeCube] query statefulsets" {
t.Fail()
}
// check post method
router.POST("/api/v1/cube/proxy/clusters/:cluster/api/v1/namespaces/:namespace/services", func(c *gin.Context) {
e = getEventName(c, *e)
return
})
_ = performRequest(router, http.MethodPost, "/api/v1/cube/proxy/clusters/pivot-cluster/api/v1/namespaces/dev/services", []byte(""))
if e.EventName != "[KubeCube] create services" {
if e.EventName != "createService" {
t.Fail()
}
// check put method
e = &Event{}
router = gin.New()
router.PUT("/api/v1/cube/proxy/clusters/:cluster/api/v1/namespaces/:namespace/secrets/:name", func(c *gin.Context) {
e = getEventName(c, *e)
return
})
_ = performRequest(router, http.MethodPut, "/api/v1/cube/proxy/clusters/pivot-cluster/api/v1/namespaces/dev/secrets/secretA", []byte(""))
if e.EventName != "[KubeCube] update secrets" {
if e.EventName != "updateSecret" {
t.Fail()
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment