Skip to content

Commit

Permalink
Rebase and bring back 'Test_generateOwnerToDisplay'
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Korczynski <[email protected]>
  • Loading branch information
AdamKorcz committed Feb 8, 2024
1 parent 6d5d46b commit 153fb4e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 31 deletions.
61 changes: 45 additions & 16 deletions checks/evaluation/pinned_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -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),
},
},
{
Expand All @@ -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),
},
},
},
Expand All @@ -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),
},
},
{
Expand All @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand Down Expand Up @@ -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)
}
})
}
}
19 changes: 4 additions & 15 deletions probes/pinsDependencies/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -132,8 +121,8 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
if rr.Remediation != nil {
f.Remediation = ruleRemToProbeRem(rr.Remediation)
}

Check warning on line 123 in probes/pinsDependencies/impl.go

View check run for this annotation

Codecov / codecov/patch

probes/pinsDependencies/impl.go#L122-L123

Added lines #L122 - L123 were not covered by tests
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 {
Expand All @@ -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)
}
Expand Down

0 comments on commit 153fb4e

Please sign in to comment.