Skip to content

Commit

Permalink
remove positiveOutcome() and length check
Browse files Browse the repository at this point in the history
Signed-off-by: AdamKorcz <[email protected]>
  • Loading branch information
AdamKorcz committed Oct 3, 2023
1 parent d1d8f28 commit 3386857
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
19 changes: 4 additions & 15 deletions checks/evaluation/binary_artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func BinaryArtifacts(name string,
hasBinaryArtifacts.Probe,
}

err := validateFindings(findings, expectedProbes)
if err != nil {
return checker.CreateRuntimeErrorResult(name, err)
if !finding.UniqueProbesEqual(findings, expectedProbes) {
e := sce.WithMessage(sce.ErrScorecardInternal, "invalid probe results")
return checker.CreateRuntimeErrorResult(name, e)
}

if findings[0].Outcome == finding.OutcomePositive {
Expand All @@ -50,15 +50,4 @@ func BinaryArtifacts(name string,
}

return checker.CreateResultWithScore(name, "binaries present in source code", score)
}

func validateFindings(findings []finding.Finding, expectedProbes []string) error {
if !finding.UniqueProbesEqual(findings, expectedProbes) {
return sce.WithMessage(sce.ErrScorecardInternal, "invalid probe results")
}

if len(findings) == 0 {
return sce.WithMessage(sce.ErrScorecardInternal, "found 0 findings. Should not happen")
}
return nil
}
}
20 changes: 8 additions & 12 deletions probes/hasBinaryArtifacts/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {

// Apply the policy evaluation.
if r.Files == nil || len(r.Files) == 0 {
return positiveOutcome()
f, err := finding.NewWith(fs, Probe,
"Repository does not have binary artifacts.", nil,
finding.OutcomePositive)
if err != nil {
return nil, Probe, fmt.Errorf("create finding: %w", err)
}
return []finding.Finding{*f}, Probe, nil
}

var findings []finding.Finding
Expand Down Expand Up @@ -66,14 +72,4 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
}

return findings, Probe, nil
}

func positiveOutcome() ([]finding.Finding, string, error) {
f, err := finding.NewWith(fs, Probe,
"Repository does not have binary artifacts.", nil,
finding.OutcomePositive)
if err != nil {
return nil, Probe, fmt.Errorf("create finding: %w", err)
}
return []finding.Finding{*f}, Probe, nil
}
}

0 comments on commit 3386857

Please sign in to comment.