Repository: aquasecurity/starboard
Pull request #66 (2020-06-21 21:31:47)

fix(trivy): Parse output of scanning scratch images
Resolves: #65

Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>

codecov[bot]: # [Codecov](https://codecov.io/gh/aquasecurity/starboard/pull/66?src=pr&el=h1) Report
> Merging [#66](https://codecov.io/gh/aquasecurity/starboard/pull/66?src=pr&el=desc) into [master](https://codecov.io/gh/aquasecurity/starboard/commit/e0c30b3d6383139193ba8b037431a12cfcf65eb3&el=desc) will **increase** coverage by `0.31%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/aquasecurity/starboard/pull/66/graphs/tree.svg?width=650&height=150&src=pr&token=qqTGKAJ0Wb)](https://codecov.io/gh/aquasecurity/starboard/pull/66?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #66      +/-   ##
==========================================
+ Coverage   10.77%   11.08%   +0.31%     
==========================================
  Files          23       23              
  Lines         854      857       +3     
==========================================
+ Hits           92       95       +3     
  Misses        757      757              
  Partials        5        5              
```


| [Impacted Files](https://codecov.io/gh/aquasecurity/starboard/pull/66?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/find/vulnerabilities/trivy/converter.go](https://codecov.io/gh/aquasecurity/starboard/pull/66/diff?src=pr&el=tree#diff-cGtnL2ZpbmQvdnVsbmVyYWJpbGl0aWVzL3RyaXZ5L2NvbnZlcnRlci5nbw==) | `78.46% <100.00%> (+1.04%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/aquasecurity/starboard/pull/66?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/aquasecurity/starboard/pull/66?src=pr&el=footer). Last update [e0c30b3...bab43e8](https://codecov.io/gh/aquasecurity/starboard/pull/66?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/pkg/find/vulnerabilities/trivy/converter.go b/pkg/find/vulnerabilities/trivy/converter.go
index 0bd5e87..6ed1f21 100644
--- a/pkg/find/vulnerabilities/trivy/converter.go
+++ b/pkg/find/vulnerabilities/trivy/converter.go
@@ -53,11 +53,15 @@ func (c *converter) skippingNoisyOutputReader(input io.Reader) (io.Reader, error
 	if index > 0 {
 		return strings.NewReader(inputAsString[index:]), nil
 	}
+	index = strings.LastIndex(inputAsString, "null")
+	if index > 0 {
+		return strings.NewReader(inputAsString[index:]), nil
+	}
 	return strings.NewReader(inputAsString), nil
 }
 
 func (c *converter) convert(reports []ScanReport) starboard.VulnerabilityReport {
-	var vulnerabilities []starboard.VulnerabilityItem
+	vulnerabilities := make([]starboard.VulnerabilityItem, 0)
 
 	for _, report := range reports {
 		for _, sr := range report.Vulnerabilities {


Test patch:
diff --git a/pkg/find/vulnerabilities/trivy/converter_test.go b/pkg/find/vulnerabilities/trivy/converter_test.go
index a5c62c8..996340d 100644
--- a/pkg/find/vulnerabilities/trivy/converter_test.go
+++ b/pkg/find/vulnerabilities/trivy/converter_test.go
@@ -102,6 +102,28 @@ func TestConverter_Convert(t *testing.T) {
 			expectedError:  nil,
 			expectedReport: sampleReport,
 		},
+		{
+			name: "Should convert vulnerability report in JSON format when OS is not detected",
+			input: `2020-06-21T23:10:15.162+0200	WARN	OS is not detected and vulnerabilities in OS packages are not detected.
+null`,
+			expectedError: nil,
+			expectedReport: starboard.VulnerabilityReport{
+				Scanner: starboard.Scanner{
+					Name:    "Trivy",
+					Vendor:  "Aqua Security",
+					Version: "0.9.1",
+				},
+				Summary: starboard.VulnerabilitySummary{
+					CriticalCount: 0,
+					HighCount:     0,
+					MediumCount:   0,
+					LowCount:      0,
+					NoneCount:     0,
+					UnknownCount:  0,
+				},
+				Vulnerabilities: []starboard.VulnerabilityItem{},
+			},
+		},
 	}
 
 	for _, tc := range testCases {