mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
Scanners report one advisory under different ids, such as a GHSA id from OSV and the CVE id from Trivy. Findings now carry an aliases list. The merge folds findings that share any id into one finding. A bypass for any id of a finding now covers it. Stored findings without aliases still load and match by their own id.
62 lines
2.3 KiB
Go
62 lines
2.3 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/lukaszraczylo/gohoarder/pkg/metadata"
|
|
)
|
|
|
|
func seedAliased(t *testing.T, a *App) {
|
|
t.Helper()
|
|
ctx := context.Background()
|
|
now := time.Now()
|
|
if err := a.metadata.SavePackage(ctx, &metadata.Package{
|
|
Registry: "npm", Name: "aliased", Version: "1.0.0", StorageKey: "npm/aliased", Size: 10, CachedAt: now, LastAccessed: now,
|
|
}); err != nil {
|
|
t.Fatalf("SavePackage: %v", err)
|
|
}
|
|
if err := a.metadata.SaveScanResult(ctx, &metadata.ScanResult{
|
|
Registry: "npm", PackageName: "aliased", PackageVersion: "1.0.0", Scanner: "osv", Status: metadata.ScanStatusVulnerable, ScannedAt: now,
|
|
VulnerabilityCount: 1,
|
|
Vulnerabilities: []metadata.Vulnerability{{
|
|
ID: "GHSA-xvch-5gv4-984h", Aliases: []string{"CVE-2021-44906"}, Severity: "critical", DetectedBy: []string{"osv"},
|
|
}},
|
|
}); err != nil {
|
|
t.Fatalf("SaveScanResult: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestDetailsShowAliasesAndHonourABypassOnAnAlias(t *testing.T) {
|
|
a, _ := newScanningApp(t)
|
|
a.config.Security.BlockOnSeverity = "critical"
|
|
seedAliased(t, a)
|
|
|
|
held, _ := getJSON(t, a, "/api/packages/npm/aliased/1.0.0/vulnerabilities")
|
|
if jsonAt(held, "decision", "verdict") != VerdictHeld {
|
|
t.Fatalf("verdict before the bypass = %v, want held", jsonAt(held, "decision", "verdict"))
|
|
}
|
|
if got, _ := jsonAt(held, "vulnerabilities", 0, "aliases").([]any); len(got) != 1 || got[0] != "CVE-2021-44906" {
|
|
t.Errorf("aliases = %v, want [CVE-2021-44906]", got)
|
|
}
|
|
|
|
if err := a.metadata.SaveCVEBypass(context.Background(), &metadata.CVEBypass{
|
|
Type: metadata.BypassTypeCVE, Target: "cve-2021-44906", Reason: "not reachable", CreatedBy: "alice",
|
|
Active: true, ExpiresAt: time.Now().Add(time.Hour),
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
waved, _ := getJSON(t, a, "/api/packages/npm/aliased/1.0.0/vulnerabilities")
|
|
if jsonAt(waved, "decision", "verdict") != VerdictBypassed {
|
|
t.Errorf("verdict with a CVE bypass = %v, want bypassed", jsonAt(waved, "decision", "verdict"))
|
|
}
|
|
if jsonAt(waved, "vulnerabilities", 0, "bypassed") != true {
|
|
t.Errorf("finding bypassed = %v, want true", jsonAt(waved, "vulnerabilities", 0, "bypassed"))
|
|
}
|
|
if jsonAt(waved, "vulnerabilities", 0, "bypass", "created_by") != "alice" {
|
|
t.Errorf("bypass = %v", jsonAt(waved, "vulnerabilities", 0, "bypass"))
|
|
}
|
|
}
|