-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix broken & inaccurate detector unit tests #3817
Comments
The Additionally, I’d appreciate your input on some test cases I wrote to simulate real-world scenarios for various detectors. For example, take a look at the bombbomb detector complex pattern test. If this approach looks good, we can work on updating the remaining test cases to follow a similar strategy. |
Agreed, and this may also involve updating detectors where the existing regex could potentially match incorrect patterns. |
Small mistakes like that should be detected once #3773 is merged.
That's a better approach, although you only really need 1/2 lines of surrounding context. I'd also suggest moving the inputs inline with the test cases (input: `...`) instead of sprintf'ing them. complexPattern = `
bombbombToken := "HUmGL.17uQMEShYp2RVMR8vypd1iqj6FZcKkQ4SazuMkbEKhzRFKuvOiwYmNWPSvkE4wiLOv-zWTkK1WkVTScRb9_io0_kvhYX31tpwR3lAJUh27RJzf1BehaJTQDXhJB6aT2gQ2LMT7dda-b3vhmEuZHzPV9AMLV6cOrcqOTkK60vMcB0PTLRQ3c_kY.a.9.hRvgogdlI8mQJrzD0myPBY7lMpjpkcskQDpOgz2I37kNDYhf7IxT6sG-a7rI1LdpJ6HhJacktlNJSswST9jbt4A0ropfJJTHGny2aId4WyPpAnQubM98F1BUnyhfkDzenaUuuQ_ZoPn9mAOsdLQUlAyp4I9oLJ_v8yQ0Q4M.Yujscho9G4ZbVTInC2mP8taCPZdRK5qt-UfAF0CX9B4E0F9NItMUbRdbm3xIkl8C6iPUcgY5OTQDBSJRLKBJgIaEyyXe10pPw.qOUhLKNPcg5qPs1xhgBsZKfW2hNTff2dCL5h6E.940ojPuT0Iw90Q8kpQ2UzeUJrhXH9_GUANKA.pjD0-YcGpnlVEDouyXaXowUoh8pLqD-BtBQfteqyFqz7THGDvQKikMy7wiBuJAo0HttMG3jw1zKtA3gM6_VIXo_K4WN6yz8Ow4n5f6Unn5zn4j2haKA4WWI5-1c8-mm7SF5VqYJVz42wBmRqB6MWXegJ7yLt_EoG1tJHftnHZ"
req.Header.Set("Authorization", bombbombToken)
` I tend to base test cases on results found from GitHub or SourceGraph search. |
I can fix the |
The detector unit tests were created by "reverse engineering" the patterns, thus they do not provide any real value or confirm how accurate the detectors are.
Additionally, the structure of the tests are (in my opinion) not maintainable as they are difficult to understand and do not reflect any realistic scenarios.
trufflehog/pkg/detectors/netsuite/netsuite_test.go
Lines 14 to 44 in def734a
Examples
There are dozens, if not hundreds, of problematic test files. These are illustrative.
BombBomb
The "valid" tests for BombBomb do not match the detector's pattern.
trufflehog/pkg/detectors/bombbomb/bombbomb.go
Line 24 in def734a
trufflehog/pkg/detectors/bombbomb/bombbomb_test.go
Line 15 in def734a
Kraken
The "valid" pattern is nonsensical and not correct base64 encoding. The detector should not match this, that is a defect.
trufflehog/pkg/detectors/kraken/kraken_test.go
Line 16 in def734a
https://support.kraken.com/hc/en-us/articles/360000919966-How-to-create-an-API-key
viewneo
A few hundred detectors contain tests tightly coupled to the current implementation of
PrefixRegex
. Any changes to the prefix pattern will break the detector tests, which seems inadvisable.trufflehog/pkg/detectors/viewneo/viewneo_test.go
Lines 38 to 42 in def734a
The text was updated successfully, but these errors were encountered: