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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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,)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
39 changes: 36 additions & 3 deletions internal/cli/root_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"])
Expand All @@ -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)
Expand Down
Loading