checks_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package main
  2. import (
  3. "testing"
  4. )
  5. func TestCheckRegex(t *testing.T) {
  6. var results []LeakElem
  7. opts := &Options{
  8. Concurrency: 10,
  9. B64EntropyCutoff: 70,
  10. HexEntropyCutoff: 40,
  11. Entropy: false,
  12. }
  13. checks := map[string]int{
  14. "aws=\"AKIALALEMEL33243OLIAE": 1,
  15. "aws\"afewafewafewafewaf\"": 0,
  16. }
  17. for k, v := range checks {
  18. results = doChecks(k, "commit", opts)
  19. if v != len(results) {
  20. t.Errorf("regexCheck failed on string %s", k)
  21. }
  22. }
  23. }
  24. func TestEntropy(t *testing.T) {
  25. var enoughEntropy bool
  26. opts := &Options{
  27. Concurrency: 10,
  28. B64EntropyCutoff: 70,
  29. HexEntropyCutoff: 40,
  30. Entropy: false,
  31. }
  32. checks := map[string]bool{
  33. "reddit_api_secret = settings./.http}": false,
  34. "heroku_client_secret = simple": false,
  35. "reddit_api_secret = \"4ok1WFf57-EMswEfAFGewa\"": true,
  36. "aws_secret= \"AKIAIMNOJVGFDXXFE4OA\"": true,
  37. }
  38. for k, v := range checks {
  39. enoughEntropy = checkShannonEntropy(k, opts)
  40. if v != enoughEntropy {
  41. t.Errorf("checkEntropy failed for %s. Expected %t, got %t", k, v, enoughEntropy)
  42. }
  43. }
  44. }
  45. func TestStopWords(t *testing.T) {
  46. if containsStopWords("aws_secret=settings.AWS_SECRET") != true {
  47. t.Errorf("checkStopWords Failed")
  48. }
  49. }