diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22da5eaa..661f9dfd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,13 +29,13 @@ jobs: - name: Run golangci-lint uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 with: - version: v2.13.2 + version: v2.15.0 # composition_lite.go is behind the lite build tags, which the run above # does not see; the house rules in .golangci.yml must cover it too. - name: Run golangci-lint under the lite build tags uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 with: - version: v2.13.2 + version: v2.15.0 args: --build-tags=bomly_external_syft,bomly_external_grype ./internal/composition/... skip-cache: true # The structural house rules (internal/tools/guardcheck) run as a vet diff --git a/Makefile b/Makefile index 276a6a53..717e6ab3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ BINARY_NAME=bomly LITE_BUILD_TAGS=bomly_external_syft,bomly_external_grype -GOLANGCI_LINT_VERSION=v2.13.2 +GOLANGCI_LINT_VERSION=v2.15.0 GO_LICENSES_VERSION=v1.6.0 GOPATH_BIN=$(shell go env GOPATH)/bin EXE_SUFFIX=$(if $(filter Windows_NT,$(OS)),.exe,) diff --git a/go.mod b/go.mod index ca6b2a0d..1cf8e892 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/bomly-dev/bomly-plugin-govulncheck-analyzer v0.4.0 github.com/bomly-dev/bomly-plugin-grype-matcher v0.7.0 github.com/bomly-dev/bomly-plugin-jsreach-analyzer v0.4.0 - github.com/bomly-dev/bomly-plugin-jvmreach-analyzer v0.4.0 + github.com/bomly-dev/bomly-plugin-jvmreach-analyzer v0.4.1 github.com/bomly-dev/bomly-plugin-osv-matcher v0.3.0 github.com/bomly-dev/bomly-plugin-pyreach-analyzer v0.4.0 github.com/bomly-dev/bomly-plugin-scorecard-matcher v0.3.0 diff --git a/go.sum b/go.sum index 8fb40313..a639fad6 100644 --- a/go.sum +++ b/go.sum @@ -253,8 +253,8 @@ github.com/bomly-dev/bomly-plugin-grype-matcher v0.7.0 h1:mp3ekZYtLWMfulmzPAWnTr github.com/bomly-dev/bomly-plugin-grype-matcher v0.7.0/go.mod h1:UD+Run063WieY49dM5iLYm24Krwy/AwvKUoAfLrusWY= github.com/bomly-dev/bomly-plugin-jsreach-analyzer v0.4.0 h1:3Fz4E0LLKUqFouQezqL5Te87H9dpo0dB3Qbl/uOqGiQ= github.com/bomly-dev/bomly-plugin-jsreach-analyzer v0.4.0/go.mod h1:x4r4Jw6MsWursNS0Gk/6JFjs7/EoFaXJD15j0DsVxvM= -github.com/bomly-dev/bomly-plugin-jvmreach-analyzer v0.4.0 h1:Lc6sI8bxVpSKluUyJogzsumlYtRZ41usNuIZ8UJCrv8= -github.com/bomly-dev/bomly-plugin-jvmreach-analyzer v0.4.0/go.mod h1:cWpKV6mblMGEe7c6jQZZ+dqJhEVhZ8ci1k5GULSaiss= +github.com/bomly-dev/bomly-plugin-jvmreach-analyzer v0.4.1 h1:ZLfQn2qABnGQj7zofaZ7Nd0KOKVCFY3EDFadv3+gwCc= +github.com/bomly-dev/bomly-plugin-jvmreach-analyzer v0.4.1/go.mod h1:0UkkLRHhXDgr6+9IwaQtSBCatpC3p5ddF6KHdYUWxNE= github.com/bomly-dev/bomly-plugin-osv-matcher v0.3.0 h1:OU0cHFxsoUZczUv9fEbOQM6A10awY1VOlmeIlTgDQhY= github.com/bomly-dev/bomly-plugin-osv-matcher v0.3.0/go.mod h1:psK1ra4DLJn2c+txMUhnTCVujZQTQ1N0LdhSsjcyKik= github.com/bomly-dev/bomly-plugin-pyreach-analyzer v0.4.0 h1:lljvmXB+zTgXw6S0eDIK1zZaPkKcsp+njD3IdorZLBU= diff --git a/internal/cli/root_cmd_test.go b/internal/cli/root_cmd_test.go index b8aa2bd2..f5ab34e9 100644 --- a/internal/cli/root_cmd_test.go +++ b/internal/cli/root_cmd_test.go @@ -16,6 +16,7 @@ import ( "github.com/bomly-dev/bomly-cli/internal/cli/exit" "github.com/bomly-dev/bomly-cli/internal/cli/render" syftdetector "github.com/bomly-dev/bomly-plugin-syft-detector/plugin" + "github.com/bomly-dev/bomly-sdk/model" "github.com/bomly-dev/bomly-sdk/system" "github.com/spf13/cobra" ) @@ -999,17 +1000,28 @@ func TestRoot_DiffCommand_AuditUsesResolvedGitRefs(t *testing.T) { "-o", "sarif=" + sarifPath, }) - if err := root.Execute(); err != nil { - t.Fatalf("root.Execute() error = %v; stderr=%s", err, stderr.String()) + // The matchers are live, so whether these real packages carry a failing + // advisory changes as advisories are published: zod 3.23.0 gained + // GHSA-mrhx-c7xc-m3w5 after this test was written. This test is about the + // refs the audit resolves, not the advisory set, so a policy-violation exit + // is accepted -- but only when the audit holds a failing finding to justify + // it. Any other error still fails. + execErr := root.Execute() + if execErr != nil && exit.Code(execErr) != exitCodePolicyViolation { + t.Fatalf("root.Execute() error = %v; stderr=%s", execErr, stderr.String()) } var payload map[string]any if err := json.Unmarshal(stdout.Bytes(), &payload); err != nil { t.Fatalf("unmarshal output: %v\n%s", err, stdout.String()) } - if payload["audit"] == nil { + audit, ok := payload["audit"].(map[string]any) + if !ok { t.Fatalf("expected audit payload, got %#v", payload) } + if failing := diffAuditFailingCount(audit); (execErr != nil) != (failing > 0) { + t.Fatalf("exit error = %v with %d failing audit findings; a policy-violation exit must match a failing finding", execErr, failing) + } summary, ok := payload["summary"].(map[string]any) if !ok { t.Fatalf("expected summary object, got %#v", payload["summary"]) @@ -1026,6 +1038,27 @@ func TestRoot_DiffCommand_AuditUsesResolvedGitRefs(t *testing.T) { } } +// exitCodePolicyViolation is the exit code a run returns when a finding meets +// the configured --fail-on threshold. +const exitCodePolicyViolation = 2 + +// diffAuditFailingCount counts the introduced and persisted findings of a +// diff's audit payload whose policy status fails the run -- the same findings +// diffPolicyExit counts. +func diffAuditFailingCount(audit map[string]any) int { + failing := 0 + for _, key := range []string{"introduced", "persisted"} { + findings, _ := audit[key].([]any) + for _, raw := range findings { + finding, _ := raw.(map[string]any) + if status, _ := finding["policy_status"].(string); status == "" || status == string(model.FindingPolicyStatusFail) { + failing++ + } + } + } + return failing +} + func TestRoot_ScanCommand_QuietSuppressesVerboseLogs(t *testing.T) { tempHome := t.TempDir() t.Setenv("HOME", tempHome)