Skip to content

Commit

Permalink
Work on test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
djschleen authored Aug 14, 2024
1 parent 022eb43 commit 6dcbe71
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"ghcr.io/devcontainers-contrib/features/starship:1": {},
"ghcr.io/azutake/devcontainer-features/go-packages-install:0": {
"packages": [
"github.com/devops-kung-fu/hookz@latest",
"github.com/jandelgado/gcov2lcov@latest",
"github.com/kisielk/errcheck@latest",
"github.com/fzipp/gocyclo/cmd/gocyclo@latest",
Expand Down
2 changes: 2 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@
"args": [
"--provider=ossindex",
"--debug=true",
"--enrich=epss",
"--output=html",
"scan",
"./_TESTDATA_/sbom/railsgoat.cyclonedx.json"
]
Expand Down
38 changes: 38 additions & 0 deletions enrichers/epss/epss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ func TestEnrich(t *testing.T) {
Cve: "sonatype-2020-1214",
},
}

httpmock.Activate()
defer httpmock.DeactivateAndReset()

httpmock.RegisterResponder("GET", "https://api.first.org/data/v1/epss",
httpmock.NewBytesResponder(200, epssTestResponse()))

enriched, err := enricher.Enrich(vulnerabilities, nil)

assert.NoError(t, err)
Expand All @@ -48,3 +55,34 @@ func TestEnrich_Error(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "EPSS API request failed with status code")
}

func epssTestResponse() []byte {
response := `
[
// {
// "coordinates": "pkg:gem/[email protected]",
// "description": "TZInfo provides daylight savings aware transformations between times in different time zones.",
// "reference": "https://ossindex.sonatype.org/component/pkg:gem/[email protected]?utm_source=mozilla&utm_medium=integration&utm_content=5.0",
// "vulnerabilities": [
// {
// "id": "CVE-2022-31163",
// "displayName": "CVE-2022-31163",
// "title": "[CVE-2022-31163] CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')",
// "description": "TZInfo... ",
// "cvssScore": 8.1,
// "cvssVector": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H",
// "cwe": "CWE-22",
// "cve": "CVE-2022-31163",
// "reference": "https://ossindex.sonatype.org/vulnerability/CVE-2022-31163?component-type=gem&component-name=tzinfo&utm_source=mozilla&utm_medium=integration&utm_content=5.0",
// "externalReferences": [
// "http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2022-31163",
// "https://github.com/tzinfo/tzinfo/releases/tag/v0.3.61",
// "https://github.com/tzinfo/tzinfo/releases/tag/v1.2.10",
// "https://github.com/tzinfo/tzinfo/security/advisories/GHSA-5cm2-9h8c-rvfx"
// ]
// }
// ]
// }
]`
return []byte(response)
}
2 changes: 1 addition & 1 deletion lib/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestLoad_multiple_cyclonedx(t *testing.T) {

func Test_LoadIgnore(t *testing.T) {
SetupTest()
afs.WriteFile("test.ignore", []byte("test\ntest2"), 0644)
_ = afs.WriteFile("test.ignore", []byte("test\ntest2"), 0644)

cves, err := l.LoadIgnore("test.ignore")
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion lib/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *Scanner) scanPackages(purls []string) (response []models.Package, err e

for k, p := range response {
if len(p.Vulnerabilities) == 0 {
slices.Delete(response, k, k)
_ = slices.Delete(response, k, k)
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func TestScanner_enrichVulnerabilities(t *testing.T) {
},
}

//TODO: MOCK THIS OUT.
scanner.enrichVulnerabilities(response)

assert.Len(t, response[0].Vulnerabilities, 2)
Expand Down
1 change: 0 additions & 1 deletion providers/providerfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func NewProvider(name string) (provider models.Provider, err error) {
case "snyk":
provider = snyk.Provider{}
default:

err = fmt.Errorf("%s is not a valid provider type", name)
}
return
Expand Down

0 comments on commit 6dcbe71

Please sign in to comment.