Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions internal/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,23 @@ import (

// DetectorInfo is what the report says about each detector that ran.
type DetectorInfo struct {
ID string `json:"id"`
Title string `json:"title"`
CVEs []string `json:"cves,omitempty"`
Advisories []string `json:"advisories,omitempty"`
Data string `json:"data,omitempty"`
ID string `json:"id"`
Title string `json:"title"`
CVEs []string `json:"cves,omitempty"`
Advisories []string `json:"advisories,omitempty"`
Data string `json:"data,omitempty"`
Kinds []KindInfo `json:"kinds,omitempty"`
}

// KindInfo is one type of finding a detector reports, so a reader can rank a
// finding by its kind without a table of its own.
type KindInfo struct {
ID string `json:"id"`
Title string `json:"title"`
// Level is the SARIF level: error, warning or note.
Level string `json:"level"`
// Severity is the CVSS-style score ("9.2"), when the kind has one.
Severity string `json:"severity,omitempty"`
}

// Report is the whole run.
Expand All @@ -42,7 +54,11 @@ func New(tool, version string, dets []engine.Detector) *Report {
for _, d := range dets {
m := d.Manifest()
r.manifests = append(r.manifests, m)
r.Detectors = append(r.Detectors, DetectorInfo{ID: m.ID, Title: m.Title, CVEs: m.CVEs, Advisories: m.Advisories, Data: m.Data})
info := DetectorInfo{ID: m.ID, Title: m.Title, CVEs: m.CVEs, Advisories: m.Advisories, Data: m.Data}
for _, k := range m.Kinds {
info.Kinds = append(info.Kinds, KindInfo{ID: k.ID, Title: k.Title, Level: k.Level, Severity: k.SecuritySeverity})
}
r.Detectors = append(r.Detectors, info)
}
return r
}
Expand Down
40 changes: 39 additions & 1 deletion internal/report/report_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package report

import "testing"
import (
"bytes"
"encoding/json"
"reflect"
"testing"

"github.com/DefectDojo/earlylight/internal/engine"
)

func TestSafe(t *testing.T) {
for _, s := range []string{"\x1b[31mred", "a\nfake line", "\x9b31m", "bad\xffutf8", "tab\there"} {
Expand All @@ -14,3 +21,34 @@ func TestSafe(t *testing.T) {
}
}
}

type kindsDetector struct{}

func (kindsDetector) Manifest() engine.Manifest {
return engine.Manifest{ID: "t-kinds", Kinds: []engine.Kind{
{ID: "lib", Title: "Library", Level: "error", SecuritySeverity: "9.2"},
{ID: "pin", Title: "Pin not checked", Level: "note"},
}}
}
func (kindsDetector) Load() error { return nil }
func (kindsDetector) NewScan(engine.TargetKind) engine.Scan { return nil }

// Importers rank findings by kind. The JSON report carries each kind's level
// and score so they don't need a table that goes stale with every detector.
func TestJSONCarriesKinds(t *testing.T) {
r := New("earlylight", "test", []engine.Detector{kindsDetector{}})
var b bytes.Buffer
if err := JSON(&b, r); err != nil {
t.Fatal(err)
}
var got struct {
Detectors []DetectorInfo `json:"detectors"`
}
if err := json.Unmarshal(b.Bytes(), &got); err != nil {
t.Fatal(err)
}
want := []KindInfo{{ID: "lib", Title: "Library", Level: "error", Severity: "9.2"}, {ID: "pin", Title: "Pin not checked", Level: "note"}}
if len(got.Detectors) != 1 || !reflect.DeepEqual(got.Detectors[0].Kinds, want) {
t.Errorf("kinds = %+v, want %+v", got.Detectors, want)
}
}
Loading