mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
fix(scanner): leave failed scanner results out of the merge
A scanner that returns a result with status error now counts as a failed scanner, like one that returns an error. Its result no longer joins the merge, and the manager counts it as an infrastructure failure or another failure by its cause. The merged status is error only when every applicable scanner failed. The fail_closed setting then decides that case as before. One scanner failing while another returns clean now reads clean.
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/config"
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/metadata"
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/scanner/scanerr"
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/uuid"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
@@ -140,9 +141,7 @@ func (s *Scanner) Scan(ctx context.Context, registry, packageName, version strin
|
||||
Scanner: s.Name(),
|
||||
ScannedAt: time.Now(),
|
||||
Status: metadata.ScanStatusError,
|
||||
Details: map[string]interface{}{
|
||||
"error": "scan timeout",
|
||||
},
|
||||
Details: scanerr.ErrorDetails("scan timeout", true),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package trivy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/config"
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/metadata"
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/scanner/scanerr"
|
||||
"github.com/lukaszraczylo/gohoarder/pkg/scanner/scannertest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestScanTimeoutIsAnInfrastructureErrorResult(t *testing.T) {
|
||||
scannertest.Script(t, "trivy", "exec sleep 5")
|
||||
|
||||
res, err := New(config.TrivyConfig{Timeout: 100 * time.Millisecond}).Scan(context.Background(), "npm", "p", "1", "/x")
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, metadata.ScanStatusError, res.Status)
|
||||
assert.Equal(t, true, res.Details[scanerr.DetailInfrastructure])
|
||||
}
|
||||
Reference in New Issue
Block a user