Skip to content

Commit

Permalink
sort secret findings
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 committed Sep 6, 2022
1 parent 21ced14 commit da78e85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pkg/fanal/secret/scanner.go
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"os"
"regexp"
"sort"
"strings"
"sync"

Expand Down Expand Up @@ -337,7 +338,7 @@ type Match struct {
Location Location
}

func (s Scanner) Scan(args ScanArgs) types.Secret {
func (s *Scanner) Scan(args ScanArgs) types.Secret {
// Global allowed paths
if s.AllowPath(args.FilePath) {
return types.Secret{
Expand Down Expand Up @@ -401,6 +402,13 @@ func (s Scanner) Scan(args ScanArgs) types.Secret {
return types.Secret{}
}

sort.Slice(findings, func(i, j int) bool {
if findings[i].RuleID != findings[j].RuleID {
return findings[i].RuleID < findings[j].RuleID
}
return findings[i].Match < findings[j].Match
})

return types.Secret{
FilePath: args.FilePath,
Findings: findings,
Expand Down
2 changes: 1 addition & 1 deletion pkg/fanal/secret/scanner_test.go
Expand Up @@ -495,7 +495,7 @@ func TestSecretScanner(t *testing.T) {
inputFilePath: "testdata/aws-secrets.txt",
want: types.Secret{
FilePath: "testdata/aws-secrets.txt",
Findings: []types.SecretFinding{wantFinding5, wantFinding9, wantFinding10},
Findings: []types.SecretFinding{wantFinding5, wantFinding10, wantFinding9},
},
},
{
Expand Down

0 comments on commit da78e85

Please sign in to comment.