mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-22 23:26:39 -08:00
* fix(log): set the default logger * feat: support plugins * feat(plugin): add run command * feat(plugin): add uninstall command * test(plugin): add tests * chore(ci): pin go version * chore(ci): disable G204 * refactor: fix lint issues * feat(plugin): skip downloading installed plugins * feat: add TRIVY_RUN_AS_PLUGIN * support Ubuntu 20.10 (#876) * docs(README): update ubuntu versions (#877) * add MkDocs implementation (#870) * mkdocs: add top level nav * mkdocs: add installation nav * mkdocs: add quick-start nav * mkdocs: add examples nav * mkdocs: add CI nav * mkdocs: add vuln-detection nav * mkdocs: add comparison nav * mkdocs: add usage nav * mkdocs: add migration nav * mkdocs: add FAQ nav * mkdocs: add mkdocs.yml * mkdocs: add github workflow * docs: update documents * fix links * chore(ci): use ORG_GITHUB_TOKEN * chore(mkdocs): use mike * chore(ci): support dev * chore(ci): documentation test Co-authored-by: knqyf263 <knqyf263@gmail.com> * docs: add plugins * chore: remove stale workflow * refactor: fix lint issues Co-authored-by: Huang Huang <mozillazg101@gmail.com> Co-authored-by: aprp <doelaudi@gmail.com>
83 lines
1.8 KiB
Go
83 lines
1.8 KiB
Go
package python_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/aquasecurity/trivy-db/pkg/db"
|
|
"github.com/aquasecurity/trivy/pkg/dbtest"
|
|
"github.com/aquasecurity/trivy/pkg/detector/library/python"
|
|
"github.com/aquasecurity/trivy/pkg/types"
|
|
)
|
|
|
|
func TestAdvisory_DetectVulnerabilities(t *testing.T) {
|
|
type args struct {
|
|
pkgName string
|
|
pkgVer string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
fixtures []string
|
|
want []types.DetectedVulnerability
|
|
wantErr string
|
|
}{
|
|
{
|
|
name: "detected",
|
|
args: args{
|
|
pkgName: "django",
|
|
pkgVer: "2.2.11a1",
|
|
},
|
|
fixtures: []string{"testdata/fixtures/pip.yaml"},
|
|
want: []types.DetectedVulnerability{
|
|
{
|
|
PkgName: "django",
|
|
InstalledVersion: "2.2.11a1",
|
|
VulnerabilityID: "CVE-2020-9402",
|
|
FixedVersion: "1.11.29, 2.2.11, 3.0.4",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
// https://github.com/aquasecurity/trivy/issues/713
|
|
name: "not detected",
|
|
args: args{
|
|
pkgName: "django",
|
|
pkgVer: "3.0.10",
|
|
},
|
|
fixtures: []string{"testdata/fixtures/pip.yaml"},
|
|
want: nil,
|
|
},
|
|
{
|
|
name: "malformed JSON",
|
|
args: args{
|
|
pkgName: "django",
|
|
pkgVer: "2.0.18",
|
|
},
|
|
fixtures: []string{"testdata/fixtures/invalid-type.yaml"},
|
|
wantErr: "failed to unmarshal advisory JSON",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
_ = dbtest.InitDB(t, tt.fixtures)
|
|
defer db.Close()
|
|
|
|
a := python.NewAdvisory()
|
|
got, err := a.DetectVulnerabilities(tt.args.pkgName, tt.args.pkgVer)
|
|
if tt.wantErr != "" {
|
|
require.NotNil(t, err)
|
|
assert.Contains(t, err.Error(), tt.wantErr)
|
|
return
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
assert.Equal(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|