feat: Adding support for Windows testing (#3037)

Signed-off-by: Owen Rumney <owen.rumney@aquasec.com>
Signed-off-by: knqyf263 <knqyf263@gmail.com>
Co-authored-by: knqyf263 <knqyf263@gmail.com>
This commit is contained in:
Owen Rumneyandknqyf263 authored and GitHub committed 2022-12-22 22:54:18 +02:00
1 parent b00f3c60f6
commit 5190f9566b
75 files changed
+1413 -1423

No files matched your search

+1
View File
@@ -0,0 +1 @@
* text=auto eol=lf
+1
View File
@@ -58,6 +58,7 @@ jobs:
suse
photon
distroless
windows
ruby
php
+15 -11
View File
@@ -9,12 +9,13 @@ on:
- 'mkdocs.yml'
- 'LICENSE'
pull_request:
env:
TINYGO_VERSION: "0.25.0"
jobs:
test:
name: Test
runs-on: ubuntu-latest
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3
@@ -30,6 +31,7 @@ jobs:
echo "Run 'go mod tidy' and push it"
exit 1
fi
if: matrix.operating-system == 'ubuntu-latest'
- name: Lint
uses: golangci/golangci-lint-action@v3.3.0
@@ -37,11 +39,12 @@ jobs:
version: v1.49
args: --deadline=30m
skip-cache: true # https://github.com/golangci/golangci-lint-action/issues/244#issuecomment-1052197778
if: matrix.operating-system == 'ubuntu-latest'
- name: Install TinyGo
run: |
wget https://github.com/tinygo-org/tinygo/releases/download/v${TINYGO_VERSION}/tinygo_${TINYGO_VERSION}_amd64.deb
sudo dpkg -i tinygo_${TINYGO_VERSION}_amd64.deb
# Install tools
- uses: aquaproj/aqua-installer@v1.2.0
with:
aqua_version: v1.25.0
- name: Run unit tests
run: make test
@@ -73,12 +76,13 @@ jobs:
with:
go-version-file: go.mod
- name: Install TinyGo
run: |
wget https://github.com/tinygo-org/tinygo/releases/download/v${TINYGO_VERSION}/tinygo_${TINYGO_VERSION}_amd64.deb
sudo dpkg -i tinygo_${TINYGO_VERSION}_amd64.deb
# Install tools
- uses: aquaproj/aqua-installer@v1.1.2
with:
aqua_version: v1.25.0
- name: Run module integration tests
shell: bash
run: |
make test-module-integration
+8
View File
@@ -0,0 +1,8 @@
---
# aqua - Declarative CLI Version Manager
# https://aquaproj.github.io/
registries:
- type: standard
ref: v3.106.0 # renovate: depName=aquaproj/aqua-registry
packages:
- name: tinygo-org/tinygo@v0.26.0
+56 -59
View File
@@ -39,7 +39,7 @@ require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/protobuf v1.5.2
github.com/google/go-containerregistry v0.12.0
github.com/google/licenseclassifier/v2 v2.0.0-pre6
github.com/google/licenseclassifier/v2 v2.0.0
github.com/google/uuid v1.3.0
github.com/google/wire v0.5.0
github.com/hashicorp/go-getter v1.6.2
@@ -82,7 +82,40 @@ require (
)
require (
cloud.google.com/go v0.104.0 // indirect
cloud.google.com/go/compute v1.12.1 // indirect
cloud.google.com/go/compute/metadata v0.2.1 // indirect
cloud.google.com/go/iam v0.5.0 // indirect
cloud.google.com/go/storage v1.23.0 // indirect
github.com/Azure/azure-sdk-for-go v67.1.0+incompatible
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.28
github.com/Azure/go-autorest/autorest/adal v0.9.21
github.com/Azure/go-autorest/autorest/azure/auth v0.5.11
github.com/Azure/go-autorest/autorest/azure/cli v0.4.5 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/GoogleCloudPlatform/docker-credential-gcr v2.0.5+incompatible
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/squirrel v1.5.3 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/Microsoft/hcsshim v0.9.4 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.8 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.3 // indirect
@@ -133,64 +166,6 @@ require (
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.8 // indirect
github.com/aws/aws-sdk-go-v2/service/workspaces v1.23.0 // indirect
github.com/aws/smithy-go v1.13.4 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.3 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/spec v0.20.7 // indirect
github.com/go-openapi/validate v0.22.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/go-type-adapters v1.0.0 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/liamg/iamgo v0.0.9 // indirect
github.com/liamg/jfather v0.0.7 // indirect
github.com/liamg/memoryfs v1.4.3 // indirect
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 // indirect
github.com/microsoft/go-rustaudit v0.0.0-20220808201409-204dfee52032 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/shibumi/go-pathspec v1.3.0 // indirect
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
go.etcd.io/etcd/api/v3 v3.5.5 // indirect
go.mongodb.org/mongo-driver v1.10.0 // indirect
)
require (
cloud.google.com/go v0.104.0 // indirect
cloud.google.com/go/compute v1.12.1 // indirect
cloud.google.com/go/iam v0.5.0 // indirect
cloud.google.com/go/storage v1.23.0 // indirect
github.com/Azure/azure-sdk-for-go v67.1.0+incompatible
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.28
github.com/Azure/go-autorest/autorest/adal v0.9.21
github.com/Azure/go-autorest/autorest/azure/auth v0.5.11
github.com/Azure/go-autorest/autorest/azure/cli v0.4.5 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/GoogleCloudPlatform/docker-credential-gcr v2.0.5+incompatible
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/squirrel v1.5.3 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/Microsoft/hcsshim v0.9.4 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bmatcuk/doublestar v1.3.4 // indirect
@@ -215,6 +190,7 @@ require (
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
@@ -226,9 +202,14 @@ require (
github.com/go-git/go-git/v5 v5.4.2
github.com/go-gorp/gorp/v3 v3.0.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/spec v0.20.7 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/validate v0.22.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-yaml v1.8.2 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
@@ -241,16 +222,20 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.6.0 // indirect
github.com/googleapis/go-type-adapters v1.0.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.14.1 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.13 // indirect
@@ -267,13 +252,18 @@ require (
github.com/knqyf263/nested v0.0.1
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/liamg/iamgo v0.0.9 // indirect
github.com/liamg/jfather v0.0.7 // indirect
github.com/liamg/memoryfs v1.4.3 // indirect
github.com/lib/pq v1.10.6 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/microsoft/go-rustaudit v0.0.0-20220808201409-204dfee52032 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
@@ -292,14 +282,17 @@ require (
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc2
github.com/opencontainers/runc v1.1.3 // indirect
github.com/opencontainers/runtime-spec v1.0.3-0.20220311020903-6969a0a09ab1 // indirect
github.com/opencontainers/selinux v1.10.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/owenrumney/squealer v1.0.1-0.20220510063705-c0be93f0edea // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
@@ -314,6 +307,7 @@ require (
github.com/russross/blackfriday v1.6.0 // indirect
github.com/saracen/walker v0.0.0-20191201085201-324a081bae7e
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shibumi/go-pathspec v1.3.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spdx/tools-golang v0.3.0
@@ -322,6 +316,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/vbatts/tar-split v0.11.2 // indirect
github.com/xanzy/ssh-agent v0.3.0 // indirect
@@ -332,6 +327,8 @@ require (
github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 // indirect
github.com/zclconf/go-cty v1.10.0 // indirect
github.com/zclconf/go-cty-yaml v1.0.2 // indirect
go.etcd.io/etcd/api/v3 v3.5.5 // indirect
go.mongodb.org/mongo-driver v1.10.0 // indirect
go.opencensus.io v0.23.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
go.uber.org/atomic v1.10.0 // indirect
+2 -2
View File
@@ -869,8 +869,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/licenseclassifier/v2 v2.0.0-pre6 h1:ytJvfOEiKcN1m5vkAJXkK2olICdrXqwNKFkBpKQ5Q+I=
github.com/google/licenseclassifier/v2 v2.0.0-pre6/go.mod h1:cOjbdH0kyC9R22sdQbYsFkto4NGCAc+ZSwbeThazEtM=
github.com/google/licenseclassifier/v2 v2.0.0 h1:1Y57HHILNf4m0ABuMVb6xk4vAJYEUO0gDxNpog0pyeA=
github.com/google/licenseclassifier/v2 v2.0.0/go.mod h1:cOjbdH0kyC9R22sdQbYsFkto4NGCAc+ZSwbeThazEtM=
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
+8
View File
@@ -12,9 +12,13 @@ builds:
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
ignore:
- goos: windows
goarch: arm64
archives:
-
@@ -25,7 +29,11 @@ archives:
arm64: ARM64
darwin: macOS
linux: Linux
windows: Windows
files:
- README.md
- LICENSE
- contrib/*.tpl
format_overrides:
- goos: windows
format: zip
+15
View File
@@ -13,6 +13,7 @@ builds:
- darwin
- linux
- freebsd
- windows
goarch:
- amd64
- 386
@@ -30,6 +31,16 @@ builds:
goarch: arm
- goos: freebsd
goarch: arm64
- goos: windows
goarch: 386
- goos: windows
goarch: arm
- goos: windows
goarch: arm64
- goos: windows
goarch: s390x
- goos: windows
goarch: ppc64le
release:
extra_files:
@@ -59,6 +70,7 @@ nfpms:
netbsd: NetBSD
freebsd: FreeBSD
dragonfly: DragonFlyBSD
windows: Windows
contents:
- src: contrib/*.tpl
dst: /usr/local/share/trivy/templates
@@ -83,6 +95,9 @@ archives:
- README.md
- LICENSE
- contrib/*.tpl
format_overrides:
- goos: windows
format: zip
brews:
+2
View File
@@ -52,6 +52,7 @@ func (c *Cache) load() (*CacheData, error) {
if err != nil {
return nil, ErrCacheNotFound
}
defer func() { _ = m.Close() }()
var data CacheData
if err := json.NewDecoder(m).Decode(&data); err != nil {
@@ -127,5 +128,6 @@ func (c *Cache) AddServices(state *state.State, includedServices []string) error
if err != nil {
return err
}
defer func() { _ = f.Close() }()
return json.NewEncoder(f).Encode(data)
}
+1 -1
View File
@@ -6,11 +6,11 @@ import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/aquasecurity/trivy/pkg/compliance/report"
"github.com/aquasecurity/trivy/pkg/types"
"github.com/stretchr/testify/assert"
)
func TestJSONWriter_Write(t *testing.T) {
+8 -7
View File
@@ -3,10 +3,11 @@ package report_test
import (
"testing"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/aquasecurity/trivy/pkg/compliance/report"
"github.com/aquasecurity/trivy/pkg/types"
"github.com/stretchr/testify/assert"
"k8s.io/utils/pointer"
)
func TestBuildSummary(t *testing.T) {
@@ -59,13 +60,13 @@ func TestBuildSummary(t *testing.T) {
ID: "1.0",
Name: "Non-root containers",
Severity: "MEDIUM",
TotalFail: pointer.Int(1),
TotalFail: lo.ToPtr(1),
},
{
ID: "1.1",
Name: "Immutable container file systems",
Severity: "LOW",
TotalFail: pointer.Int(1),
TotalFail: lo.ToPtr(1),
},
},
},
@@ -126,19 +127,19 @@ func TestBuildSummary(t *testing.T) {
ID: "1.0",
Name: "Non-root containers",
Severity: "MEDIUM",
TotalFail: pointer.Int(1),
TotalFail: lo.ToPtr(1),
},
{
ID: "1.1",
Name: "Immutable container file systems",
Severity: "LOW",
TotalFail: pointer.Int(1),
TotalFail: lo.ToPtr(1),
},
{
ID: "1.2",
Name: "tzdata - new upstream version",
Severity: "LOW",
TotalFail: pointer.Int(1),
TotalFail: lo.ToPtr(1),
},
},
},
+2
View File
@@ -67,6 +67,8 @@ func TestTableWriter_Write(t *testing.T) {
require.NoError(t, err)
want, err := os.ReadFile(tt.want)
want = bytes.ReplaceAll(want, []byte("\r"), []byte(""))
require.NoError(t, err)
assert.Equal(t, string(want), buf.String())
+4
View File
@@ -32,3 +32,7 @@ func InitDB(t *testing.T, fixtureFiles []string) string {
return dir
}
func Close() error {
return db.Close()
}
+1
View File
@@ -363,6 +363,7 @@ func TestScanner_Detect(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dbtest.InitDB(t, tt.fixtures)
defer func() { _ = dbtest.Close() }()
s := redhat.NewScanner()
got, err := s.Detect(tt.args.osVer, nil, tt.args.pkgs)
+2 -4
View File
@@ -2,7 +2,6 @@ package apk
import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
@@ -11,16 +10,15 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/kylelemons/godebug/pretty"
"github.com/stretchr/testify/assert"
"github.com/aquasecurity/trivy/pkg/fanal/types"
)
func TestAnalyze(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
content, err := ioutil.ReadFile("testdata/history_v3.9.json")
content, err := os.ReadFile("testdata/history_v3.9.json")
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
@@ -2,7 +2,7 @@ package dockerfile
import (
"context"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@@ -26,33 +26,9 @@ func Test_dockerConfigAnalyzer_Analyze(t *testing.T) {
Files: map[types.HandlerType][]types.File{
types.MisconfPostHandler: {
{
Type: types.Dockerfile,
Path: "testdata/Dockerfile.deployment",
Content: []byte(`FROM foo
COPY . /
RUN echo hello
`),
},
},
},
},
},
{
name: "happy path with multi-stage",
inputFile: "testdata/Dockerfile.multistage",
want: &analyzer.AnalysisResult{
Files: map[types.HandlerType][]types.File{
types.MisconfPostHandler: {
{
Type: types.Dockerfile,
Path: "testdata/Dockerfile.multistage",
Content: []byte(`FROM foo AS build
COPY . /
RUN echo hello
FROM scratch
COPY --from=build /bar /bar
`),
Type: types.Dockerfile,
Path: "testdata/Dockerfile.deployment",
Content: []byte(`FROM scratch`),
},
},
},
@@ -62,15 +38,12 @@ COPY --from=build /bar /bar
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f, err := os.Open(tt.inputFile)
require.NoError(t, err)
defer f.Close()
r := strings.NewReader("FROM scratch")
a := dockerConfigAnalyzer{}
ctx := context.Background()
got, err := a.Analyze(ctx, analyzer.AnalysisInput{
FilePath: tt.inputFile,
Content: f,
Content: r,
})
if tt.wantErr != "" {
+7
View File
@@ -2,6 +2,7 @@ package helm
import (
"archive/tar"
"bytes"
"compress/gzip"
"context"
"errors"
@@ -28,7 +29,9 @@ const maxTarSize = 209_715_200 // 200MB
type helmConfigAnalyzer struct{}
func (a helmConfigAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
isAnArchive := false
if isArchive(input.FilePath) {
isAnArchive = true
if !isHelmChart(input.FilePath, input.Content) {
return nil, nil
}
@@ -42,6 +45,10 @@ func (a helmConfigAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisIn
if err != nil {
return nil, xerrors.Errorf("failed to read %s: %w", input.FilePath, err)
}
if !isAnArchive {
// if it's not an archive we need to remove the carriage returns
b = bytes.ReplaceAll(b, []byte("\r"), []byte(""))
}
return &analyzer.AnalysisResult{
Files: map[types.HandlerType][]types.File{
+130 -132
View File
@@ -3,6 +3,7 @@ package helm
import (
"context"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
@@ -30,13 +31,13 @@ func Test_helmConfigAnalyzer_Analyze(t *testing.T) {
namespaces: []string{"main"},
policyPaths: []string{"../testdata/kubernetes.rego"},
},
inputFile: "testdata/Chart.yaml",
inputFile: filepath.Join("testdata", "Chart.yaml"),
want: &analyzer.AnalysisResult{
Files: map[types.HandlerType][]types.File{
types.MisconfPostHandler: {
{
Type: "helm",
Path: "testdata/Chart.yaml",
Path: filepath.Join("testdata", "Chart.yaml"),
Content: []byte(`apiVersion: v2
name: testchart
description: A Helm chart for Kubernetes
@@ -73,13 +74,13 @@ appVersion: "1.16.0"
namespaces: []string{"main"},
policyPaths: []string{"../testdata/kubernetes.rego"},
},
inputFile: "testdata/values.yaml",
inputFile: filepath.Join("testdata", "values.yaml"),
want: &analyzer.AnalysisResult{
Files: map[types.HandlerType][]types.File{
types.MisconfPostHandler: {
{
Type: "helm",
Path: "testdata/values.yaml",
Path: filepath.Join("testdata", "values.yaml"),
Content: []byte(`# Default values for testchart.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
@@ -178,140 +179,137 @@ affinity: {}
namespaces: []string{"main"},
policyPaths: []string{"../testdata/kubernetes.rego"},
},
inputFile: "testdata/testchart.tgz",
inputFile: filepath.Join("testdata", "testchart.tgz"),
want: &analyzer.AnalysisResult{
Files: map[types.HandlerType][]types.File{
types.MisconfPostHandler: {
{
Type: "helm",
Path: "testdata/testchart.tgz",
Path: filepath.Join("testdata", "testchart.tgz"),
Content: []uint8{
0x1f, 0x8b, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0xed, 0x58, 0x5b,
0x6f, 0xdb, 0x36, 0x14, 0xce, 0xb3, 0x7e, 0x5, 0xd7, 0x3c, 0xa4, 0x2d, 0x1a, 0xd9,
0x4a, 0xec, 0xa4, 0xf0, 0x5b, 0x90, 0xec, 0x12, 0x2c, 0x69, 0x83, 0xa6, 0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9, 0xa8, 0xf8, 0xe,
0x2d, 0xe6, 0x73, 0x6f, 0x24, 0xbc, 0xf6, 0xc6, 0xc1, 0xcd, 0xd0, 0xe1, 0x83, 0xe9,
0x53, 0x4a, 0xfd, 0x2a, 0xb6, 0x11, 0x47, 0x2d, 0x4, 0x7, 0xfc, 0x66, 0xed, 0x0, 0x49,
0x4a, 0xb5, 0xdd, 0x4e, 0x85, 0x3f, 0xbe, 0x78, 0xf3, 0x86, 0xfe, 0x51, 0x79, 0x1f,
0x42, 0xf3, 0x42, 0x40, 0x9, 0x84, 0x29, 0xfa, 0xd, 0xa5, 0x28, 0xf1, 0x8e, 0x68, 0xe7,
0x81, 0xff, 0xfd, 0x98, 0x89, 0xc6, 0x58, 0x77, 0x29, 0x68, 0x4b, 0x36, 0x36, 0x96,
0x2f, 0x6f, 0x14, 0x15, 0xc1, 0x58, 0xcf, 0x10, 0xe3, 0x9, 0x9f, 0x4c, 0xe0, 0x35, 0xbf,
0x8, 0xaf, 0xbf, 0x75, 0x77, 0xef, 0xa0, 0x83, 0xe, 0x3a, 0xe8, 0xa0, 0x83, 0xe, 0x3a,
0xe8, 0xa0, 0x83, 0xe, 0x3a, 0xe8, 0xa0, 0x83, 0xe, 0x3a, 0xd8, 0xda, 0xfa, 0x17, 0xe2,
0x8a, 0xf9, 0x39, 0x0, 0x28, 0x0, 0x0,
},
},
},
@@ -324,7 +322,7 @@ affinity: {}
namespaces: []string{"main"},
policyPaths: []string{"../testdata/kubernetes.rego"},
},
inputFile: "testdata/nope.tgz",
inputFile: filepath.Join("testdata", "nope.tgz"),
want: nil,
},
}
@@ -396,17 +394,17 @@ func Test_helmConfigAnalyzer_Required(t *testing.T) {
},
{
name: "testchart.tgz",
filePath: "testdata/testchart.tgz",
filePath: filepath.Join("testdata", "testchart.tgz"),
want: true,
},
{
name: "testchart.tar.gz",
filePath: "testdata/testchart.tar.gz",
filePath: filepath.Join("testdata", "testchart.tar.gz"),
want: true,
},
{
name: "nope.tgz",
filePath: "testdata/nope.tgz",
filePath: filepath.Join("testdata", "nope.tgz"),
want: true, // its a tarball after all
},
}
+9 -102
View File
@@ -2,7 +2,7 @@ package json
import (
"context"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@@ -13,111 +13,22 @@ import (
)
func Test_jsonConfigAnalyzer_Analyze(t *testing.T) {
type args struct {
namespaces []string
policyPaths []string
}
tests := []struct {
name string
args args
inputFile string
want *analyzer.AnalysisResult
wantErr string
}{
{
name: "happy path",
args: args{
namespaces: []string{"main"},
policyPaths: []string{"../testdata/kubernetes.rego"},
},
inputFile: "testdata/deployment.json",
name: "happy path",
inputFile: "test.json",
want: &analyzer.AnalysisResult{
Files: map[types.HandlerType][]types.File{
types.MisconfPostHandler: {
{
Type: "json",
Path: "testdata/deployment.json",
Content: []byte(`{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "hello-kubernetes"
},
"spec": {
"replicas": 3
}
}
`),
},
},
},
},
},
{
name: "deny",
args: args{
namespaces: []string{"main"},
policyPaths: []string{"../testdata/kubernetes.rego"},
},
inputFile: "testdata/deployment_deny.json",
want: &analyzer.AnalysisResult{
Files: map[types.HandlerType][]types.File{
types.MisconfPostHandler: {
{
Type: "json",
Path: "testdata/deployment_deny.json",
Content: []byte(`{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "hello-kubernetes"
},
"spec": {
"replicas": 4
}
}
`),
},
},
},
},
},
{
name: "json array",
args: args{
namespaces: []string{"main"},
policyPaths: []string{"../testdata/kubernetes.rego"},
},
inputFile: "testdata/array.json",
want: &analyzer.AnalysisResult{
Files: map[types.HandlerType][]types.File{
types.MisconfPostHandler: {
{
Type: "json",
Path: "testdata/array.json",
Content: []byte(`[
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "hello-kubernetes"
},
"spec": {
"replicas": 4
}
},
{
"apiVersion": "apps/v2",
"kind": "Deployment",
"metadata": {
"name": "hello-kubernetes"
},
"spec": {
"replicas": 5
}
}
]
`),
Type: "json",
Path: "test.json",
Content: []byte(`{}`),
},
},
},
@@ -127,16 +38,12 @@ func Test_jsonConfigAnalyzer_Analyze(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f, err := os.Open(tt.inputFile)
require.NoError(t, err)
defer f.Close()
r := strings.NewReader("{}")
s := jsonConfigAnalyzer{}
ctx := context.Background()
got, err := s.Analyze(ctx, analyzer.AnalysisInput{
got, err := s.Analyze(context.Background(), analyzer.AnalysisInput{
FilePath: tt.inputFile,
Content: f,
Content: r,
})
if tt.wantErr != "" {
+8 -131
View File
@@ -2,7 +2,7 @@ package yaml
import (
"context"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@@ -13,142 +13,22 @@ import (
)
func Test_yamlConfigAnalyzer_Analyze(t *testing.T) {
type args struct {
namespaces []string
policyPaths []string
}
tests := []struct {
name string
args args
inputFile string
want *analyzer.AnalysisResult
wantErr string
}{
{
name: "happy path",
args: args{
namespaces: []string{"main"},
policyPaths: []string{"../testdata/kubernetes.rego"},
},
inputFile: "testdata/deployment.yaml",
name: "happy path",
inputFile: "test.yaml",
want: &analyzer.AnalysisResult{
Files: map[types.HandlerType][]types.File{
types.MisconfPostHandler: {
{
Type: "yaml",
Path: "testdata/deployment.yaml",
Content: []byte(`apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kubernetes
spec:
replicas: 3
`),
},
},
},
},
},
{
name: "deny",
args: args{
namespaces: []string{"main"},
policyPaths: []string{"../testdata/kubernetes.rego"},
},
inputFile: "testdata/deployment_deny.yaml",
want: &analyzer.AnalysisResult{
OS: (*types.OS)(nil),
PackageInfos: []types.PackageInfo(nil),
Applications: []types.Application(nil),
Files: map[types.HandlerType][]types.File{
types.MisconfPostHandler: {
{
Type: "yaml",
Path: "testdata/deployment_deny.yaml",
Content: []byte(`apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kubernetes
spec:
replicas: 4
`),
},
},
},
},
},
{
name: "happy path using anchors",
args: args{
namespaces: []string{"main"},
policyPaths: []string{"testdata/deny.rego"},
},
inputFile: "testdata/anchor.yaml",
want: &analyzer.AnalysisResult{
OS: (*types.OS)(nil),
PackageInfos: []types.PackageInfo(nil),
Applications: []types.Application(nil),
Files: map[types.HandlerType][]types.File{
types.MisconfPostHandler: {
{
Type: "yaml",
Path: "testdata/anchor.yaml",
Content: []byte(`default: &default
line: single line
john: &J
john_name: john
fred: &F
fred_name: fred
main:
<<: *default
name:
<<: [*J, *F]
comment: |
multi
line
`),
},
},
},
},
},
{
name: "multiple yaml",
args: args{
namespaces: []string{"main"},
policyPaths: []string{"../testdata/kubernetes.rego"},
},
inputFile: "testdata/multiple.yaml",
want: &analyzer.AnalysisResult{
OS: (*types.OS)(nil),
PackageInfos: []types.PackageInfo(nil),
Applications: []types.Application(nil),
Files: map[types.HandlerType][]types.File{
types.MisconfPostHandler: {
{
Type: "yaml",
Path: "testdata/multiple.yaml",
Content: []byte(`apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kubernetes
spec:
replicas: 4
---
apiVersion: v1
kind: Service
metadata:
name: hello-kubernetes
spec:
ports:
- protocol: TCP
port: 80
targetPort: 8080
`),
Type: "yaml",
Path: "test.yaml",
Content: []byte(`- abc`),
},
},
},
@@ -157,15 +37,12 @@ spec:
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f, err := os.Open(tt.inputFile)
require.NoError(t, err)
defer f.Close()
r := strings.NewReader("- abc")
a := yamlConfigAnalyzer{}
ctx := context.Background()
got, err := a.Analyze(ctx, analyzer.AnalysisInput{
FilePath: tt.inputFile,
Content: f,
Content: r,
})
if tt.wantErr != "" {
@@ -3,8 +3,11 @@ package binary
import (
"context"
"os"
"runtime"
"testing"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -73,8 +76,8 @@ func Test_gobinaryLibraryAnalyzer_Required(t *testing.T) {
want bool
}{
{
name: "file perm 0755",
filePath: "testdata/0755",
name: "executable file",
filePath: lo.Ternary(runtime.GOOS == "windows", "testdata/binary.exe", "testdata/0755"),
want: true,
},
{
@@ -0,0 +1 @@
exe
Whitespace-only changes.
@@ -34,8 +34,8 @@ func (a gradleLockAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisIn
return res, nil
}
func (a gradleLockAnalyzer) Required(_ string, fileInfo os.FileInfo) bool {
return strings.HasSuffix(fileInfo.Name(), fileNameSuffix)
func (a gradleLockAnalyzer) Required(filePath string, _ os.FileInfo) bool {
return strings.HasSuffix(filePath, fileNameSuffix)
}
func (a gradleLockAnalyzer) Type() analyzer.Type {
@@ -2,7 +2,6 @@ package gradle
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
@@ -87,20 +86,8 @@ func Test_nugetLibraryAnalyzer_Required(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := os.MkdirAll(filepath.Dir(tt.filePath), 0700)
assert.NoError(t, err)
_, err = os.Create(tt.filePath)
assert.NoError(t, err)
defer func() {
err = os.RemoveAll(filepath.Dir(tt.filePath))
assert.NoError(t, err)
}()
fileInfo, err := os.Stat(tt.filePath)
assert.NoError(t, err)
a := gradleLockAnalyzer{}
got := a.Required("", fileInfo)
got := a.Required(tt.filePath, nil)
assert.Equal(t, tt.want, got)
})
}
@@ -28,23 +28,46 @@ func Test_javaLibraryAnalyzer_Analyze(t *testing.T) {
Type: types.Jar,
FilePath: "testdata/test.war",
Libraries: []types.Package{
{Name: "org.glassfish:javax.el", FilePath: "testdata/test.war", Version: "3.0.0"},
{
Name: "com.fasterxml.jackson.core:jackson-databind", FilePath: "testdata/test.war",
Version: "2.9.10.6",
Name: "org.glassfish:javax.el",
FilePath: "testdata/test.war",
Version: "3.0.0",
},
{
Name: "com.fasterxml.jackson.core:jackson-annotations", FilePath: "testdata/test.war",
Version: "2.9.10",
Name: "com.fasterxml.jackson.core:jackson-databind",
FilePath: "testdata/test.war",
Version: "2.9.10.6",
},
{
Name: "com.fasterxml.jackson.core:jackson-core", FilePath: "testdata/test.war",
Version: "2.9.10",
Name: "com.fasterxml.jackson.core:jackson-annotations",
FilePath: "testdata/test.war",
Version: "2.9.10",
},
{
Name: "com.fasterxml.jackson.core:jackson-core",
FilePath: "testdata/test.war",
Version: "2.9.10",
},
{
Name: "org.slf4j:slf4j-api",
FilePath: "testdata/test.war",
Version: "1.7.30",
},
{
Name: "com.cronutils:cron-utils",
FilePath: "testdata/test.war",
Version: "9.1.2",
},
{
Name: "org.apache.commons:commons-lang3",
FilePath: "testdata/test.war",
Version: "3.11",
},
{
Name: "com.example:web-app",
FilePath: "testdata/test.war",
Version: "1.0-SNAPSHOT",
},
{Name: "org.slf4j:slf4j-api", FilePath: "testdata/test.war", Version: "1.7.30"},
{Name: "com.cronutils:cron-utils", FilePath: "testdata/test.war", Version: "9.1.2"},
{Name: "org.apache.commons:commons-lang3", FilePath: "testdata/test.war", Version: "3.11"},
{Name: "com.example:web-app", FilePath: "testdata/test.war", Version: "1.0-SNAPSHOT"},
},
},
},
@@ -60,8 +83,9 @@ func Test_javaLibraryAnalyzer_Analyze(t *testing.T) {
FilePath: "testdata/test.par",
Libraries: []types.Package{
{
Name: "com.fasterxml.jackson.core:jackson-core", FilePath: "testdata/test.par",
Version: "2.9.10",
Name: "com.fasterxml.jackson.core:jackson-core",
FilePath: "testdata/test.par",
Version: "2.9.10",
},
},
},
@@ -121,14 +121,14 @@ func Test_npmLibraryAnalyzer_Analyze(t *testing.T) {
{
name: "sad path",
inputFile: "testdata/wrong.json",
wantErr: "unable to parse testdata/wrong.json",
wantErr: "unable to parse",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f, err := os.Open(tt.inputFile)
require.NoError(t, err)
defer f.Close()
defer func() { _ = f.Close() }()
a := npmLibraryAnalyzer{}
got, err := a.Analyze(context.Background(), analyzer.AnalysisInput{
@@ -42,7 +42,7 @@ func Test_nodePkgLibraryAnalyzer_Analyze(t *testing.T) {
{
name: "sad path",
inputFile: "testdata/noname.json",
wantErr: "unable to parse testdata/noname.json",
wantErr: "unable to parse",
},
}
for _, tt := range tests {
@@ -5,10 +5,11 @@ import (
"os"
"testing"
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
"github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
"github.com/aquasecurity/trivy/pkg/fanal/types"
)
func Test_yarnLibraryAnalyzer_Analyze(t *testing.T) {
@@ -3,8 +3,10 @@ package binary
import (
"context"
"os"
"runtime"
"testing"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -33,7 +35,12 @@ func Test_rustBinaryLibraryAnalyzer_Analyze(t *testing.T) {
Version: "0.1.0",
DependsOn: []string{"library_crate@0.1.0"},
},
{ID: "library_crate@0.1.0", Name: "library_crate", Version: "0.1.0", Indirect: true},
{
ID: "library_crate@0.1.0",
Name: "library_crate",
Version: "0.1.0",
Indirect: true,
},
},
},
},
@@ -74,8 +81,8 @@ func Test_rustBinaryLibraryAnalyzer_Required(t *testing.T) {
want bool
}{
{
name: "file perm 0755",
filePath: "testdata/0755",
name: "executable file",
filePath: lo.Ternary(runtime.GOOS == "windows", "testdata/binary.exe", "testdata/0755"),
want: true,
},
{
@@ -0,0 +1 @@
exe
+1 -10
View File
@@ -2,7 +2,6 @@ package licensing
import (
"context"
"fmt"
"io"
"math"
"os"
@@ -64,15 +63,7 @@ func (a licenseFileAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisI
return nil, nil
}
filePath := input.FilePath
// Files extracted from the image have an empty input.Dir.
// Also, paths to these files do not have "/" prefix.
// We need to add a "/" prefix to properly filter paths from the config file.
if input.Dir == "" { // add leading `/` for files extracted from image
filePath = fmt.Sprintf("/%s", filePath)
}
lf, err := licensing.Classify(filePath, input.Content)
lf, err := licensing.Classify(input.FilePath, input.Content)
if err != nil {
return nil, xerrors.Errorf("license classification error: %w", err)
} else if len(lf.Findings) == 0 {
+1 -1
View File
@@ -25,7 +25,7 @@ func Test_licenseAnalyzer_Analyze(t *testing.T) {
Licenses: []types.LicenseFile{
{
Type: types.LicenseTypeHeader,
FilePath: "/testdata/licensed.c",
FilePath: "testdata/licensed.c",
Findings: []types.LicenseFinding{
{
Name: "AGPL-3.0",
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"path"
"sort"
"strings"
@@ -86,7 +86,7 @@ func (a alpinePkgAnalyzer) parseApkInfo(scanner *bufio.Scanner) ([]types.Package
case "F:":
dir = line[2:]
case "R:":
installedFiles = append(installedFiles, filepath.Join(dir, line[2:]))
installedFiles = append(installedFiles, path.Join(dir, line[2:]))
case "p:": // provides (corresponds to provides in PKGINFO, concatenated by spaces into a single line)
a.parseProvides(line, pkg.ID, provides)
case "D:": // dependencies (corresponds to depend in PKGINFO, concatenated by spaces into a single line)
+3
View File
@@ -1,6 +1,7 @@
package secret
import (
"bytes"
"context"
"fmt"
"io"
@@ -87,6 +88,8 @@ func (a *SecretAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput
return nil, xerrors.Errorf("read error %s: %w", input.FilePath, err)
}
content = bytes.ReplaceAll(content, []byte("\r"), []byte(""))
filePath := input.FilePath
// Files extracted from the image have an empty input.Dir.
// Also, paths to these files do not have "/" prefix.
+72 -9
View File
@@ -201,9 +201,30 @@ func TestArtifact_Inspect(t *testing.T) {
Packages: alpinePkgs,
},
},
Applications: []types.Application(nil),
OpaqueDirs: []string(nil),
WhiteoutFiles: []string(nil),
Licenses: []types.LicenseFile{
{
Type: "header",
FilePath: "etc/ssl/misc/CA.pl",
Findings: []types.LicenseFinding{
{
Name: "OpenSSL",
Confidence: 1,
Link: "https://spdx.org/licenses/OpenSSL.html",
},
},
},
{
Type: "header",
FilePath: "etc/ssl/misc/tsget.pl",
Findings: []types.LicenseFinding{
{
Name: "OpenSSL",
Confidence: 1,
Link: "https://spdx.org/licenses/OpenSSL.html",
},
},
},
},
},
},
Returns: cache.ArtifactCachePutBlobReturns{},
@@ -856,9 +877,30 @@ func TestArtifact_Inspect(t *testing.T) {
Packages: alpinePkgs,
},
},
Applications: []types.Application(nil),
OpaqueDirs: []string(nil),
WhiteoutFiles: []string(nil),
Licenses: []types.LicenseFile{
{
Type: "header",
FilePath: "etc/ssl/misc/CA.pl",
Findings: []types.LicenseFinding{
{
Name: "OpenSSL",
Confidence: 1,
Link: "https://spdx.org/licenses/OpenSSL.html",
},
},
},
{
Type: "header",
FilePath: "etc/ssl/misc/tsget.pl",
Findings: []types.LicenseFinding{
{
Name: "OpenSSL",
Confidence: 1,
Link: "https://spdx.org/licenses/OpenSSL.html",
},
},
},
},
},
},
Returns: cache.ArtifactCachePutBlobReturns{
@@ -904,9 +946,30 @@ func TestArtifact_Inspect(t *testing.T) {
Packages: alpinePkgs,
},
},
Applications: []types.Application(nil),
OpaqueDirs: []string(nil),
WhiteoutFiles: []string(nil),
Licenses: []types.LicenseFile{
{
Type: "header",
FilePath: "etc/ssl/misc/CA.pl",
Findings: []types.LicenseFinding{
{
Name: "OpenSSL",
Confidence: 1,
Link: "https://spdx.org/licenses/OpenSSL.html",
},
},
},
{
Type: "header",
FilePath: "etc/ssl/misc/tsget.pl",
Findings: []types.LicenseFinding{
{
Name: "OpenSSL",
Confidence: 1,
Link: "https://spdx.org/licenses/OpenSSL.html",
},
},
},
},
},
},
Returns: cache.ArtifactCachePutBlobReturns{},
+5 -1
View File
@@ -91,6 +91,9 @@ func (a Artifact) Inspect(ctx context.Context) (types.ArtifactReference, error)
return xerrors.Errorf("filepath rel (%s): %w", filePath, err)
}
// For Windows
filePath = filepath.ToSlash(filePath)
opts := analyzer.AnalysisOptions{Offline: a.artifactOption.Offline}
if err = a.analyzer.AnalyzeFile(ctx, &wg, limit, result, directory, filePath, info, opener, nil, opts); err != nil {
return xerrors.Errorf("analyze file (%s): %w", filePath, err)
@@ -137,7 +140,8 @@ func (a Artifact) Inspect(ctx context.Context) (types.ArtifactReference, error)
if err == nil && string(b) != "" {
hostName = strings.TrimSpace(string(b))
} else {
hostName = a.rootPath
// To slash for Windows
hostName = filepath.ToSlash(a.rootPath)
}
return types.ArtifactReference{
File diff suppressed because it is too large. Load diff
@@ -1,57 +1,59 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_ZRS",
"Premium_LRS"
],
"metadata": {
"description": "Storage Account type"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_ZRS",
"Premium_LRS"
],
"metadata": {
"description": "Storage Account type"
}
},
"variables": {
"storageAccountName": "[concat('store', uniquestring(resourceGroup().id))]"
},
"resources": [{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"apiVersion": "2018-07-01",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "StorageV2",
"properties": {}
},
{
"type": "Microsoft.Storage/storageAccounts",
"name": "bucket2",
"location": "[parameters('location')]",
"apiVersion": "2018-07-01",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "StorageV2",
"properties": {}
}],
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[variables('storageAccountName')]"
}
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"storageAccountName": "[concat('store', uniquestring(resourceGroup().id))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"apiVersion": "2018-07-01",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "StorageV2",
"properties": {}
},
{
"type": "Microsoft.Storage/storageAccounts",
"name": "bucket2",
"location": "[parameters('location')]",
"apiVersion": "2018-07-01",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "StorageV2",
"properties": {}
}
],
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[variables('storageAccountName')]"
}
}
}
@@ -26,17 +26,19 @@
"variables": {
"storageAccountName": "[concat('store', uniquestring(resourceGroup().id))]"
},
"resources": [{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"apiVersion": "2018-07-01",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "StorageV2",
"properties": {}
}],
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"apiVersion": "2018-07-01",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "StorageV2",
"properties": {}
}
],
"outputs": {
"storageAccountName": {
"type": "string",
@@ -26,17 +26,19 @@
"variables": {
"storageAccountName": "[concat('store', uniquestring(resourceGroup().id))]"
},
"resources": [{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"apiVersion": "2018-07-01",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "StorageV2",
"properties": {}
}],
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"apiVersion": "2018-07-01",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "StorageV2",
"properties": {}
}
],
"outputs": {
"storageAccountName": {
"type": "string",
@@ -4,9 +4,9 @@ metadata:
name: evil-pod
spec:
containers:
- command: ["sh", "-c", "echo 'Hello' && sleep 1h"]
- command: [ "sh", "-c", "echo 'Hello' && sleep 1h" ]
image: evil
name: evil1
- command: ["sh", "-c", "echo 'Hello' && sleep 1h"]
- command: [ "sh", "-c", "echo 'Hello' && sleep 1h" ]
image: evil
name: evil2
@@ -4,6 +4,6 @@ metadata:
name: good-pod
spec:
containers:
- command: ["sh", "-c", "echo 'Hello' && sleep 1h"]
- command: [ "sh", "-c", "echo 'Hello' && sleep 1h" ]
image: good
name: good
@@ -4,6 +4,6 @@ metadata:
name: evil-pod
spec:
containers:
- command: ["sh", "-c", "echo 'Hello' && sleep 1h"]
- command: [ "sh", "-c", "echo 'Hello' && sleep 1h" ]
image: evil
name: evil
@@ -1,4 +1,3 @@
resource "aws_s3_bucket" "three" {
}
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"net/url"
"os"
git "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"golang.org/x/xerrors"
+2
View File
@@ -1,3 +1,5 @@
//go:build unix
package remote
import (
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"os"
"path/filepath"
digest "github.com/opencontainers/go-digest"
"github.com/opencontainers/go-digest"
"golang.org/x/xerrors"
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
+26 -15
View File
@@ -3,6 +3,8 @@ package sbom_test
import (
"context"
"errors"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@@ -20,11 +22,11 @@ func TestArtifact_Inspect(t *testing.T) {
filePath string
putBlobExpectation cache.ArtifactCachePutBlobExpectation
want types.ArtifactReference
wantErr string
wantErr []string
}{
{
name: "happy path",
filePath: "testdata/bom.json",
filePath: filepath.Join("testdata", "bom.json"),
putBlobExpectation: cache.ArtifactCachePutBlobExpectation{
Args: cache.ArtifactCachePutBlobArgs{
BlobID: "sha256:21f10e5ab97c37f6c4d6a45815cd5db10e9539d5db8614d3b1d8890111d7a2b8",
@@ -38,8 +40,9 @@ func TestArtifact_Inspect(t *testing.T) {
{
Packages: []types.Package{
{
Name: "musl", Version: "1.2.3-r0", SrcName: "musl", SrcVersion: "1.2.3-r0", Licenses: []string{"MIT"},
Ref: "pkg:apk/alpine/musl@1.2.3-r0?distro=3.16.0",
Name: "musl", Version: "1.2.3-r0", SrcName: "musl", SrcVersion: "1.2.3-r0",
Licenses: []string{"MIT"},
Ref: "pkg:apk/alpine/musl@1.2.3-r0?distro=3.16.0",
Layer: types.Layer{
DiffID: "sha256:dd565ff850e7003356e2b252758f9bdc1ff2803f61e995e24c7844f6297f8fc3",
},
@@ -120,7 +123,7 @@ func TestArtifact_Inspect(t *testing.T) {
Returns: cache.ArtifactCachePutBlobReturns{},
},
want: types.ArtifactReference{
Name: "testdata/bom.json",
Name: filepath.Join("testdata", "bom.json"),
Type: types.ArtifactCycloneDX,
ID: "sha256:21f10e5ab97c37f6c4d6a45815cd5db10e9539d5db8614d3b1d8890111d7a2b8",
BlobIDs: []string{
@@ -130,7 +133,7 @@ func TestArtifact_Inspect(t *testing.T) {
},
{
name: "happy path for sbom attestation",
filePath: "testdata/sbom.cdx.intoto.jsonl",
filePath: filepath.Join("testdata", "sbom.cdx.intoto.jsonl"),
putBlobExpectation: cache.ArtifactCachePutBlobExpectation{
Args: cache.ArtifactCachePutBlobArgs{
BlobID: "sha256:21f10e5ab97c37f6c4d6a45815cd5db10e9539d5db8614d3b1d8890111d7a2b8",
@@ -144,8 +147,9 @@ func TestArtifact_Inspect(t *testing.T) {
{
Packages: []types.Package{
{
Name: "musl", Version: "1.2.3-r0", SrcName: "musl", SrcVersion: "1.2.3-r0", Licenses: []string{"MIT"},
Ref: "pkg:apk/alpine/musl@1.2.3-r0?distro=3.16.0",
Name: "musl", Version: "1.2.3-r0", SrcName: "musl", SrcVersion: "1.2.3-r0",
Licenses: []string{"MIT"},
Ref: "pkg:apk/alpine/musl@1.2.3-r0?distro=3.16.0",
Layer: types.Layer{
DiffID: "sha256:dd565ff850e7003356e2b252758f9bdc1ff2803f61e995e24c7844f6297f8fc3",
},
@@ -226,7 +230,7 @@ func TestArtifact_Inspect(t *testing.T) {
Returns: cache.ArtifactCachePutBlobReturns{},
},
want: types.ArtifactReference{
Name: "testdata/sbom.cdx.intoto.jsonl",
Name: filepath.Join("testdata", "sbom.cdx.intoto.jsonl"),
Type: types.ArtifactCycloneDX,
ID: "sha256:21f10e5ab97c37f6c4d6a45815cd5db10e9539d5db8614d3b1d8890111d7a2b8",
BlobIDs: []string{
@@ -236,12 +240,12 @@ func TestArtifact_Inspect(t *testing.T) {
},
{
name: "sad path with no such directory",
filePath: "./testdata/unknown.json",
wantErr: "no such file or directory",
filePath: filepath.Join("testdata", "unknown.json"),
wantErr: []string{"no such file or directory", "The system cannot find the file specified"},
},
{
name: "sad path PutBlob returns an error",
filePath: "testdata/os-only-bom.json",
filePath: filepath.Join("testdata", "os-only-bom.json"),
putBlobExpectation: cache.ArtifactCachePutBlobExpectation{
Args: cache.ArtifactCachePutBlobArgs{
BlobID: "sha256:05a4e94bb5503e437108210c90849a977ea0b9b83e4e8606aabc9647b2a5256c",
@@ -260,7 +264,7 @@ func TestArtifact_Inspect(t *testing.T) {
Err: errors.New("error"),
},
},
wantErr: "failed to store blob",
wantErr: []string{"failed to store blob"},
},
}
for _, tt := range tests {
@@ -272,9 +276,16 @@ func TestArtifact_Inspect(t *testing.T) {
require.NoError(t, err)
got, err := a.Inspect(context.Background())
if tt.wantErr != "" {
if len(tt.wantErr) > 0 {
require.NotNil(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
found := false
for _, wantErr := range tt.wantErr {
if strings.Contains(err.Error(), wantErr) {
found = true
break
}
}
assert.True(t, found)
return
}
+10 -1
View File
@@ -1 +1,10 @@
{"payloadType":"application/vnd.in-toto+json","payload":"eyJfdHlwZSI6Imh0dHBzOi8vaW4tdG90by5pby9TdGF0ZW1lbnQvdjAuMSIsInByZWRpY2F0ZVR5cGUiOiJodHRwczovL2N5Y2xvbmVkeC5vcmcvYm9tIiwic3ViamVjdCI6W3sibmFtZSI6ImluZGV4LmRvY2tlci5pby9vdG1zNjEvaGVsb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ZDRhNi00ZjcxLWFkMTQtMDg5M2FjNjA5MTgyIn0seyJkZXBlbmRzT24iOlsicGtnOmNvbXBvc2VyL3BlYXIvbG9nQDEuMTMuMSIsInBrZzpjb21wb3Nlci9wZWFyL3BlYXJfZXhjZXB0aW9uQHYxLjAuMCJdLCJyZWYiOiIxMDA5MjVmZi03YzBhLTQ3MGYtYTcyNS04ZmI5NzNiNDBlN2IifSx7ImRlcGVuZHNPbiI6WyJwa2c6Z29sYW5nL2dpdGh1Yi5jb20vcGFja2FnZS11cmwvcLine truncated
"signatures": [
{
"keyid": "",
"sig": "MEUCIQD57kCtdvc8gCX9CU3yMO/areJwRf7U52SatgsY5+Z+uAIgU3EQv/qAC+oj2bp3HusTrOAMjMN9RajsuFmifbahZeo="
}
]
}
+8 -4
View File
@@ -36,7 +36,7 @@ func TestNewArtifact(t *testing.T) {
}{
{
name: "happy path for file",
target: filepath.Join("testdata", "rawdata.img"),
target: "testdata/rawdata.img",
wantErr: assert.NoError,
},
{
@@ -46,7 +46,7 @@ func TestNewArtifact(t *testing.T) {
},
{
name: "sad path unsupported vm format",
target: filepath.Join("testdata", "monolithicSparse.vmdk"),
target: "testdata/monolithicSparse.vmdk",
wantErr: func(t assert.TestingT, err error, args ...interface{}) bool {
return assert.ErrorContains(t, err, "unsupported type error")
},
@@ -55,7 +55,7 @@ func TestNewArtifact(t *testing.T) {
name: "sad path file not found",
target: "testdata/no-file",
wantErr: func(t assert.TestingT, err error, args ...interface{}) bool {
return assert.ErrorContains(t, err, "no such file or directory")
return assert.ErrorContains(t, err, "file open error")
},
},
}
@@ -177,6 +177,9 @@ func TestArtifact_Inspect(t *testing.T) {
c.ApplyPutBlobExpectation(tt.putBlobExpectation)
c.ApplyMissingBlobsExpectation(tt.missingBlobsExpectation)
c.ApplyPutArtifactExpectations(tt.putArtifactExpectations)
c.ApplyDeleteBlobsExpectation(cache.ArtifactCacheDeleteBlobsExpectation{
Args: cache.ArtifactCacheDeleteBlobsArgs{BlobIDsAnything: true},
})
filePath := tt.filePath
if !strings.HasPrefix(tt.filePath, ebsPrefix) {
@@ -189,11 +192,12 @@ func TestArtifact_Inspect(t *testing.T) {
if aa, ok := a.(*vm.EBS); ok {
// blockSize: 512 KB, volumeSize: 40MB
ebs := ebsfile.NewMockEBS(filepath.Join("testdata", "AmazonLinux2.img.gz"), 512<<10, 40<<20)
ebs := ebsfile.NewMockEBS("testdata/AmazonLinux2.img.gz", 512<<10, 40<<20)
aa.SetEBS(ebs)
}
got, err := a.Inspect(context.Background())
defer a.Clean(got)
if tt.wantErr != "" {
require.Error(t, err)
assert.ErrorContains(t, err, tt.wantErr)
+16 -4
View File
@@ -99,7 +99,10 @@ func TestFSCache_GetBlob(t *testing.T) {
fs, err := NewFSCache(tmpDir)
require.NoError(t, err)
defer fs.Clear()
defer func() {
_ = fs.Clear()
_ = fs.Close()
}()
got, err := fs.GetBlob(tt.args.layerID)
assert.Equal(t, tt.wantErr, err != nil, err)
@@ -269,7 +272,10 @@ func TestFSCache_PutBlob(t *testing.T) {
fs, err := NewFSCache(tmpDir)
require.NoError(t, err)
defer fs.Clear()
defer func() {
_ = fs.Clear()
_ = fs.Close()
}()
if strings.HasPrefix(tt.name, "sad") {
require.NoError(t, fs.Close())
@@ -349,7 +355,10 @@ func TestFSCache_PutArtifact(t *testing.T) {
fs, err := NewFSCache(tmpDir)
require.NoError(t, err)
//defer fs.Clear()
defer func() {
_ = fs.Clear()
_ = fs.Close()
}()
err = fs.PutArtifact(tt.args.imageID, tt.args.imageConfig)
if tt.wantErr != "" {
@@ -466,7 +475,10 @@ func TestFSCache_MissingBlobs(t *testing.T) {
fs, err := NewFSCache(tmpDir)
require.NoError(t, err)
defer fs.Clear()
defer func() {
_ = fs.Clear()
_ = fs.Close()
}()
gotMissingImage, gotMissingLayerIDs, err := fs.MissingBlobs(tt.args.imageID, tt.args.layerIDs)
if tt.wantErr != "" {
+1 -1
View File
@@ -37,7 +37,7 @@ func CalcKey(id string, analyzerVersions, hookVersions map[string]int, artifactO
for _, p := range paths {
s, err := dirhash.HashDir(p, "", dirhash.DefaultHash)
if err != nil {
return "", xerrors.Errorf("hash dir (%s): %w", p, err)
return "", xerrors.Errorf("hash dir error (%s): %w", p, err)
}
if _, err = h.Write([]byte(s)); err != nil {
+2 -2
View File
@@ -152,7 +152,7 @@ func TestCalcKey(t *testing.T) {
},
policy: []string{"policydir"},
},
wantErr: "no such file or directory",
wantErr: "hash dir error",
},
}
for _, tt := range tests {
@@ -170,7 +170,7 @@ func TestCalcKey(t *testing.T) {
got, err := CalcKey(tt.args.key, tt.args.analyzerVersions, tt.args.hookVersions, artifactOpt)
if tt.wantErr != "" {
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
assert.ErrorContains(t, err, tt.wantErr)
return
}
assert.NoError(t, err)
+4
View File
@@ -72,3 +72,7 @@ func (s ConfigScanner) Scan(dir string) ([]types.Misconfiguration, error) {
return mergedLayer.Misconfigurations, nil
}
func (s ConfigScanner) Close() error {
return s.cache.Close()
}
+7 -4
View File
@@ -1,6 +1,7 @@
package external_test
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
@@ -26,10 +27,10 @@ func TestConfigScanner_Scan(t *testing.T) {
{
name: "deny",
fields: fields{
policyPaths: []string{"testdata/deny"},
policyPaths: []string{filepath.Join("testdata", "deny")},
namespaces: []string{"testdata"},
},
inputDir: "testdata/deny",
inputDir: filepath.Join("testdata", "deny"),
want: []types.Misconfiguration{
{
FileType: "dockerfile",
@@ -93,10 +94,10 @@ func TestConfigScanner_Scan(t *testing.T) {
{
name: "allow",
fields: fields{
policyPaths: []string{"testdata/allow"},
policyPaths: []string{filepath.Join("testdata", "allow")},
namespaces: []string{"testdata"},
},
inputDir: "testdata/allow",
inputDir: filepath.Join("testdata", "allow"),
want: []types.Misconfiguration{
{
FileType: "dockerfile",
@@ -131,6 +132,8 @@ func TestConfigScanner_Scan(t *testing.T) {
tt.fields.policyPaths, tt.fields.dataPaths, tt.fields.namespaces, false)
require.NoError(t, err)
defer func() { _ = s.Close() }()
got, err := s.Scan(tt.inputDir)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
+4 -3
View File
@@ -2,7 +2,7 @@ package gomod
import (
"context"
"path/filepath"
"path"
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
"github.com/aquasecurity/trivy/pkg/fanal/artifact"
@@ -30,7 +30,8 @@ func (h gomodMergeHook) Handle(_ context.Context, _ *analyzer.AnalysisResult, bl
var apps []types.Application
for _, app := range blob.Applications {
if app.Type == types.GoModule {
dir, file := filepath.Split(app.FilePath)
// The file path is supposed to be slash-separated regardless of OS.
dir, file := path.Split(app.FilePath)
// go.sum should be merged to go.mod.
if file == types.GoSum {
@@ -39,7 +40,7 @@ func (h gomodMergeHook) Handle(_ context.Context, _ *analyzer.AnalysisResult, bl
if file == types.GoMod && lessThanGo117(app) {
// e.g. /app/go.mod => /app/go.sum
gosumFile := filepath.Join(dir, types.GoSum)
gosumFile := path.Join(dir, types.GoSum)
if gosum := findGoSum(gosumFile, blob.Applications); gosum != nil {
mergeGoSum(&app, gosum) // nolint
}
+5 -5
View File
@@ -103,7 +103,7 @@ func Test_gomodMergeHook_Hook(t *testing.T) {
Applications: []types.Application{
{
Type: types.GoModule,
FilePath: "/app/go.mod",
FilePath: "app/go.mod",
Libraries: []types.Package{
{
Name: "github.com/aquasecurity/go-dep-parser",
@@ -117,7 +117,7 @@ func Test_gomodMergeHook_Hook(t *testing.T) {
},
{
Type: types.GoModule,
FilePath: "/app/go.sum",
FilePath: "app/go.sum",
Libraries: []types.Package{
{
Name: "modernc.org/libc",
@@ -135,7 +135,7 @@ func Test_gomodMergeHook_Hook(t *testing.T) {
Applications: []types.Application{
{
Type: types.GoModule,
FilePath: "/app/go.mod",
FilePath: "app/go.mod",
Libraries: []types.Package{
{
Name: "github.com/aquasecurity/go-dep-parser",
@@ -161,7 +161,7 @@ func Test_gomodMergeHook_Hook(t *testing.T) {
Applications: []types.Application{
{
Type: types.GoModule,
FilePath: "/app/go.mod",
FilePath: "app/go.mod",
Libraries: []types.Package{
{
Name: "github.com/aquasecurity/go-dep-parser",
@@ -179,7 +179,7 @@ func Test_gomodMergeHook_Hook(t *testing.T) {
Applications: []types.Application{
{
Type: types.GoModule,
FilePath: "/app/go.mod",
FilePath: "app/go.mod",
Libraries: []types.Package{
{
Name: "github.com/aquasecurity/go-dep-parser",
+3 -3
View File
@@ -97,7 +97,7 @@ func findFSTarget(paths []string) (string, []string, error) {
for _, path := range absPaths {
path := filepath.ToSlash(path)
path = strings.TrimPrefix(path, slashTarget)
path = strings.TrimPrefix(path, string(filepath.Separator))
path = strings.TrimPrefix(path, "/")
if path == "" {
path = "."
}
@@ -106,8 +106,8 @@ func findFSTarget(paths []string) (string, []string, error) {
// we don't use filepath.Join here as we need to maintain the root "/"
target := strings.Join(outputSegments, string(filepath.Separator))
if target == "" {
target = string(filepath.Separator)
if target == "" || filepath.VolumeName(target) == target {
target += string(filepath.Separator)
}
return target, cleanPaths, nil
}
+35 -15
View File
@@ -3,6 +3,9 @@ package misconf
import (
"context"
"fmt"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
@@ -81,44 +84,62 @@ func Test_FindingFSTarget(t *testing.T) {
wantErr: true,
},
{
input: []string{"/"},
wantTarget: "/",
input: []string{string(os.PathSeparator)},
wantTarget: string(os.PathSeparator),
wantPaths: []string{"."},
},
{
input: []string{"/home/user"},
wantTarget: "/home/user",
input: []string{filepath.Join(string(os.PathSeparator), "home", "user")},
wantTarget: filepath.Join(string(os.PathSeparator), "home", "user"),
wantPaths: []string{"."},
},
{
input: []string{"/home/user", "/home/user/something"},
wantTarget: "/home/user",
input: []string{
filepath.Join(string(os.PathSeparator), "home", "user"),
filepath.Join(string(os.PathSeparator), "home", "user", "something"),
},
wantTarget: filepath.Join(string(os.PathSeparator), "home", "user"),
wantPaths: []string{".", "something"},
},
{
input: []string{"/home/user", "/home/user/something/else"},
wantTarget: "/home/user",
input: []string{
filepath.Join(string(os.PathSeparator), "home", "user"),
filepath.Join(string(os.PathSeparator), "home", "user", "something", "else"),
},
wantTarget: filepath.Join(string(os.PathSeparator), "home", "user"),
wantPaths: []string{".", "something/else"},
},
{
input: []string{"/home/user", "/home/user2/something/else"},
wantTarget: "/home",
input: []string{
filepath.Join(string(os.PathSeparator), "home", "user"),
filepath.Join(string(os.PathSeparator), "home", "user2", "something", "else"),
},
wantTarget: filepath.Join(string(os.PathSeparator), "home"),
wantPaths: []string{"user", "user2/something/else"},
},
{
input: []string{"/foo", "/bar"},
wantTarget: "/",
input: []string{
filepath.Join(string(os.PathSeparator), "foo"),
filepath.Join(string(os.PathSeparator), "bar"),
},
wantTarget: string(os.PathSeparator),
wantPaths: []string{"foo", "bar"},
},
{
input: []string{"/", "/bar"},
wantTarget: "/",
input: []string{string(os.PathSeparator), filepath.Join(string(os.PathSeparator), "bar")},
wantTarget: string(os.PathSeparator),
wantPaths: []string{".", "bar"},
},
}
for _, test := range tests {
t.Run(fmt.Sprintf("%#v", test.input), func(t *testing.T) {
if runtime.GOOS == "windows" {
wantTarget, err := filepath.Abs(test.wantTarget)
require.NoError(t, err)
test.wantTarget = filepath.Clean(wantTarget)
}
target, paths, err := findFSTarget(test.input)
if test.wantErr {
require.Error(t, err)
@@ -128,5 +149,4 @@ func Test_FindingFSTarget(t *testing.T) {
}
})
}
}
+5
View File
@@ -5,6 +5,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/aquasecurity/testdocker/engine"
@@ -43,6 +44,10 @@ func setupPodmanSock(t *testing.T) *httptest.Server {
}
func TestPodmanImage(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("podman.sock is not available for Windows CI")
}
type fields struct {
Image v1.Image
opener opener
+7 -6
View File
@@ -1,6 +1,7 @@
package image
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
@@ -14,32 +15,32 @@ func TestTryOCI(t *testing.T) {
}{
{
name: "correct path to index without tag",
ociImagePath: "testdata/multi",
ociImagePath: filepath.Join("testdata", "multi"),
wantErr: "",
},
{
name: "correct path to index with correct tag",
ociImagePath: "testdata/multi:tg11",
ociImagePath: filepath.Join("testdata", "multi:tg11"),
wantErr: "",
},
{
name: "correct path to index with incorrect tag",
ociImagePath: "testdata/multi:tg12",
ociImagePath: filepath.Join("testdata", "multi:tg12"),
wantErr: "invalid OCI image tag",
},
{
name: "correct path to manifest without tag",
ociImagePath: "testdata/single",
ociImagePath: filepath.Join("testdata", "single"),
wantErr: "",
},
{
name: "correct path to manifest with correct tag",
ociImagePath: "testdata/single:3.14",
ociImagePath: filepath.Join("testdata", "single:3.14"),
wantErr: "",
},
{
name: "correct path to manifest with incorrect tag",
ociImagePath: "testdata/single:3.11",
ociImagePath: filepath.Join("testdata", "single:3.11"),
wantErr: "invalid OCI image tag",
},
}
+65 -61
View File
@@ -1,7 +1,9 @@
package secret_test
import (
"bytes"
"os"
"path/filepath"
"testing"
"go.uber.org/zap"
@@ -534,27 +536,27 @@ func TestSecretScanner(t *testing.T) {
}{
{
name: "find match",
configPath: "testdata/config.yaml",
inputFilePath: "testdata/secret.txt",
configPath: filepath.Join("testdata", "config.yaml"),
inputFilePath: filepath.Join("testdata", "secret.txt"),
want: types.Secret{
FilePath: "testdata/secret.txt",
FilePath: filepath.Join("testdata", "secret.txt"),
Findings: []types.SecretFinding{wantFinding1, wantFinding2},
},
},
{
name: "find aws secrets",
configPath: "testdata/config.yaml",
inputFilePath: "testdata/aws-secrets.txt",
configPath: filepath.Join("testdata", "config.yaml"),
inputFilePath: filepath.Join("testdata", "aws-secrets.txt"),
want: types.Secret{
FilePath: "testdata/aws-secrets.txt",
FilePath: filepath.Join("testdata", "aws-secrets.txt"),
Findings: []types.SecretFinding{wantFinding5, wantFinding10, wantFinding9},
},
},
{
name: "find Asymmetric Private Key secrets",
inputFilePath: "testdata/asymmetric-private-secret.txt",
inputFilePath: filepath.Join("testdata", "asymmetric-private-secret.txt"),
want: types.Secret{
FilePath: "testdata/asymmetric-private-secret.txt",
FilePath: filepath.Join("testdata", "asymmetric-private-secret.txt"),
Findings: []types.SecretFinding{wantFindingAsymmetricPrivateKey},
},
},
@@ -568,170 +570,170 @@ func TestSecretScanner(t *testing.T) {
},
{
name: "find Asymmetric Private Key secrets json",
inputFilePath: "testdata/asymmetric-private-secret.json",
inputFilePath: filepath.Join("testdata", "asymmetric-private-secret.json"),
want: types.Secret{
FilePath: "testdata/asymmetric-private-secret.json",
FilePath: filepath.Join("testdata", "asymmetric-private-secret.json"),
Findings: []types.SecretFinding{wantFindingAsymmetricPrivateKeyJson},
},
},
{
name: "include when keyword found",
configPath: "testdata/config-happy-keywords.yaml",
inputFilePath: "testdata/secret.txt",
configPath: filepath.Join("testdata", "config-happy-keywords.yaml"),
inputFilePath: filepath.Join("testdata", "secret.txt"),
want: types.Secret{
FilePath: "testdata/secret.txt",
FilePath: filepath.Join("testdata", "secret.txt"),
Findings: []types.SecretFinding{wantFinding1, wantFinding2},
},
},
{
name: "exclude when no keyword found",
configPath: "testdata/config-sad-keywords.yaml",
inputFilePath: "testdata/secret.txt",
configPath: filepath.Join("testdata", "config-sad-keywords.yaml"),
inputFilePath: filepath.Join("testdata", "secret.txt"),
want: types.Secret{},
},
{
name: "should ignore .md files by default",
configPath: "testdata/config.yaml",
inputFilePath: "testdata/secret.md",
configPath: filepath.Join("testdata", "config.yaml"),
inputFilePath: filepath.Join("testdata", "secret.md"),
want: types.Secret{
FilePath: "testdata/secret.md",
FilePath: filepath.Join("testdata", "secret.md"),
},
},
{
name: "should disable .md allow rule",
configPath: "testdata/config-disable-allow-rule-md.yaml",
inputFilePath: "testdata/secret.md",
configPath: filepath.Join("testdata", "config-disable-allow-rule-md.yaml"),
inputFilePath: filepath.Join("testdata", "secret.md"),
want: types.Secret{
FilePath: "testdata/secret.md",
FilePath: filepath.Join("testdata", "secret.md"),
Findings: []types.SecretFinding{wantFinding1, wantFinding2},
},
},
{
name: "should find ghp builtin secret",
configPath: "",
inputFilePath: "testdata/builtin-rule-secret.txt",
inputFilePath: filepath.Join("testdata", "builtin-rule-secret.txt"),
want: types.Secret{
FilePath: "testdata/builtin-rule-secret.txt",
FilePath: filepath.Join("testdata", "builtin-rule-secret.txt"),
Findings: []types.SecretFinding{wantFinding5a, wantFinding6},
},
},
{
name: "should enable github-pat builtin rule, but disable aws-access-key-id rule",
configPath: "testdata/config-enable-ghp.yaml",
inputFilePath: "testdata/builtin-rule-secret.txt",
configPath: filepath.Join("testdata", "config-enable-ghp.yaml"),
inputFilePath: filepath.Join("testdata", "builtin-rule-secret.txt"),
want: types.Secret{
FilePath: "testdata/builtin-rule-secret.txt",
FilePath: filepath.Join("testdata", "builtin-rule-secret.txt"),
Findings: []types.SecretFinding{wantFindingGHButDisableAWS},
},
},
{
name: "should disable github-pat builtin rule",
configPath: "testdata/config-disable-ghp.yaml",
inputFilePath: "testdata/builtin-rule-secret.txt",
configPath: filepath.Join("testdata", "config-disable-ghp.yaml"),
inputFilePath: filepath.Join("testdata", "builtin-rule-secret.txt"),
want: types.Secret{
FilePath: "testdata/builtin-rule-secret.txt",
FilePath: filepath.Join("testdata", "builtin-rule-secret.txt"),
Findings: []types.SecretFinding{wantFindingPATDisabled},
},
},
{
name: "should disable custom rule",
configPath: "testdata/config-disable-rule1.yaml",
inputFilePath: "testdata/secret.txt",
configPath: filepath.Join("testdata", "config-disable-rule1.yaml"),
inputFilePath: filepath.Join("testdata", "secret.txt"),
want: types.Secret{},
},
{
name: "allow-rule path",
configPath: "testdata/allow-path.yaml",
inputFilePath: "testdata/secret.txt",
configPath: filepath.Join("testdata", "allow-path.yaml"),
inputFilePath: filepath.Join("testdata", "secret.txt"),
want: types.Secret{},
},
{
name: "allow-rule regex inside group",
configPath: "testdata/allow-regex.yaml",
inputFilePath: "testdata/secret.txt",
configPath: filepath.Join("testdata", "allow-regex.yaml"),
inputFilePath: filepath.Join("testdata", "secret.txt"),
want: types.Secret{
FilePath: "testdata/secret.txt",
FilePath: filepath.Join("testdata", "secret.txt"),
Findings: []types.SecretFinding{wantFinding1},
},
},
{
name: "allow-rule regex outside group",
configPath: "testdata/allow-regex-outside-group.yaml",
inputFilePath: "testdata/secret.txt",
configPath: filepath.Join("testdata", "allow-regex-outside-group.yaml"),
inputFilePath: filepath.Join("testdata", "secret.txt"),
want: types.Secret{},
},
{
name: "exclude-block regexes",
configPath: "testdata/exclude-block.yaml",
inputFilePath: "testdata/secret.txt",
configPath: filepath.Join("testdata", "exclude-block.yaml"),
inputFilePath: filepath.Join("testdata", "secret.txt"),
want: types.Secret{
FilePath: "testdata/secret.txt",
FilePath: filepath.Join("testdata", "secret.txt"),
Findings: []types.SecretFinding{wantFindingRegexDisabled},
},
},
{
name: "skip examples file",
inputFilePath: "testdata/example-secret.txt",
inputFilePath: filepath.Join("testdata", "example-secret.txt"),
want: types.Secret{
FilePath: "testdata/example-secret.txt",
FilePath: filepath.Join("testdata", "example-secret.txt"),
},
},
{
name: "global allow-rule path",
configPath: "testdata/global-allow-path.yaml",
inputFilePath: "testdata/secret.txt",
configPath: filepath.Join("testdata", "global-allow-path.yaml"),
inputFilePath: filepath.Join("testdata", "secret.txt"),
want: types.Secret{
FilePath: "testdata/secret.txt",
FilePath: filepath.Join("testdata", "secret.txt"),
Findings: nil,
},
},
{
name: "global allow-rule regex",
configPath: "testdata/global-allow-regex.yaml",
inputFilePath: "testdata/secret.txt",
configPath: filepath.Join("testdata", "global-allow-regex.yaml"),
inputFilePath: filepath.Join("testdata", "secret.txt"),
want: types.Secret{
FilePath: "testdata/secret.txt",
FilePath: filepath.Join("testdata", "secret.txt"),
Findings: []types.SecretFinding{wantFinding1},
},
},
{
name: "global exclude-block regexes",
configPath: "testdata/global-exclude-block.yaml",
inputFilePath: "testdata/secret.txt",
configPath: filepath.Join("testdata", "global-exclude-block.yaml"),
inputFilePath: filepath.Join("testdata", "secret.txt"),
want: types.Secret{
FilePath: "testdata/secret.txt",
FilePath: filepath.Join("testdata", "secret.txt"),
Findings: []types.SecretFinding{wantFindingRegexDisabled},
},
},
{
name: "multiple secret groups",
configPath: "testdata/multiple-secret-groups.yaml",
inputFilePath: "testdata/secret.txt",
configPath: filepath.Join("testdata", "multiple-secret-groups.yaml"),
inputFilePath: filepath.Join("testdata", "secret.txt"),
want: types.Secret{
FilePath: "testdata/secret.txt",
FilePath: filepath.Join("testdata", "secret.txt"),
Findings: []types.SecretFinding{wantFinding3, wantFinding4},
},
},
{
name: "truncate long line",
inputFilePath: "testdata/long-line-secret.txt",
inputFilePath: filepath.Join("testdata", "long-line-secret.txt"),
want: types.Secret{
FilePath: "testdata/long-line-secret.txt",
FilePath: filepath.Join("testdata", "long-line-secret.txt"),
Findings: []types.SecretFinding{wantFinding7},
},
},
{
name: "add unknown severity when rule has no severity",
configPath: "testdata/config-without-severity.yaml",
inputFilePath: "testdata/secret.txt",
configPath: filepath.Join("testdata", "config-without-severity.yaml"),
inputFilePath: filepath.Join("testdata", "secret.txt"),
want: types.Secret{
FilePath: "testdata/secret.txt",
FilePath: filepath.Join("testdata", "secret.txt"),
Findings: []types.SecretFinding{wantFinding8},
},
},
{
name: "invalid aws secrets",
inputFilePath: "testdata/invalid-aws-secrets.txt",
inputFilePath: filepath.Join("testdata", "invalid-aws-secrets.txt"),
want: types.Secret{},
},
{
@@ -750,6 +752,8 @@ func TestSecretScanner(t *testing.T) {
content, err := os.ReadFile(tt.inputFilePath)
require.NoError(t, err)
content = bytes.ReplaceAll(content, []byte("\r"), []byte(""))
c, err := secret.ParseConfig(tt.configPath)
require.NoError(t, err)
+15 -1
View File
@@ -24,10 +24,24 @@ type LicenseFile struct {
Type LicenseType
FilePath string
PkgName string
Findings []LicenseFinding
Findings LicenseFindings
Layer Layer `json:",omitempty"`
}
type LicenseFindings []LicenseFinding
func (findings LicenseFindings) Len() int {
return len(findings)
}
func (findings LicenseFindings) Swap(i, j int) {
findings[i], findings[j] = findings[j], findings[i]
}
func (findings LicenseFindings) Less(i, j int) bool {
return findings[i].Name < findings[j].Name
}
type LicenseFinding struct {
Category LicenseCategory // such as "forbidden"
Name string
+6
View File
@@ -7,6 +7,7 @@ import (
"math"
"os"
"os/exec"
"path/filepath"
dio "github.com/aquasecurity/go-dep-parser/pkg/io"
)
@@ -56,6 +57,11 @@ func Keys(m map[string]struct{}) []string {
}
func IsExecutable(fileInfo os.FileInfo) bool {
// For Windows
if filepath.Ext(fileInfo.Name()) == ".exe" {
return true
}
mode := fileInfo.Mode()
if !mode.IsRegular() {
return false
+6 -5
View File
@@ -3,6 +3,7 @@ package utils
import (
"bufio"
"os"
"path/filepath"
"testing"
)
@@ -11,11 +12,11 @@ func TestIsGzip(t *testing.T) {
in string
want bool
}{
{"testdata/test.txt.gz", true},
{"testdata/test.tar.gz", true},
{"testdata/test.txt", false},
{"testdata/test.txt.zst", false},
{"testdata/aqua.png", false},
{filepath.Join("testdata", "test.txt.gz"), true},
{filepath.Join("testdata", "test.tar.gz"), true},
{filepath.Join("testdata", "test.txt"), false},
{filepath.Join("testdata", "test.txt.zst"), false},
{filepath.Join("testdata", "aqua.png"), false},
}
for _, tt := range tests {
t.Run(tt.in, func(t *testing.T) {
+5 -4
View File
@@ -4,6 +4,7 @@ import (
"errors"
"io"
"os"
"path/filepath"
"strings"
"testing"
@@ -28,7 +29,7 @@ func TestDir_Walk(t *testing.T) {
}{
{
name: "happy path",
rootDir: "testdata/fs",
rootDir: filepath.Join("testdata", "fs"),
analyzeFn: func(filePath string, info os.FileInfo, opener analyzer.Opener) error {
if filePath == "testdata/fs/bar" {
got, err := opener()
@@ -44,7 +45,7 @@ func TestDir_Walk(t *testing.T) {
},
{
name: "skip file",
rootDir: "testdata/fs",
rootDir: filepath.Join("testdata", "fs"),
fields: fields{
skipFiles: []string{"testdata/fs/bar"},
},
@@ -59,7 +60,7 @@ func TestDir_Walk(t *testing.T) {
name: "skip dir",
rootDir: "testdata/fs/",
fields: fields{
skipDirs: []string{"/testdata/fs/app/"},
skipDirs: []string{"/testdata/fs/app"},
},
analyzeFn: func(filePath string, info os.FileInfo, opener analyzer.Opener) error {
if strings.HasPrefix(filePath, "testdata/fs/app") {
@@ -70,7 +71,7 @@ func TestDir_Walk(t *testing.T) {
},
{
name: "sad path",
rootDir: "testdata/fs",
rootDir: filepath.Join("testdata", "fs"),
analyzeFn: func(filePath string, info os.FileInfo, opener analyzer.Opener) error {
return errors.New("error")
},
+11 -6
View File
@@ -4,10 +4,13 @@ import (
"archive/tar"
"io"
"io/fs"
"path"
"path/filepath"
"strings"
"golang.org/x/xerrors"
"github.com/aquasecurity/trivy/pkg/fanal/utils"
)
const (
@@ -15,6 +18,8 @@ const (
wh string = ".wh."
)
var parentDir = ".." + utils.PathSeparator
type LayerTar struct {
walker
threshold int64
@@ -33,7 +38,6 @@ func NewLayerTar(skipFiles, skipDirs []string, slow bool) LayerTar {
}
func (w LayerTar) Walk(layer io.Reader, analyzeFn WalkFunc) ([]string, []string, error) {
var opqDirs, whFiles, skipDirs []string
tr := tar.NewReader(layer)
for {
@@ -44,9 +48,10 @@ func (w LayerTar) Walk(layer io.Reader, analyzeFn WalkFunc) ([]string, []string,
return nil, nil, xerrors.Errorf("failed to extract the archive: %w", err)
}
filePath := hdr.Name
filePath = strings.TrimLeft(filepath.Clean(filePath), "/")
fileDir, fileName := filepath.Split(filePath)
// filepath.Clean cannot be used since tar file paths should be OS-agnostic.
filePath := path.Clean(hdr.Name)
filePath = strings.TrimLeft(filePath, "/")
fileDir, fileName := path.Split(filePath)
// e.g. etc/.wh..wh..opq
if opq == fileName {
@@ -56,7 +61,7 @@ func (w LayerTar) Walk(layer io.Reader, analyzeFn WalkFunc) ([]string, []string,
// etc/.wh.hostname
if strings.HasPrefix(fileName, wh) {
name := strings.TrimPrefix(fileName, wh)
fpath := filepath.Join(fileDir, name)
fpath := path.Join(fileDir, name)
whFiles = append(whFiles, fpath)
continue
}
@@ -108,7 +113,7 @@ func underSkippedDir(filePath string, skipDirs []string) bool {
if err != nil {
return false
}
if !strings.HasPrefix(rel, "../") {
if !strings.HasPrefix(rel, parentDir) {
return true
}
}
+5 -4
View File
@@ -3,6 +3,7 @@ package walker_test
import (
"errors"
"os"
"path/filepath"
"strings"
"testing"
@@ -31,7 +32,7 @@ func TestLayerTar_Walk(t *testing.T) {
}{
{
name: "happy path",
inputFile: "testdata/test.tar",
inputFile: filepath.Join("testdata", "test.tar"),
analyzeFn: func(filePath string, info os.FileInfo, opener analyzer.Opener) error {
return nil
},
@@ -40,7 +41,7 @@ func TestLayerTar_Walk(t *testing.T) {
},
{
name: "skip file",
inputFile: "testdata/test.tar",
inputFile: filepath.Join("testdata", "test.tar"),
fields: fields{
skipFiles: []string{"/app/myweb/index.html"},
},
@@ -55,9 +56,9 @@ func TestLayerTar_Walk(t *testing.T) {
},
{
name: "skip dir",
inputFile: "testdata/test.tar",
inputFile: filepath.Join("testdata", "test.tar"),
fields: fields{
skipDirs: []string{"/app/"},
skipDirs: []string{"/app"},
},
analyzeFn: func(filePath string, info os.FileInfo, opener analyzer.Opener) error {
if strings.HasPrefix(filePath, "app") {
+13 -3
View File
@@ -3,6 +3,7 @@ package licensing
import (
"fmt"
"io"
"sort"
"sync"
classifier "github.com/google/licenseclassifier/v2"
@@ -13,8 +14,11 @@ import (
"github.com/aquasecurity/trivy/pkg/log"
)
var cf *classifier.Classifier
var classifierOnce sync.Once
var (
cf *classifier.Classifier
classifierOnce sync.Once
m sync.Mutex
)
func initGoogleClassifier() error {
// Initialize the default classifier once.
@@ -37,13 +41,18 @@ func Classify(filePath string, r io.Reader) (*types.LicenseFile, error) {
return nil, err
}
var findings []types.LicenseFinding
var findings types.LicenseFindings
var matchType types.LicenseType
seen := map[string]struct{}{}
// cf.Match is not thread safe
m.Lock()
// Use 'github.com/google/licenseclassifier' to find licenses
result := cf.Match(cf.Normalize(content))
m.Unlock()
for _, match := range result.Matches {
if match.Confidence <= 0.9 {
continue
@@ -68,6 +77,7 @@ func Classify(filePath string, r io.Reader) (*types.LicenseFile, error) {
Link: licenseLink,
})
}
sort.Sort(findings)
return &types.LicenseFile{
Type: matchType,
FilePath: filePath,
+8 -1
View File
@@ -2,6 +2,7 @@ package log
import (
"os"
"runtime"
xlog "github.com/masahiro331/go-xfs-filesystem/log"
"go.uber.org/zap"
@@ -58,6 +59,12 @@ func NewLogger(debug, disable bool) (*zap.SugaredLogger, error) {
return zapcore.DebugLevel < lvl && lvl < zapcore.ErrorLevel
})
encoderLevel := zapcore.CapitalColorLevelEncoder
// when running on Windows, don't log with color
if runtime.GOOS == "windows" {
encoderLevel = zapcore.CapitalLevelEncoder
}
encoderConfig := zapcore.EncoderConfig{
TimeKey: "Time",
LevelKey: "Level",
@@ -65,7 +72,7 @@ func NewLogger(debug, disable bool) (*zap.SugaredLogger, error) {
CallerKey: "Caller",
MessageKey: "Msg",
StacktraceKey: "St",
EncodeLevel: zapcore.CapitalColorLevelEncoder,
EncodeLevel: encoderLevel,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
+5
View File
@@ -4,6 +4,7 @@ import (
"context"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
@@ -16,6 +17,10 @@ import (
)
func TestManager_Register(t *testing.T) {
if runtime.GOOS == "windows" {
// WASM tests difficult on Windows
t.Skip("Test satisfied adequately by Linux tests")
}
tests := []struct {
name string
noModuleDir bool
+25
View File
@@ -4,6 +4,7 @@ import (
"context"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
@@ -14,6 +15,10 @@ import (
)
func TestPlugin_Run(t *testing.T) {
if runtime.GOOS == "windows" {
// the test.sh script can't be run on windows so skipping
t.Skip("Test satisfied adequately by Linux tests")
}
type fields struct {
Name string
Repository string
@@ -169,6 +174,10 @@ func TestPlugin_Run(t *testing.T) {
}
func TestInstall(t *testing.T) {
if runtime.GOOS == "windows" {
// the test.sh script can't be run on windows so skipping
t.Skip("Test satisfied adequately by Linux tests")
}
tests := []struct {
name string
url string
@@ -272,6 +281,10 @@ func TestInstall(t *testing.T) {
}
func TestUninstall(t *testing.T) {
if runtime.GOOS == "windows" {
// the test.sh script can't be run on windows so skipping
t.Skip("Test satisfied adequately by Linux tests")
}
pluginName := "test_plugin"
tempDir := t.TempDir()
@@ -292,6 +305,10 @@ func TestUninstall(t *testing.T) {
}
func TestInformation(t *testing.T) {
if runtime.GOOS == "windows" {
// the test.sh script can't be run on windows so skipping
t.Skip("Test satisfied adequately by Linux tests")
}
pluginName := "test_plugin"
tempDir := t.TempDir()
@@ -325,6 +342,10 @@ description: A simple test plugin`
}
func TestLoadAll1(t *testing.T) {
if runtime.GOOS == "windows" {
// the test.sh script can't be run on windows so skipping
t.Skip("Test satisfied adequately by Linux tests")
}
tests := []struct {
name string
dir string
@@ -380,6 +401,10 @@ func TestLoadAll1(t *testing.T) {
}
func TestUpdate(t *testing.T) {
if runtime.GOOS == "windows" {
// the test.sh script can't be run on windows so skipping
t.Skip("Test satisfied adequately by Linux tests")
}
pluginName := "test_plugin"
tempDir := t.TempDir()
+6
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"io"
"os"
"runtime"
"strings"
"sync"
@@ -131,6 +132,11 @@ func summarize(specifiedSeverities []dbTypes.Severity, severityCount map[string]
}
func IsOutputToTerminal(output io.Writer) bool {
if runtime.GOOS == "windows" {
// if its windows, we don't support formatting
return false
}
if output != os.Stdout {
return false
}
+3
View File
@@ -114,6 +114,8 @@ func Test_dbWorker_update(t *testing.T) {
tt.needsUpdate.input.appVersion, tt.needsUpdate.input.skip).Return(
tt.needsUpdate.output.needsUpdate, tt.needsUpdate.output.err)
defer func() { _ = db.Close() }()
if tt.download.call {
mockDBClient.On("Download", mock.Anything, mock.Anything).Run(
func(args mock.Arguments) {
@@ -222,6 +224,7 @@ func Test_newServeMux(t *testing.T) {
c, err := cache.NewFSCache(t.TempDir())
require.NoError(t, err)
defer func() { _ = c.Close() }()
ts := httptest.NewServer(newServeMux(
c, dbUpdateWg, requestWg, tt.args.token, tt.args.tokenHeader),