Skip to content

Find, verify, and analyze leaked credentials

[chore] Add test to check all versioned detectors are non-zero (#2272)

Miccah5e78ad402e7f
diff --git a/pkg/engine/defaults_test.go b/pkg/engine/defaults_test.go
index 67e41bc86..6131b211f 100644
--- a/pkg/engine/defaults_test.go
+++ b/pkg/engine/defaults_test.go
@@ -48,3 +48,20 @@ func TestDefaultDetectorTypesImplementing(t *testing.T) {
)
}
}
+
+func TestDefaultVersionerDetectorsHaveNonZeroVersions(t *testing.T) {
+ // Loop through all our default detectors and find the ones that
+ // implement Versioner. Of those, check each version is not zero.
+ // This is required due to an implementation detail of filtering detectors.
+ // See: https://github.com/trufflesecurity/trufflehog/blob/v3.63.7/main.go#L624-L638
+ for _, detector := range DefaultDetectors() {
+ v, ok := detector.(detectors.Versioner)
+ if !ok || v.Version() != 0 {
+ continue
+ }
+ t.Errorf(
+ "detector %q implements Versioner that returns a zero version",
+ detectorspb.DetectorType_name[int32(detector.Type())],
+ )
+ }
+}