Skip to content

Commit

Permalink
try using probe registration data
Browse files Browse the repository at this point in the history
Signed-off-by: Spencer Schrock <[email protected]>
  • Loading branch information
spencerschrock committed Feb 9, 2024
1 parent 26acbd6 commit 301d072
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 94 deletions.
8 changes: 8 additions & 0 deletions internal/probes/probes.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ func Register(probe Probe) error {
registered[probe.Name] = probe
return nil
}

func Get(name string) (Probe, error) {
p, ok := registered[name]
if !ok {
return Probe{}, errors.CreateInternal(errors.ErrorUnsupportedCheck, "probe not found")
}
return p, nil
}
9 changes: 4 additions & 5 deletions pkg/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/ossf/scorecard/v4/clients"
sce "github.com/ossf/scorecard/v4/errors"
"github.com/ossf/scorecard/v4/finding"
proberegistration "github.com/ossf/scorecard/v4/internal/probes"
"github.com/ossf/scorecard/v4/options"
"github.com/ossf/scorecard/v4/probes"
"github.com/ossf/scorecard/v4/probes/zrunner"
Expand Down Expand Up @@ -198,14 +199,12 @@ func runEnabledProbes(request *checker.CheckRequest,

probeFindings := make([]finding.Finding, 0)
for _, probeName := range probesToRun {
// Get the probe Run func
probeRunner, err := probes.GetProbeRunner(probeName)
probe, err := proberegistration.Get(probeName)
if err != nil {
msg := fmt.Sprintf("could not find probe: %s", probeName)
return sce.WithMessage(sce.ErrScorecardInternal, msg)
return err
}
// Run probe
findings, _, err := probeRunner(&ret.RawResults)
findings, _, err := probe.Implementation(&ret.RawResults)
if err != nil {
return sce.WithMessage(sce.ErrScorecardInternal, "ending run")
}
Expand Down
22 changes: 14 additions & 8 deletions pkg/scorecard_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import (
docChecks "github.com/ossf/scorecard/v4/docs/checks"
sce "github.com/ossf/scorecard/v4/errors"
"github.com/ossf/scorecard/v4/finding"
proberegistration "github.com/ossf/scorecard/v4/internal/probes"
"github.com/ossf/scorecard/v4/log"
"github.com/ossf/scorecard/v4/options"
spol "github.com/ossf/scorecard/v4/policy"
"github.com/ossf/scorecard/v4/probes"
)

// ScorecardInfo contains information about the scorecard code that was run.
Expand Down Expand Up @@ -313,14 +313,20 @@ func assignRawData(probeCheckName string, request *checker.CheckRequest, ret *Sc
}

func populateRawResults(request *checker.CheckRequest, probesToRun []string, ret *ScorecardResult) error {
probeCheckNames := make([]string, 0)
seen := map[string]bool{}
for _, probeName := range probesToRun {
probeCheckName := probes.CheckMap[probeName]
if !contains(probeCheckNames, probeCheckName) {
probeCheckNames = append(probeCheckNames, probeCheckName)
err := assignRawData(probeCheckName, request, ret)
if err != nil {
return err
p, err := proberegistration.Get(probeName)
if err != nil {
return err
}
for _, checkName := range p.RequiredRawData {
checkName := string(checkName)
if !seen[checkName] {
err := assignRawData(checkName, request, ret)
if err != nil {
return err
}
seen[checkName] = true
}
}
}
Expand Down
81 changes: 0 additions & 81 deletions probes/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,80 +155,6 @@ var (
releasesHaveProvenance.Run,
}

probeRunners = map[string]func(*checker.RawResults) ([]finding.Finding, string, error){
securityPolicyPresent.Probe: securityPolicyPresent.Run,
securityPolicyContainsLinks.Probe: securityPolicyContainsLinks.Run,
securityPolicyContainsVulnerabilityDisclosure.Probe: securityPolicyContainsVulnerabilityDisclosure.Run,
securityPolicyContainsText.Probe: securityPolicyContainsText.Run,
toolRenovateInstalled.Probe: toolRenovateInstalled.Run,
toolDependabotInstalled.Probe: toolDependabotInstalled.Run,
toolPyUpInstalled.Probe: toolPyUpInstalled.Run,
fuzzedWithOSSFuzz.Probe: fuzzedWithOSSFuzz.Run,
fuzzedWithGoNative.Probe: fuzzedWithGoNative.Run,
fuzzedWithPythonAtheris.Probe: fuzzedWithPythonAtheris.Run,
fuzzedWithCLibFuzzer.Probe: fuzzedWithCLibFuzzer.Run,
fuzzedWithCppLibFuzzer.Probe: fuzzedWithCppLibFuzzer.Run,
fuzzedWithSwiftLibFuzzer.Probe: fuzzedWithSwiftLibFuzzer.Run,
fuzzedWithRustCargofuzz.Probe: fuzzedWithRustCargofuzz.Run,
fuzzedWithJavaJazzerFuzzer.Probe: fuzzedWithJavaJazzerFuzzer.Run,
fuzzedWithClusterFuzzLite.Probe: fuzzedWithClusterFuzzLite.Run,
fuzzedWithPropertyBasedHaskell.Probe: fuzzedWithPropertyBasedHaskell.Run,
fuzzedWithPropertyBasedTypescript.Probe: fuzzedWithPropertyBasedTypescript.Run,
fuzzedWithPropertyBasedJavascript.Probe: fuzzedWithPropertyBasedJavascript.Run,
packagedWithAutomatedWorkflow.Probe: packagedWithAutomatedWorkflow.Run,
hasLicenseFile.Probe: hasLicenseFile.Run,
hasFSFOrOSIApprovedLicense.Probe: hasFSFOrOSIApprovedLicense.Run,
hasLicenseFileAtTopDir.Probe: hasLicenseFileAtTopDir.Run,
contributorsFromOrgOrCompany.Probe: contributorsFromOrgOrCompany.Run,
hasOSVVulnerabilities.Probe: hasOSVVulnerabilities.Run,
sastToolCodeQLInstalled.Probe: sastToolCodeQLInstalled.Run,
sastToolRunsOnAllCommits.Probe: sastToolRunsOnAllCommits.Run,
sastToolSonarInstalled.Probe: sastToolSonarInstalled.Run,
hasDangerousWorkflowScriptInjection.Probe: hasDangerousWorkflowScriptInjection.Run,
hasDangerousWorkflowUntrustedCheckout.Probe: hasDangerousWorkflowUntrustedCheckout.Run,
notArchived.Probe: notArchived.Run,
hasRecentCommits.Probe: hasRecentCommits.Run,
issueActivityByProjectMember.Probe: issueActivityByProjectMember.Run,
notCreatedRecently.Probe: notCreatedRecently.Run,
}

CheckMap = map[string]string{
securityPolicyPresent.Probe: "Security-Policy",
securityPolicyContainsLinks.Probe: "Security-Policy",
securityPolicyContainsVulnerabilityDisclosure.Probe: "Security-Policy",
securityPolicyContainsText.Probe: "Security-Policy",
toolRenovateInstalled.Probe: "Dependency-Update-Tool",
toolDependabotInstalled.Probe: "Dependency-Update-Tool",
toolPyUpInstalled.Probe: "Dependency-Update-Tool",
fuzzedWithOSSFuzz.Probe: "Fuzzing",
fuzzedWithGoNative.Probe: "Fuzzing",
fuzzedWithPythonAtheris.Probe: "Fuzzing",
fuzzedWithCLibFuzzer.Probe: "Fuzzing",
fuzzedWithCppLibFuzzer.Probe: "Fuzzing",
fuzzedWithSwiftLibFuzzer.Probe: "Fuzzing",
fuzzedWithRustCargofuzz.Probe: "Fuzzing",
fuzzedWithJavaJazzerFuzzer.Probe: "Fuzzing",
fuzzedWithClusterFuzzLite.Probe: "Fuzzing",
fuzzedWithPropertyBasedHaskell.Probe: "Fuzzing",
fuzzedWithPropertyBasedTypescript.Probe: "Fuzzing",
fuzzedWithPropertyBasedJavascript.Probe: "Fuzzing",
packagedWithAutomatedWorkflow.Probe: "Packaging",
hasLicenseFile.Probe: "License",
hasFSFOrOSIApprovedLicense.Probe: "License",
hasLicenseFileAtTopDir.Probe: "License",
contributorsFromOrgOrCompany.Probe: "Contributors",
hasOSVVulnerabilities.Probe: "Vulnerabilities",
sastToolCodeQLInstalled.Probe: "SAST",
sastToolRunsOnAllCommits.Probe: "SAST",
sastToolSonarInstalled.Probe: "SAST",
hasDangerousWorkflowScriptInjection.Probe: "Dangerous-Workflow",
hasDangerousWorkflowUntrustedCheckout.Probe: "Dangerous-Workflow",
notArchived.Probe: "Maintained",
hasRecentCommits.Probe: "Maintained",
issueActivityByProjectMember.Probe: "Maintained",
notCreatedRecently.Probe: "Maintained",
}

errProbeNotFound = errors.New("probe not found")
)

Expand All @@ -244,13 +170,6 @@ func init() {
})
}

func GetProbeRunner(probeName string) (func(*checker.RawResults) ([]finding.Finding, string, error), error) {
if runner, ok := probeRunners[probeName]; ok {
return runner, nil
}
return nil, errProbeNotFound
}

func concatMultipleProbes(slices [][]ProbeImpl) []ProbeImpl {
var totalLen int
for _, s := range slices {
Expand Down

0 comments on commit 301d072

Please sign in to comment.