Skip to content

Find, verify, and analyze leaked credentials

Add some false positive tests #4703

Cody Rose7c7facf03271
diff --git a/pkg/detectors/falsepositives_test.go b/pkg/detectors/falsepositives_test.go
index 7d3cedafc..6884ebca4 100644
--- a/pkg/detectors/falsepositives_test.go
+++ b/pkg/detectors/falsepositives_test.go
@@ -32,6 +32,50 @@ func (d customFalsePositiveChecker) IsFalsePositive(result Result) (bool, string
return IsKnownFalsePositive(string(result.Raw), map[FalsePositive]struct{}{"a specific magic string": {}}, false)
}
+// This test validates that GetFalsePositiveCheck, when invoked on a detector that does not implement
+// CustomFalsePositiveChecker, returns a predicate that behaves as expected.
+func TestGetFalsePositiveCheck_DefaultLogic(t *testing.T) {
+ testCases := []struct {
+ raw string
+ isFalsePositive bool
+ }{
+ {"00000", true}, // "default" false positive list
+ {"number", true}, // from wordlist
+ {"00000000-0000-0000-0000-000000000000", true}, // from uuid list
+ {"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", true}, // from uuid list
+ {"hga8adshla3434g", false},
+ {"f795f7db-2dfe-4095-96f3-8f8370c735f9", false},
+ }
+
+ for _, tt := range testCases {
+ isFalsePositive, _ := GetFalsePositiveCheck(fakeDetector{})(Result{Raw: []byte(tt.raw)})
+ assert.Equal(t, tt.isFalsePositive, isFalsePositive, "secret %q had unexpected false positive status", tt.raw)
+ }
+}
+
+// This test validates that GetFalsePositiveCheck, when invoked on a detector that implements
+// CustomFalsePositiveChecker, returns a predicate that behaves as expected. (Specifically, the predicate should not
+// flag secrets that are present in the standard false positive lists.)
+func TestGetFalsePositiveCheck_CustomLogic(t *testing.T) {
+ testCases := []struct {
+ raw string
+ isFalsePositive bool
+ }{
+ {"a specific magic string", true}, // the specific value the custom checker is looking for
+ {"00000", false},
+ {"number", false},
+ {"00000000-0000-0000-0000-000000000000", false},
+ {"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", false},
+ {"hga8adshla3434g", false},
+ {"f795f7db-2dfe-4095-96f3-8f8370c735f9", false},
+ }
+
+ for _, tt := range testCases {
+ isFalsePositive, _ := GetFalsePositiveCheck(customFalsePositiveChecker{})(Result{Raw: []byte(tt.raw)})
+ assert.Equal(t, tt.isFalsePositive, isFalsePositive, "secret %q had unexpected false positive status", tt.raw)
+ }
+}
+
func TestFilterKnownFalsePositives_DefaultLogic(t *testing.T) {
results := []Result{
{Raw: []byte("00000")}, // "default" false positive list