detector: Add LayerID to detect vulns (#419)

* detector/alpine: Add LayerID to detect vulns

Signed-off-by: Simarpreet Singh <simar@linux.com>

* amazon: Add LayerID to DetectedVulns

Signed-off-by: Simarpreet Singh <simar@linux.com>

* debian: Add LayerID to DetectVulns + tests

Signed-off-by: Simarpreet Singh <simar@linux.com>

* oracle: Add LayerID to DetectVulns + tests

Signed-off-by: Simarpreet Singh <simar@linux.com>

* photon: Add LayerID to DetectVulns + tests

Signed-off-by: Simarpreet Singh <simar@linux.com>

* redhat: Add LayerID to DetectVulns + tests

Signed-off-by: Simarpreet Singh <simar@linux.com>

* suse: Add LayerID to DetectVulns + tests

Signed-off-by: Simarpreet Singh <simar@linux.com>

* ubuntu: Add LayerID to DetectVulns + tests

Signed-off-by: Simarpreet Singh <simar@linux.com>

* integration: Fix integration tests to include LayerID

Signed-off-by: Simarpreet Singh <simar@linux.com>

* fix(rpc): add layer_id

* fix(rpc): insert layer_id to the struct

* fix(extractor): add cleanup function

* fix(library): add layer ID to detected vulnerabilities

* test: update mocks

* chore(mod): point to the feature branch of fanal

* mod: Point to fanal/master

Signed-off-by: Simarpreet Singh <simar@linux.com>

* scan_test: Include LayerID as part of the assertion

Signed-off-by: Simarpreet Singh <simar@linux.com>

* docker_engine_test.go: Update an error message to conform with fanal/master.

Signed-off-by: Simarpreet Singh <simar@linux.com>

Co-authored-by: Teppei Fukuda <knqyf263@gmail.com>
This commit is contained in:
Teppei Fukuda
2020-03-04 19:55:16 +02:00
committed by GitHub
parent 18b80e3781
commit aca31dffb3
69 changed files with 3565 additions and 271 deletions

View File

@@ -5,6 +5,8 @@ import (
"os"
"testing"
ftypes "github.com/aquasecurity/fanal/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/xerrors"
@@ -32,7 +34,7 @@ func TestServer_Detect(t *testing.T) {
tests := []struct {
name string
args args
detectExpectation library.DetectExpectation
detectExpectation library.OperationDetectExpectation
fillInfoExpectation vulnerability.FillInfoExpectation
wantRes *proto.DetectResponse
wantErr string
@@ -48,14 +50,16 @@ func TestServer_Detect(t *testing.T) {
},
},
},
detectExpectation: library.DetectExpectation{
Args: library.DetectInput{
detectExpectation: library.OperationDetectExpectation{
Args: library.OperationDetectArgs{
FilePath: "app/Pipfile.lock",
Libs: []ptypes.Library{
{Name: "django", Version: "3.0.0"},
Pkgs: []ftypes.LibraryInfo{
{
Library: ptypes.Library{Name: "django", Version: "3.0.0"},
},
},
},
ReturnArgs: library.DetectOutput{
Returns: library.OperationDetectReturns{
Vulns: []types.DetectedVulnerability{
{
VulnerabilityID: "CVE-2019-0001",
@@ -117,14 +121,14 @@ func TestServer_Detect(t *testing.T) {
},
},
},
detectExpectation: library.DetectExpectation{
Args: library.DetectInput{
detectExpectation: library.OperationDetectExpectation{
Args: library.OperationDetectArgs{
FilePath: "app/Pipfile.lock",
Libs: []ptypes.Library{
{Name: "django", Version: "3.0.0"},
Pkgs: []ftypes.LibraryInfo{
{Library: ptypes.Library{Name: "django", Version: "3.0.0"}},
},
},
ReturnArgs: library.DetectOutput{
Returns: library.OperationDetectReturns{
Err: xerrors.New("error"),
},
},
@@ -133,7 +137,8 @@ func TestServer_Detect(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockDetector := library.NewMockDetector([]library.DetectExpectation{tt.detectExpectation})
mockDetector := new(library.MockOperation)
mockDetector.ApplyDetectExpectation(tt.detectExpectation)
mockVulnClient := new(vulnerability.MockOperation)
mockVulnClient.ApplyFillInfoExpectation(tt.fillInfoExpectation)