checks_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "testing"
  4. )
  5. func TestCheckRegex(t *testing.T) {
  6. var results []string
  7. checks := map[string]int{
  8. "github.com": 0,
  9. "github.com/user/": 0,
  10. "github.com/user -- Sys": 0,
  11. "github_api_client = \"sample key\"\naws=afewafewafewafewaf": 2,
  12. "aws=\"afewafewafewafewaf\"": 1,
  13. "aws\"afewafewafewafewaf\"": 0,
  14. "heroku := \"afewafewafewafewaf\"": 1,
  15. "heroku_client_secret := \"afewafewafewafewaf\"": 1,
  16. "reddit_api_secreit = \"Fwe4fa431FgklreF\"": 1,
  17. "+ * [Github Help: Managing Deploy Keys](https://help.github.com/articles/managing-deploy-keys)": 0,
  18. }
  19. for k, v := range checks {
  20. results = checkRegex(k)
  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, 70, 40)
  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. }