mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-30 06:57:10 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
933b5a75c0 | ||
|
|
f4cf96e1e8 | ||
|
|
aa8487ad87 |
+1
-1
@@ -2,7 +2,7 @@
|
||||
# Combines frontend serving and backend proxy (previously separate gateway)
|
||||
# EXPECTS: Pre-built frontend files in frontend/dist/ directory
|
||||
|
||||
FROM nginx:alpine
|
||||
FROM mirror.gcr.io/library/nginx:1.31.9-alpine@sha256:fb4658584bd9a916ffb6f6e365f97c25cfdb2923801f551ea08356e695f14ff7
|
||||
|
||||
# Install envsubst for runtime configuration
|
||||
RUN apk add --no-cache gettext
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
# This Dockerfile expects a PRE-BUILT binary from GoReleaser (no compilation)
|
||||
# GoReleaser injects the platform-specific binary automatically
|
||||
|
||||
FROM --platform=$TARGETPLATFORM alpine:latest
|
||||
FROM --platform=$TARGETPLATFORM mirror.gcr.io/library/alpine:3.24.4@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf
|
||||
|
||||
ARG TARGETARCH
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
# This Dockerfile expects a PRE-BUILT binary from GoReleaser (no compilation)
|
||||
# GoReleaser injects the platform-specific binary automatically
|
||||
|
||||
FROM --platform=$TARGETPLATFORM alpine:latest
|
||||
FROM --platform=$TARGETPLATFORM mirror.gcr.io/library/alpine:3.24.4@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf
|
||||
|
||||
ARG TARGETARCH
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
# This Dockerfile expects a PRE-BUILT binary from GoReleaser (no compilation)
|
||||
# GoReleaser injects the platform-specific binary automatically
|
||||
|
||||
FROM --platform=$TARGETPLATFORM alpine:latest
|
||||
FROM --platform=$TARGETPLATFORM mirror.gcr.io/library/alpine:3.24.4@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf
|
||||
|
||||
ARG TARGETARCH
|
||||
|
||||
|
||||
@@ -53,6 +53,22 @@ describe('useRealtimeStore', () => {
|
||||
expect(store.lastStats).toMatchObject({ total_packages: 42, total_size: 1024 })
|
||||
})
|
||||
|
||||
it('unwraps the server stats_update shape {stats, timestamp}', () => {
|
||||
const store = useRealtimeStore()
|
||||
store.ingest(
|
||||
makeEvent('stats_update', {
|
||||
stats: { total_packages: 1454, total_size: 980870617, total_downloads: 5376, scanned_packages: 1451 },
|
||||
timestamp: '2026-11-23T16:00:00Z',
|
||||
}),
|
||||
)
|
||||
expect(store.lastStats).toMatchObject({
|
||||
total_packages: 1454,
|
||||
total_size: 980870617,
|
||||
total_downloads: 5376,
|
||||
scanned_packages: 1451,
|
||||
})
|
||||
})
|
||||
|
||||
it('exposes filtered computed slices', () => {
|
||||
const store = useRealtimeStore()
|
||||
store.ingest(makeEvent('package_cached'))
|
||||
|
||||
@@ -55,7 +55,9 @@ export const useRealtimeStore = defineStore('realtime', () => {
|
||||
events.value.splice(0, events.value.length - EVENTS_CAP)
|
||||
}
|
||||
if (event.type === 'stats_update') {
|
||||
lastStats.value = event.payload as RealtimeStats
|
||||
// The server nests the counters under `stats`; reading the payload flat shows zeros.
|
||||
const nested = event.payload.stats
|
||||
lastStats.value = (nested && typeof nested === 'object' ? nested : event.payload) as RealtimeStats
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
@@ -42,14 +43,14 @@ func (a *App) handleVulnerabilities(c fiber.Ctx) error {
|
||||
Str("version", version).
|
||||
Msg("Getting vulnerabilities for package")
|
||||
|
||||
pkg, pkgErr := a.metadata.GetPackage(ctx, registry, name, version)
|
||||
key, pkg, pkgErr := a.resolvePackageKey(ctx, registry, name, version)
|
||||
releaseVersion := ""
|
||||
if pkgErr == nil && pkg != nil {
|
||||
releaseVersion = pkg.ReleaseVersion
|
||||
}
|
||||
|
||||
// Get scan result from metadata store
|
||||
scanResult, err := a.metadata.GetScanResult(ctx, registry, name, version)
|
||||
scanResult, err := a.metadata.GetScanResult(ctx, registry, key, version)
|
||||
if err != nil {
|
||||
if pkgErr != nil {
|
||||
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"error": "package not found"})
|
||||
@@ -169,3 +170,23 @@ func (a *App) handleVulnerabilities(c fiber.Ctx) error {
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
// goCacheKeyExts orders the Go cache files a module version is stored under; the
|
||||
// .zip carries the scan result.
|
||||
var goCacheKeyExts = []string{"zip", "mod", "info"}
|
||||
|
||||
// resolvePackageKey maps the name the dashboard shows to the stored row name.
|
||||
// Go rows are stored under cache keys (module/@v/version.ext), not the module path.
|
||||
func (a *App) resolvePackageKey(ctx context.Context, registry, name, version string) (string, *metadata.Package, error) {
|
||||
pkg, err := a.metadata.GetPackage(ctx, registry, name, version)
|
||||
if err == nil || registry != "go" || strings.Contains(name, "/@v/") {
|
||||
return name, pkg, err
|
||||
}
|
||||
for _, ext := range goCacheKeyExts {
|
||||
key := name + "/@v/" + version + "." + ext
|
||||
if p, kerr := a.metadata.GetPackage(ctx, registry, key, version); kerr == nil {
|
||||
return key, p, nil
|
||||
}
|
||||
}
|
||||
return name, nil, err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/metadata"
|
||||
)
|
||||
|
||||
// The list shows Go modules by module path, but rows are stored under cache keys.
|
||||
func TestGoVulnerabilityDetailsResolveCacheKeyNames(t *testing.T) {
|
||||
a := newTestApp(t, nil)
|
||||
ctx := context.Background()
|
||||
const module, version = "github.com/go-git/go-git/v5", "v5.3.0"
|
||||
for _, ext := range []string{"info", "mod", "zip"} {
|
||||
name := module + "/@v/" + version + "." + ext
|
||||
err := a.metadata.SavePackage(ctx, &metadata.Package{
|
||||
Registry: "go", Name: name, Version: version, StorageKey: "go/" + name,
|
||||
Size: 10, CachedAt: time.Now(), LastAccessed: time.Now(),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("SavePackage %s: %v", name, err)
|
||||
}
|
||||
}
|
||||
err := a.metadata.SaveScanResult(ctx, &metadata.ScanResult{
|
||||
Registry: "go", PackageName: module + "/@v/" + version + ".zip", PackageVersion: version,
|
||||
Scanner: "osv", Status: metadata.ScanStatusVulnerable, ScannedAt: time.Now(),
|
||||
Vulnerabilities: []metadata.Vulnerability{{ID: "GHSA-test", Severity: "critical"}},
|
||||
VulnerabilityCount: 1,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("SaveScanResult: %v", err)
|
||||
}
|
||||
|
||||
code, _, body := doRequest(t, a, "/api/packages/go/"+module+"/"+version+"/vulnerabilities", nil)
|
||||
if code != http.StatusOK {
|
||||
t.Fatalf("GET details = %d %s, want 200", code, body)
|
||||
}
|
||||
var out struct {
|
||||
Scanned bool `json:"scanned"`
|
||||
Count int `json:"vulnerability_count"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(body), &out); err != nil {
|
||||
t.Fatalf("decode %q: %v", body, err)
|
||||
}
|
||||
if !out.Scanned || out.Count != 1 {
|
||||
t.Errorf("details = %s, want the .zip scan with 1 vulnerability", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGoVulnerabilityDetailsMissingModuleIs404(t *testing.T) {
|
||||
a := newTestApp(t, nil)
|
||||
code, _, body := doRequest(t, a, "/api/packages/go/example.com/nope/v1.0.0/vulnerabilities", nil)
|
||||
if code != http.StatusNotFound {
|
||||
t.Errorf("GET missing = %d %s, want 404", code, body)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user