Skip to content

Commit 51787e2

Browse files
committed
remove dead code
1 parent 43adfe6 commit 51787e2

File tree

2 files changed

+0
-88
lines changed

2 files changed

+0
-88
lines changed

pkg/detectors/falsepositives.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package detectors
22

33
import (
44
_ "embed"
5-
"fmt"
65
"math"
76
"strings"
87
"unicode"
@@ -172,30 +171,3 @@ func FilterResultsWithEntropy(ctx context.Context, results []Result, entropy flo
172171
}
173172
return filteredResults
174173
}
175-
176-
// FilterKnownFalsePositives filters out known false positives from the results.
177-
func FilterKnownFalsePositives(ctx context.Context, detector Detector, results []Result) []Result {
178-
var filteredResults []Result
179-
180-
isFalsePositive := GetFalsePositiveCheck(detector)
181-
182-
for _, result := range results {
183-
if len(result.Raw) == 0 {
184-
ctx.Logger().Error(fmt.Errorf("empty raw"), "Skipping result: invalid")
185-
continue
186-
}
187-
188-
if result.Verified {
189-
filteredResults = append(filteredResults, result)
190-
continue
191-
}
192-
193-
if isFp, reason := isFalsePositive(result); isFp {
194-
ctx.Logger().V(4).Info("Skipping result: false positive", "result", string(result.Raw), "reason", reason)
195-
continue
196-
}
197-
filteredResults = append(filteredResults, result)
198-
}
199-
200-
return filteredResults
201-
}

pkg/detectors/falsepositives_test.go

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,12 @@
11
package detectors
22

33
import (
4-
"context"
54
_ "embed"
65
"testing"
76

87
"github.com/stretchr/testify/assert"
9-
10-
logContext "github.com/trufflesecurity/trufflehog/v3/pkg/context"
11-
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
128
)
139

14-
type fakeDetector struct{}
15-
type customFalsePositiveChecker struct{ fakeDetector }
16-
17-
func (d fakeDetector) FromData(ctx context.Context, verify bool, data []byte) ([]Result, error) {
18-
return nil, nil
19-
}
20-
21-
func (d fakeDetector) Keywords() []string {
22-
return nil
23-
}
24-
25-
func (d fakeDetector) Type() detectorspb.DetectorType {
26-
return detectorspb.DetectorType(0)
27-
}
28-
29-
func (f fakeDetector) Description() string { return "" }
30-
31-
func (d customFalsePositiveChecker) IsFalsePositive(result Result) (bool, string) {
32-
return IsKnownFalsePositive(string(result.Raw), map[FalsePositive]struct{}{"a specific magic string": {}}, false)
33-
}
34-
35-
func TestFilterKnownFalsePositives_DefaultLogic(t *testing.T) {
36-
results := []Result{
37-
{Raw: []byte("00000")}, // "default" false positive list
38-
{Raw: []byte("number")}, // from wordlist
39-
// from uuid list
40-
{Raw: []byte("00000000-0000-0000-0000-000000000000")},
41-
{Raw: []byte("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")},
42-
// real secrets
43-
{Raw: []byte("hga8adshla3434g")},
44-
{Raw: []byte("f795f7db-2dfe-4095-96f3-8f8370c735f9")},
45-
}
46-
expected := []Result{
47-
{Raw: []byte("hga8adshla3434g")},
48-
{Raw: []byte("f795f7db-2dfe-4095-96f3-8f8370c735f9")},
49-
}
50-
filtered := FilterKnownFalsePositives(logContext.Background(), fakeDetector{}, results)
51-
assert.ElementsMatch(t, expected, filtered)
52-
}
53-
54-
func TestFilterKnownFalsePositives_CustomLogic(t *testing.T) {
55-
results := []Result{
56-
{Raw: []byte("a specific magic string")}, // specific target
57-
{Raw: []byte("00000")}, // "default" false positive list
58-
{Raw: []byte("number")}, // from wordlist
59-
{Raw: []byte("hga8adshla3434g")}, // real secret
60-
}
61-
expected := []Result{
62-
{Raw: []byte("00000")},
63-
{Raw: []byte("number")},
64-
{Raw: []byte("hga8adshla3434g")},
65-
}
66-
filtered := FilterKnownFalsePositives(logContext.Background(), customFalsePositiveChecker{}, results)
67-
assert.ElementsMatch(t, expected, filtered)
68-
}
69-
7010
func TestIsFalsePositive(t *testing.T) {
7111
type args struct {
7212
match string

0 commit comments

Comments
 (0)