checks_test.go 1.1 KB

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