mirror of
https://github.com/ossf/scorecard.git
synced 2024-10-26 10:28:10 +03:00
🌱 Refactor the osv check into a interface
Refactor the osv check into a interface for that it can be tested.
This commit is contained in:
parent
c11772788a
commit
c8f15a495e
@ -41,9 +41,16 @@ type osvResponse struct {
|
||||
} `json:"vulns"`
|
||||
}
|
||||
|
||||
// Vulnerabilities cheks for vulnerabilities in api.osv.dev.
|
||||
type Vulnerabilities interface {
|
||||
HasUnfixedVulnerabilities(c *checker.CheckRequest) checker.CheckResult
|
||||
}
|
||||
type vulns struct{}
|
||||
|
||||
//nolint:gochecknoinits
|
||||
func init() {
|
||||
registerCheck(CheckVulnerabilities, HasUnfixedVulnerabilities)
|
||||
v := &vulns{}
|
||||
registerCheck(CheckVulnerabilities, v.HasUnfixedVulnerabilities)
|
||||
}
|
||||
|
||||
func (resp *osvResponse) getVulnerabilities() []string {
|
||||
@ -54,8 +61,13 @@ func (resp *osvResponse) getVulnerabilities() []string {
|
||||
return ids
|
||||
}
|
||||
|
||||
// NewVulnerabilities creates a new Vulnerabilities check.
|
||||
func NewVulnerabilities() Vulnerabilities {
|
||||
return &vulns{}
|
||||
}
|
||||
|
||||
// HasUnfixedVulnerabilities runs Vulnerabilities check.
|
||||
func HasUnfixedVulnerabilities(c *checker.CheckRequest) checker.CheckResult {
|
||||
func (v *vulns) HasUnfixedVulnerabilities(c *checker.CheckRequest) checker.CheckResult {
|
||||
commits, err := c.RepoClient.ListCommits()
|
||||
if err != nil {
|
||||
e := sce.WithMessage(sce.ErrScorecardInternal, "Client.Repositories.ListCommits")
|
||||
|
@ -49,7 +49,8 @@ var _ = Describe("E2E TEST:Vulnerabilities", func() {
|
||||
NumberOfInfo: 0,
|
||||
NumberOfDebug: 0,
|
||||
}
|
||||
result := checks.HasUnfixedVulnerabilities(&req)
|
||||
|
||||
result := checks.NewVulnerabilities().HasUnfixedVulnerabilities(&req)
|
||||
// UPGRADEv2: to remove.
|
||||
// Old version.
|
||||
Expect(result.Error).Should(BeNil())
|
||||
@ -80,7 +81,7 @@ var _ = Describe("E2E TEST:Vulnerabilities", func() {
|
||||
NumberOfInfo: 0,
|
||||
NumberOfDebug: 0,
|
||||
}
|
||||
result := checks.HasUnfixedVulnerabilities(&checkRequest)
|
||||
result := checks.NewVulnerabilities().HasUnfixedVulnerabilities(&checkRequest)
|
||||
// UPGRADEv2: to remove.
|
||||
// Old version.
|
||||
Expect(result.Error).Should(BeNil())
|
||||
|
Loading…
Reference in New Issue
Block a user