Skip to content

Commit

Permalink
Remove duplicates from output, and remove scorecard vulnerability e2e…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
another-rex committed Dec 9, 2022
1 parent 7bda3a9 commit f405955
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
18 changes: 18 additions & 0 deletions clients/osv.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,28 @@ func (v osvClient) HasUnfixedVulnerabilities(
}

response := VulnerabilitiesResponse{}

for _, v := range res.Flatten() {
response.Vulnerabilities = append(response.Vulnerabilities, Vulnerability{
ID: v.Vulnerability.ID,
})
// Remove duplicate vulnerability IDs for now as we don't report information
// on the source of each vulnerability yet, therefore having multiple identical
// vuln IDs might be confusing.
response.Vulnerabilities = removeDuplicate(response.Vulnerabilities)
}
return response, nil
}

// RemoveDuplicate removes duplicate entries from a slice
func removeDuplicate[T comparable](sliceList []T) []T {
allKeys := make(map[T]bool)
list := []T{}
for _, item := range sliceList {
if _, value := allKeys[item]; !value {
allKeys[item] = true
list = append(list, item)
}
}
return list
}
29 changes: 0 additions & 29 deletions e2e/vulnerabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,6 @@ import (

var _ = Describe("E2E TEST:"+checks.CheckVulnerabilities, func() {
Context("E2E TEST:Validating vulnerabilities status", func() {
It("Should return that there are no vulnerabilities", func() {
repo, err := githubrepo.MakeGithubRepo("ossf/scorecard")
Expect(err).Should(BeNil())
repoClient := githubrepo.CreateGithubRepoClient(context.Background(), logger)
err = repoClient.InitRepo(repo, clients.HeadSHA, 0)
Expect(err).Should(BeNil())

dl := scut.TestDetailLogger{}
req := checker.CheckRequest{
Ctx: context.Background(),
RepoClient: repoClient,
VulnerabilitiesClient: clients.DefaultVulnerabilitiesClient(),
Repo: repo,
Dlogger: &dl,
}
expected := scut.TestReturn{
Error: nil,
Score: checker.MaxResultScore,
NumberOfWarn: 0,
NumberOfInfo: 0,
NumberOfDebug: 0,
}

result := checks.Vulnerabilities(&req)
// New version.
Expect(scut.ValidateTestReturn(nil, "no osv vulnerabilities", &expected, &result, &dl)).Should(BeTrue())
Expect(repoClient.Close()).Should(BeNil())
})

It("Should return that there are vulnerabilities", func() {
repo, err := githubrepo.MakeGithubRepo("ossf-tests/scorecard-check-vulnerabilities-open62541")
Expect(err).Should(BeNil())
Expand Down

0 comments on commit f405955

Please sign in to comment.