feat(java): support jar/war/ear (#837)

* refactor(server): remove Detect endpoint

* refactor(library): do not use interface

* refactor: add dbtest package

* test: add bolt fixtures

* feat: support jar scanning

* refactor: rename node to npm

* refactor: fix lint issues

* test(maven): remove some tests

* chore(mod): update fanal

* docs: update README

* chore(mod): update trivy-db

* fix(library/drive): add ecosystem

* fix: do not display 0 vulnerabilities

* refactor(table): split method

* Update README.md (#838)

* fix(app): increase the default value of timeout (#842)

* feat(maven): use go-mvn-version

* test(maven): update tests

* fix(scan): skip files and dirs before vulnerability detection

* fix: display log messages only once per type

* docs(README): add file suffixes

* chore(mod): update go-mvn-version

* feat(log): set go-dep-parser logger

* chore(mod): update fanal

* docs: update README

* docs(README): add java source

* test(maven): fix invalid case
This commit is contained in:
Teppei Fukuda
2021-02-14 18:19:42 +02:00
committed by GitHub
parent 3047c524d9
commit c9f22f4e55
43 changed files with 455 additions and 2695 deletions

View File

@@ -1,22 +1,19 @@
package library_test
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
lib "github.com/aquasecurity/fanal/analyzer/library"
"github.com/aquasecurity/trivy-db/pkg/db"
"github.com/aquasecurity/trivy/pkg/dbtest"
"github.com/aquasecurity/trivy/pkg/detector/library"
"github.com/aquasecurity/trivy/pkg/types"
"github.com/aquasecurity/trivy/pkg/utils"
)
func TestDriver_Detect(t *testing.T) {
type fields struct {
fileName string
}
type args struct {
pkgName string
pkgVer string
@@ -24,7 +21,7 @@ func TestDriver_Detect(t *testing.T) {
tests := []struct {
name string
fixtures []string
fields fields
libType string
args args
want []types.DetectedVulnerability
wantErr string
@@ -32,7 +29,7 @@ func TestDriver_Detect(t *testing.T) {
{
name: "happy path",
fixtures: []string{"testdata/fixtures/php.yaml"},
fields: fields{fileName: "composer.lock"},
libType: lib.Composer,
args: args{
pkgName: "symfony/symfony",
pkgVer: "4.2.6",
@@ -49,7 +46,7 @@ func TestDriver_Detect(t *testing.T) {
{
name: "non-prefix buckets",
fixtures: []string{"testdata/fixtures/php-without-prefix.yaml"},
fields: fields{fileName: "composer.lock"},
libType: lib.Composer,
args: args{
pkgName: "symfony/symfony",
pkgVer: "4.2.6",
@@ -66,7 +63,7 @@ func TestDriver_Detect(t *testing.T) {
{
name: "no patched versions in the advisory",
fixtures: []string{"testdata/fixtures/php.yaml"},
fields: fields{fileName: "composer.lock"},
libType: lib.Composer,
args: args{
pkgName: "symfony/symfony",
pkgVer: "4.4.6",
@@ -83,7 +80,7 @@ func TestDriver_Detect(t *testing.T) {
{
name: "no vulnerable versions in the advisory",
fixtures: []string{"testdata/fixtures/ruby.yaml"},
fields: fields{fileName: "Gemfile.lock"},
libType: lib.Bundler,
args: args{
pkgName: "activesupport",
pkgVer: "4.1.1",
@@ -100,7 +97,7 @@ func TestDriver_Detect(t *testing.T) {
{
name: "no vulnerability",
fixtures: []string{"testdata/fixtures/php.yaml"},
fields: fields{fileName: "composer.lock"},
libType: lib.Composer,
args: args{
pkgName: "symfony/symfony",
pkgVer: "4.4.7",
@@ -110,12 +107,10 @@ func TestDriver_Detect(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Initialize DB
dir := utils.InitTestDB(t, tt.fixtures)
defer os.RemoveAll(dir)
_ = dbtest.InitDB(t, tt.fixtures)
defer db.Close()
factory := library.DriverFactory{}
driver, err := factory.NewDriver(tt.fields.fileName)
driver, err := library.NewDriver(tt.libType)
require.NoError(t, err)
got, err := driver.Detect(tt.args.pkgName, tt.args.pkgVer)