mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-11-30 19:11:51 +08:00
feat: expose traffic IDs and filter finding statistics
This commit is contained in:
1 parent
459a484237
commit
8ee94f2215
14 files changed
+333
-70
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/Autumn-27/artex/db"
|
||||
)
|
||||
|
||||
func TestFindingStatsFiltersHTTP(t *testing.T) {
|
||||
s, recorded, request := trafficEvidenceServer(t)
|
||||
finding, err := s.m.pg.GetFinding(recorded.FindingID)
|
||||
if err != nil || finding == nil {
|
||||
t.Fatal("missing fixture finding", err)
|
||||
}
|
||||
filter := fmt.Sprintf("task_id=%d&severity=low&status=pending&vulnclass=TEST&q=bound&from=2000-01-01T00:00:00Z&to=2100-01-01T00:00:00Z", *finding.TaskID)
|
||||
for _, suffix := range []string{"", "&page=2&limit=1"} {
|
||||
r := request("GET", "/api/exploration/findings/stats?"+filter+suffix, "")
|
||||
var st db.FindingStats
|
||||
if r.Code != 200 || json.Unmarshal(r.Body.Bytes(), &st) != nil || st.Total != 1 || st.Low != 1 || st.High != 0 || st.Distinct == nil || st.Distinct.Total != 1 {
|
||||
t.Fatalf("status=%d stats=%s", r.Code, r.Body)
|
||||
}
|
||||
}
|
||||
r := request("GET", "/api/exploration/findings/stats?"+filter+"&asset_scope=__none__", "")
|
||||
if r.Code != 200 {
|
||||
t.Fatal(r.Code, r.Body)
|
||||
}
|
||||
r = request("GET", fmt.Sprintf("/api/exploration/findings/stats?task_id=%d&severity=high", *finding.TaskID), "")
|
||||
var st db.FindingStats
|
||||
if r.Code != 200 || json.Unmarshal(r.Body.Bytes(), &st) != nil || st.Total != 0 || st.Distinct.Total != 0 {
|
||||
t.Fatalf("empty filtered stats=%s", r.Body)
|
||||
}
|
||||
if len(st.Tasks) == 0 || len(st.VulnClasses) == 0 {
|
||||
t.Fatal("empty result removed filter choices")
|
||||
}
|
||||
}
|
||||
+2
-8
@@ -2337,15 +2337,9 @@ func (s *Server) resolveAssetIDs(ids []int64) map[int64]*db.Asset {
|
||||
return assets
|
||||
}
|
||||
|
||||
// findingStats serves the whole-table aggregates (stat cards + vuln-class filter)
|
||||
// for the paginated 发现 page.
|
||||
// findingStats serves filtered, pagination-independent counts and global options.
|
||||
func (s *Server) findingStats(w http.ResponseWriter, r *http.Request) {
|
||||
st, err := s.m.pg.FindingStats()
|
||||
if err != nil {
|
||||
writeErr(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
st.Distinct, err = s.m.pg.DistinctFindingStats("")
|
||||
st, err := s.m.pg.FilteredFindingStats(findingFilterFromQuery(r.URL.Query()))
|
||||
if err != nil {
|
||||
writeErr(w, 500, err.Error())
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user