mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-21 23:00:42 -08:00
BREAKING: migrate to a new JSON schema (#782)
* feat: introduce a new JSON schema * test: update * chore(mod): update fanal * refactor: add a comment * test(report): fix * refactor(writer): add omitempty * refactor: replace url * test(scanner): fix
This commit is contained in:
@@ -23,7 +23,7 @@ func TestScanner_ScanArtifact(t *testing.T) {
|
||||
args args
|
||||
inspectExpectation artifact.ArtifactInspectExpectation
|
||||
scanExpectation DriverScanExpectation
|
||||
wantResults report.Results
|
||||
want report.Report
|
||||
wantErr string
|
||||
}{
|
||||
{
|
||||
@@ -37,9 +37,11 @@ func TestScanner_ScanArtifact(t *testing.T) {
|
||||
},
|
||||
Returns: artifact.ArtifactInspectReturns{
|
||||
Reference: ftypes.ArtifactReference{
|
||||
Name: "alpine:3.11",
|
||||
ID: "sha256:e7d92cdc71feacf90708cb59182d0df1b911f8ae022d29e8e95d75ca6a99776a",
|
||||
BlobIDs: []string{"sha256:5216338b40a7b96416b8b9858974bbe4acc3096ee60acbc4dfb1ee02aecceb10"},
|
||||
Name: "alpine:3.11",
|
||||
ID: "sha256:e7d92cdc71feacf90708cb59182d0df1b911f8ae022d29e8e95d75ca6a99776a",
|
||||
BlobIDs: []string{"sha256:5216338b40a7b96416b8b9858974bbe4acc3096ee60acbc4dfb1ee02aecceb10"},
|
||||
RepoTags: []string{"alpine:3.11"},
|
||||
RepoDigests: []string{"alpine@sha256:0bd0e9e03a022c3b0226667621da84fc9bf562a9056130424b5bfbd8bcb0397f"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -87,33 +89,38 @@ func TestScanner_ScanArtifact(t *testing.T) {
|
||||
Eols: true,
|
||||
},
|
||||
},
|
||||
wantResults: report.Results{
|
||||
{
|
||||
Target: "alpine:3.11",
|
||||
Vulnerabilities: []types.DetectedVulnerability{
|
||||
{
|
||||
VulnerabilityID: "CVE-2019-9999",
|
||||
PkgName: "vim",
|
||||
InstalledVersion: "1.2.3",
|
||||
FixedVersion: "1.2.4",
|
||||
Layer: ftypes.Layer{
|
||||
Digest: "sha256:5216338b40a7b96416b8b9858974bbe4acc3096ee60acbc4dfb1ee02aecceb10",
|
||||
DiffID: "sha256:b2a1a2d80bf0c747a4f6b0ca6af5eef23f043fcdb1ed4f3a3e750aef2dc68079",
|
||||
want: report.Report{
|
||||
ArtifactID: "sha256:e7d92cdc71feacf90708cb59182d0df1b911f8ae022d29e8e95d75ca6a99776a",
|
||||
RepoTags: []string{"alpine:3.11"},
|
||||
RepoDigests: []string{"alpine@sha256:0bd0e9e03a022c3b0226667621da84fc9bf562a9056130424b5bfbd8bcb0397f"},
|
||||
Results: report.Results{
|
||||
{
|
||||
Target: "alpine:3.11",
|
||||
Vulnerabilities: []types.DetectedVulnerability{
|
||||
{
|
||||
VulnerabilityID: "CVE-2019-9999",
|
||||
PkgName: "vim",
|
||||
InstalledVersion: "1.2.3",
|
||||
FixedVersion: "1.2.4",
|
||||
Layer: ftypes.Layer{
|
||||
Digest: "sha256:5216338b40a7b96416b8b9858974bbe4acc3096ee60acbc4dfb1ee02aecceb10",
|
||||
DiffID: "sha256:b2a1a2d80bf0c747a4f6b0ca6af5eef23f043fcdb1ed4f3a3e750aef2dc68079",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Target: "node-app/package-lock.json",
|
||||
Vulnerabilities: []types.DetectedVulnerability{
|
||||
{
|
||||
VulnerabilityID: "CVE-2019-11358",
|
||||
PkgName: "jquery",
|
||||
InstalledVersion: "3.3.9",
|
||||
FixedVersion: ">=3.4.0",
|
||||
{
|
||||
Target: "node-app/package-lock.json",
|
||||
Vulnerabilities: []types.DetectedVulnerability{
|
||||
{
|
||||
VulnerabilityID: "CVE-2019-11358",
|
||||
PkgName: "jquery",
|
||||
InstalledVersion: "3.3.9",
|
||||
FixedVersion: ">=3.4.0",
|
||||
},
|
||||
},
|
||||
Type: "npm",
|
||||
},
|
||||
Type: "npm",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -172,7 +179,7 @@ func TestScanner_ScanArtifact(t *testing.T) {
|
||||
mockArtifact.ApplyInspectExpectation(tt.inspectExpectation)
|
||||
|
||||
s := NewScanner(d, mockArtifact)
|
||||
gotResults, err := s.ScanArtifact(context.Background(), tt.args.options)
|
||||
got, err := s.ScanArtifact(context.Background(), tt.args.options)
|
||||
if tt.wantErr != "" {
|
||||
require.NotNil(t, err, tt.name)
|
||||
require.Contains(t, err.Error(), tt.wantErr, tt.name)
|
||||
@@ -181,7 +188,7 @@ func TestScanner_ScanArtifact(t *testing.T) {
|
||||
require.NoError(t, err, tt.name)
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.wantResults, gotResults, tt.name)
|
||||
assert.Equal(t, tt.want, got, tt.name)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user