Skip to content

Find, verify, and analyze leaked credentials

remove tracker type (#4723)

Cody Rose4d4080bd2760
diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go
index 67e4b985a..f8bc54709 100644
--- a/pkg/engine/engine.go
+++ b/pkg/engine/engine.go
@@ -213,7 +213,7 @@ type Engine struct {
verify bool
// Note: bad hack only used for testing.
- verificationOverlapTracker *verificationOverlapTracker
+ verificationOverlapTracker *atomic.Int32
// detectorWorkerMultiplier is used to calculate the number of detector workers.
detectorWorkerMultiplier int
@@ -534,17 +534,6 @@ func (e *Engine) initialize(ctx context.Context) error {
return nil
}
-type verificationOverlapTracker struct {
- verificationOverlapDuplicateCount int
- mu sync.Mutex
-}
-
-func (r *verificationOverlapTracker) increment() {
- r.mu.Lock()
- r.verificationOverlapDuplicateCount++
- r.mu.Unlock()
-}
-
const ignoreTag = "trufflehog:ignore"
// AhoCorasickCoreKeywords returns a set of keywords that the engine's
@@ -995,7 +984,7 @@ func (e *Engine) verificationOverlapWorker(ctx context.Context) {
// This indicates that the same secret was found by multiple detectors.
// We should NOT VERIFY this chunk's data.
if e.verificationOverlapTracker != nil {
- e.verificationOverlapTracker.increment()
+ e.verificationOverlapTracker.Add(1)
}
res.SetVerificationError(errOverlap)
e.processResult(
diff --git a/pkg/engine/engine_test.go b/pkg/engine/engine_test.go
index ef42c05e2..c49fe770a 100644
--- a/pkg/engine/engine_test.go
+++ b/pkg/engine/engine_test.go
@@ -8,6 +8,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
+ "sync/atomic"
"testing"
"time"
@@ -767,7 +768,7 @@ func TestVerificationOverlapChunk(t *testing.T) {
e, err := NewEngine(ctx, &c)
assert.NoError(t, err)
- e.verificationOverlapTracker = new(verificationOverlapTracker)
+ e.verificationOverlapTracker = &atomic.Int32{}
e.Start(ctx)
@@ -783,8 +784,8 @@ func TestVerificationOverlapChunk(t *testing.T) {
assert.Equal(t, want, e.GetMetrics().UnverifiedSecretsFound)
// We want 0 because these are custom detectors and verification should still occur.
- wantDupe := 0
- assert.Equal(t, wantDupe, e.verificationOverlapTracker.verificationOverlapDuplicateCount)
+ wantDupe := int32(0)
+ assert.Equal(t, wantDupe, e.verificationOverlapTracker.Load())
}
func TestEngine_FalsePositivesRetainedCorrectly(t *testing.T) {