diff --git a/checks/evaluation/pinned_dependencies_test.go b/checks/evaluation/pinned_dependencies_test.go index a855cec2e2d4..5af1bead9db6 100644 --- a/checks/evaluation/pinned_dependencies_test.go +++ b/checks/evaluation/pinned_dependencies_test.go @@ -249,8 +249,8 @@ func Test_PinningDependencies(t *testing.T) { LineStart: &testLineStart, Snippet: &testSnippet, }, - Values: map[string]int{ - "dependencyType": 6, // pip type + Values: map[string]string{ + "dependencyType": string(checker.DependencyUseTypePipCommand), }, }, }, @@ -272,8 +272,8 @@ func Test_PinningDependencies(t *testing.T) { LineEnd: &testLineEnd, Snippet: &testSnippet, }, - Values: map[string]int{ - "dependencyType": 6, // pip type + Values: map[string]string{ + "dependencyType": string(checker.DependencyUseTypePipCommand), }, }, }, @@ -296,8 +296,8 @@ func Test_PinningDependencies(t *testing.T) { LineEnd: &testLineEnd, Snippet: &testSnippet, }, - Values: map[string]int{ - "dependencyType": 6, // pip type + Values: map[string]string{ + "dependencyType": string(checker.DependencyUseTypePipCommand), }, }, }, @@ -319,8 +319,8 @@ func Test_PinningDependencies(t *testing.T) { LineEnd: &testLineEnd, Snippet: &testSnippet, }, - Values: map[string]int{ - "dependencyType": 6, // pip type + Values: map[string]string{ + "dependencyType": string(checker.DependencyUseTypePipCommand), }, }, { @@ -333,8 +333,8 @@ func Test_PinningDependencies(t *testing.T) { LineEnd: &testLineEnd, Snippet: &testSnippet, }, - Values: map[string]int{ - "dependencyType": 6, // pip type + Values: map[string]string{ + "dependencyType": string(checker.DependencyUseTypePipCommand), }, }, }, @@ -357,8 +357,8 @@ func Test_PinningDependencies(t *testing.T) { LineEnd: &testLineEnd, Snippet: &testSnippet, }, - Values: map[string]int{ - "dependencyType": 6, // pip type + Values: map[string]string{ + "dependencyType": string(checker.DependencyUseTypePipCommand), }, }, { @@ -371,8 +371,8 @@ func Test_PinningDependencies(t *testing.T) { LineEnd: &testLineEnd, Snippet: &testSnippet, }, - Values: map[string]int{ - "dependencyType": 3, // go type + Values: map[string]string{ + "dependencyType": string(checker.DependencyUseTypeGoCommand), }, }, }, @@ -395,8 +395,8 @@ func Test_PinningDependencies(t *testing.T) { LineEnd: &testLineEnd, Snippet: &testSnippet, }, - Values: map[string]int{ - "dependencyType": 0, // GH Action type + Values: map[string]string{ + "dependencyType": string(checker.DependencyUseTypeGHAction), }, }, }, @@ -703,3 +703,32 @@ func TestUpdatePinningResults(t *testing.T) { }) } } + +func Test_generateOwnerToDisplay(t *testing.T) { + t.Parallel() + tests := []struct { //nolint:govet + name string + gitHubOwned bool + want string + }{ + { + name: "returns GitHub if gitHubOwned is true", + gitHubOwned: true, + want: "GitHub-owned GitHubAction", + }, + { + name: "returns GitHub if gitHubOwned is false", + gitHubOwned: false, + want: "third-party GitHubAction", + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + if got := generateOwnerToDisplay(tt.gitHubOwned); got != tt.want { + t.Errorf("generateOwnerToDisplay() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/probes/pinsDependencies/impl.go b/probes/pinsDependencies/impl.go index 1b16ce27a4ec..8404f42e25f0 100644 --- a/probes/pinsDependencies/impl.go +++ b/probes/pinsDependencies/impl.go @@ -36,17 +36,6 @@ const ( DepTypeKey = "dependencyType" ) -var dependencyTypes = map[checker.DependencyUseType]int{ - checker.DependencyUseTypeGHAction: 0, - checker.DependencyUseTypeDockerfileContainerImage: 1, - checker.DependencyUseTypeDownloadThenRun: 2, - checker.DependencyUseTypeGoCommand: 3, - checker.DependencyUseTypeChocoCommand: 4, - checker.DependencyUseTypeNpmCommand: 5, - checker.DependencyUseTypePipCommand: 6, - checker.DependencyUseTypeNugetCommand: 7, -} - func Run(raw *checker.RawResults) ([]finding.Finding, string, error) { if raw == nil { return nil, "", fmt.Errorf("%w: raw", uerror.ErrNil) @@ -132,8 +121,8 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) { if rr.Remediation != nil { f.Remediation = ruleRemToProbeRem(rr.Remediation) } - f = f.WithValues(map[string]int{ - DepTypeKey: dependencyTypes[rr.Type], + f = f.WithValues(map[string]string{ + DepTypeKey: string(rr.Type), }) findings = append(findings, *f) } else { @@ -149,8 +138,8 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) { Outcome: finding.OutcomePositive, Location: loc, } - f = f.WithValues(map[string]int{ - DepTypeKey: dependencyTypes[rr.Type], + f = f.WithValues(map[string]string{ + DepTypeKey: string(rr.Type), }) findings = append(findings, *f) }