mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-28 06:46:26 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ada975065 | ||
|
|
b98e761c90 |
@@ -79,7 +79,7 @@ describe('TrendChart', () => {
|
||||
|
||||
expect(critical.attributes('aria-pressed')).toBe('true')
|
||||
expect(vulnerable()).toContain('with lines for critical')
|
||||
expect(wrapper.text()).toContain('Critical (highest severity)')
|
||||
expect(wrapper.text()).toContain('Packages with critical vulnerabilities')
|
||||
|
||||
await critical.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
type="multiple"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
aria-label="Add a line per highest severity"
|
||||
aria-label="Add a line per severity"
|
||||
>
|
||||
<ToggleGroupItem v-for="level in SEVERITY_LEVELS" :key="level" :value="level">
|
||||
{{ formatSeverityName(level) }}
|
||||
@@ -172,7 +172,7 @@ const vulnerableLabel = computed(() => {
|
||||
const vulnerableSeries = computed(() => [
|
||||
{ name: 'Vulnerable packages', data: values('vulnerable_packages'), tone: 'primary' as const },
|
||||
...SEVERITY_LEVELS.filter((level) => severities.value.includes(level)).map((level) => ({
|
||||
name: `${formatSeverityName(level)} (highest severity)`,
|
||||
name: `Packages with ${level} vulnerabilities`,
|
||||
data: values(level),
|
||||
tone: SEVERITY_LINE_TONES[level],
|
||||
})),
|
||||
|
||||
@@ -3,6 +3,7 @@ package gormstore
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/metadata"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -52,6 +53,19 @@ func checkSeverityFilter(t *testing.T, store *GORMStoreV2) {
|
||||
|
||||
require.Equal(t, []string{"crit"}, pick(metadata.GroupListOptions{Severities: []string{"critical"}, Query: "cr"}), "composes with search")
|
||||
require.Empty(t, pick(metadata.GroupListOptions{Severities: []string{"critical"}, Query: "high"}))
|
||||
|
||||
// The trend snapshot counts a package under every severity it holds, exactly as the filter selects it.
|
||||
snap, err := liveSnapshot(ctx, store.db, time.Now(), nil)
|
||||
require.NoError(t, err)
|
||||
for sev, got := range map[string]*int64{
|
||||
metadata.SeverityCritical: snap.Critical, metadata.SeverityHigh: snap.High,
|
||||
metadata.SeverityModerate: snap.Moderate, metadata.SeverityLow: snap.Low,
|
||||
} {
|
||||
require.EqualValues(t, len(pick(metadata.GroupListOptions{Severities: []string{sev}})), *got, sev)
|
||||
}
|
||||
require.EqualValues(t, 5, *snap.VulnerablePackages)
|
||||
require.EqualValues(t, len(pick(metadata.GroupListOptions{Severities: metadata.Severities})), *snap.VulnerablePackages)
|
||||
require.EqualValues(t, [4]int64{1, 2, 1, 2}, [4]int64{*snap.Critical, *snap.High, *snap.Moderate, *snap.Low}, "multi counts under high and low")
|
||||
}
|
||||
|
||||
func checkSeverityFilterStatementsAreConstant(t *testing.T, store *GORMStoreV2) {
|
||||
|
||||
@@ -39,14 +39,18 @@ func liveSnapshot(ctx context.Context, db *gorm.DB, at time.Time, blocked *int64
|
||||
Moderate int64
|
||||
Low int64
|
||||
}
|
||||
// A package counts under every severity its latest scan holds, as the severity filter selects it.
|
||||
scanned := func(col string) string {
|
||||
return "COALESCE(SUM(CASE WHEN security_scanned = ? AND id IN (" + latestScanWith(col+" > 0") + ") THEN 1 ELSE 0 END), 0)"
|
||||
}
|
||||
err := artifactPackages(db.WithContext(ctx).Model(&PackageModel{})).Select(`
|
||||
COUNT(*) AS total,
|
||||
COALESCE(SUM(size), 0) AS size,
|
||||
COALESCE(SUM(CASE WHEN vulnerability_count > 0 THEN 1 ELSE 0 END), 0) AS vulnerable,
|
||||
COALESCE(SUM(CASE WHEN highest_severity = 'critical' THEN 1 ELSE 0 END), 0) AS critical,
|
||||
COALESCE(SUM(CASE WHEN highest_severity = 'high' THEN 1 ELSE 0 END), 0) AS high,
|
||||
COALESCE(SUM(CASE WHEN highest_severity = 'medium' THEN 1 ELSE 0 END), 0) AS moderate,
|
||||
COALESCE(SUM(CASE WHEN highest_severity = 'low' THEN 1 ELSE 0 END), 0) AS low`).
|
||||
`+scanned("vuln_count")+` AS vulnerable,
|
||||
`+scanned(severityColumns[metadata.SeverityCritical])+` AS critical,
|
||||
`+scanned(severityColumns[metadata.SeverityHigh])+` AS high,
|
||||
`+scanned(severityColumns[metadata.SeverityModerate])+` AS moderate,
|
||||
`+scanned(severityColumns[metadata.SeverityLow])+` AS low`, true, true, true, true, true).
|
||||
Scan(&r).Error
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, errors.ErrCodeStorageFailure, "failed to read stats for snapshot")
|
||||
@@ -214,14 +218,17 @@ func (p backfillPackage) stateAtDayEnd(end time.Time, scans []backfillScan, with
|
||||
if sc.vulns > 0 {
|
||||
st.vulnerable = 1
|
||||
}
|
||||
switch {
|
||||
case sc.critical > 0:
|
||||
// Every severity the scan holds counts, as in liveSnapshot.
|
||||
if sc.critical > 0 {
|
||||
st.critical = 1
|
||||
case sc.high > 0:
|
||||
}
|
||||
if sc.high > 0 {
|
||||
st.high = 1
|
||||
case sc.moderate > 0:
|
||||
}
|
||||
if sc.moderate > 0 {
|
||||
st.moderate = 1
|
||||
case sc.lowCounts > 0:
|
||||
}
|
||||
if sc.lowCounts > 0 {
|
||||
st.low = 1
|
||||
}
|
||||
return st
|
||||
|
||||
@@ -106,11 +106,11 @@ func checkBackfillStatsSnapshots(t *testing.T, store *GORMStoreV2) {
|
||||
require.Equal(t, [5]int64{1, 0, 1, 0, 0}, vulns(day(4)))
|
||||
|
||||
require.EqualValues(t, 2, day(3).TotalPackages)
|
||||
require.Equal(t, [5]int64{2, 1, 1, 0, 0}, vulns(day(3)))
|
||||
require.Equal(t, [5]int64{2, 1, 1, 0, 1}, vulns(day(3)), "a counts under critical and low")
|
||||
|
||||
require.EqualValues(t, 1, day(2).TotalPackages, "b was deleted on day -2; early lived and died within it")
|
||||
require.EqualValues(t, 10, day(2).TotalSize)
|
||||
require.Equal(t, [5]int64{1, 1, 0, 0, 0}, vulns(day(2)))
|
||||
require.Equal(t, [5]int64{1, 1, 0, 0, 1}, vulns(day(2)))
|
||||
|
||||
require.EqualValues(t, 1, day(1).TotalPackages)
|
||||
require.Equal(t, [5]int64{0, 0, 0, 0, 0}, vulns(day(1)), "the clean rescan clears the vulnerability")
|
||||
|
||||
Reference in New Issue
Block a user