Skip to content

Commit

Permalink
remove the 'totalWebhooks' value from findings
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Korczynski <[email protected]>
  • Loading branch information
AdamKorcz committed Dec 5, 2023
1 parent d59047a commit 2dc1b1e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 60 deletions.
2 changes: 1 addition & 1 deletion checks/evaluation/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Webhooks(name string,

var webhooksWithNoSecret int

totalWebhooks := findings[0].Values["totalWebhooks"]
totalWebhooks := len(findings)

for i := range findings {
f := &findings[i]
Expand Down
111 changes: 60 additions & 51 deletions checks/evaluation/webhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ func TestWebhooks(t *testing.T) {
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
Values: map[string]int{
"totalWebhooks": 1,
},
},
},
result: scut.TestReturn{
Expand All @@ -75,9 +72,10 @@ func TestWebhooks(t *testing.T) {
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 2,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
},
result: scut.TestReturn{
Expand All @@ -90,16 +88,22 @@ func TestWebhooks(t *testing.T) {
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 5,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 5,
},
},
},
result: scut.TestReturn{
Expand All @@ -112,9 +116,50 @@ func TestWebhooks(t *testing.T) {
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 12,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomePositive,
},
},
result: scut.TestReturn{
Expand All @@ -127,86 +172,50 @@ func TestWebhooks(t *testing.T) {
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 12,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 12,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 12,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 12,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 12,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 12,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 12,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 12,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 12,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 12,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 12,
},
},
{
Probe: "webhooksUseSecrets",
Outcome: finding.OutcomeNegative,
Values: map[string]int{
"totalWebhooks": 12,
},
},
},
result: scut.TestReturn{
Expand Down
2 changes: 1 addition & 1 deletion probes/webhooksUseSecrets/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ motivation: >
implementation: >
The probe checks all webhooks of a project and checks whether each uses secret authentication.
outcome:
- If the project has any webhooks without secret authorization, the probe returns as many OutcomeNegative (0) as the project has webhooks without secret authorization. All findings include the value "totalWebhooks" which is the total number of webhooks that the project has. The finding also includes the path to the webhook.
- If the project has any webhooks without secret authorization, the probe returns as many OutcomeNegative (0) as the project has webhooks without secret authorization and as many OutcomePositive as there are webhooks with secret authorization. All findings include the path to the webhook.
- If the project does not have any webhooks without secret authorization, the probe returns one OutcomePositive (1).
remediation:
effort: Low
Expand Down
9 changes: 2 additions & 7 deletions probes/webhooksUseSecrets/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
}

Check warning on line 35 in probes/webhooksUseSecrets/impl.go

View check run for this annotation

Codecov / codecov/patch

probes/webhooksUseSecrets/impl.go#L34-L35

Added lines #L34 - L35 were not covered by tests

r := raw.WebhookResults
totalWebhooks := len(r.Webhooks)
var findings []finding.Finding

if len(r.Webhooks) == 0 {
Expand All @@ -57,9 +56,7 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
if err != nil {
return nil, Probe, fmt.Errorf("create finding: %w", err)
}

Check warning on line 58 in probes/webhooksUseSecrets/impl.go

View check run for this annotation

Codecov / codecov/patch

probes/webhooksUseSecrets/impl.go#L57-L58

Added lines #L57 - L58 were not covered by tests
f = f.WithValues(map[string]int{
"totalWebhooks": totalWebhooks,
}).WithLocation(&finding.Location{
f = f.WithLocation(&finding.Location{
Path: hook.Path,
})
findings = append(findings, *f)
Expand All @@ -70,9 +67,7 @@ func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
if err != nil {
return nil, Probe, fmt.Errorf("create finding: %w", err)
}

Check warning on line 69 in probes/webhooksUseSecrets/impl.go

View check run for this annotation

Codecov / codecov/patch

probes/webhooksUseSecrets/impl.go#L68-L69

Added lines #L68 - L69 were not covered by tests
f = f.WithValues(map[string]int{
"totalWebhooks": totalWebhooks,
}).WithLocation(&finding.Location{
f = f.WithLocation(&finding.Location{
Path: hook.Path,
})
findings = append(findings, *f)
Expand Down

0 comments on commit 2dc1b1e

Please sign in to comment.