fixed regex allow none or more that none

This commit is contained in:
zricethezav committed 2018-01-28 13:25:48 -05:00
1 parent ec654441bb
commit 8af639d7ff
2 files changed
+18 -12

No files matched your search

+11 -5
View File
@@ -6,16 +6,22 @@ import (
func TestCheckRegex(t *testing.T) {
var secretsPresent bool
var results []string
checks := map[string]bool{
"github.com": false,
"github.com/user/": false,
"github_api_client = \"sample key\"": true,
"github.com": false,
"github.com/user/": false,
"github_api_client = \"sample key\"": true,
"aws=\"afewafewafewafewaf\"": true,
"aws\"afewafewafewafewaf\"": false,
"heroku := \"afewafewafewafewaf\"": true,
"heroku_client_secret := \"afewafewafewafewaf\"": true,
"reddit_api_secreit = \"Fwe4fa431FgklreF\"": true,
}
for k, v := range checks {
_, secretsPresent = checkRegex(k)
results, secretsPresent = checkRegex(k)
if v != secretsPresent {
t.Errorf("regexCheck failed on string %s. Expected secretsPresent: %t, got %t", k, v, secretsPresent)
t.Errorf("regexCheck failed on string %s. Expected secretsPresent: %t, got %t, %v", k, v, secretsPresent, results)
}
}
}
+7 -7
View File
@@ -28,13 +28,13 @@ func init() {
appRoot, _ = os.Getwd()
cache = make(map[string]bool)
regexes = map[string]*regexp.Regexp{
"github": regexp.MustCompile(`[g|G][i|I][t|T][h|H][u|U][b|B].+[=|:=|:|<-].*\w+.*`),
"aws": regexp.MustCompile(`[a|A][w|W][s|S].+[=|:=|:|<-].*\w+.*`),
"heroku": regexp.MustCompile(`[h|H][e|E][r|R][o|O][k|K][u|U].+[=|:=|:|<-].*\w+.*`),
"facebook": regexp.MustCompile(`[f|F][a|A][c|C][e|E][b|B][o|O][o|O][k|K].+[=|:=|:|<-].*\w+.*`),
"twitter": regexp.MustCompile(`[t|T][w|W][i|I][t|T][t|T][e|E][r|R].+[=|:=|:|<-].*\w+.*`),
"reddit": regexp.MustCompile(`[r|R][e|E][d|D][d|D][i|I][t|T].+[=|:=|:|<-].*\w+.*`),
"twilio": regexp.MustCompile(`[t|T][w|W][i|I][l|L][i|I][o|O].+[=|:=|:|<-].*\w+.*`),
"github": regexp.MustCompile(`[g|G][i|I][t|T][h|H][u|U][b|B].*[=|:=|:|<-].*\w+.*`),
"aws": regexp.MustCompile(`[a|A][w|W][s|S].*[=|:=|:|<-].*\w+.*`),
"heroku": regexp.MustCompile(`[h|H][e|E][r|R][o|O][k|K][u|U].*[=|:=|:|<-].*\w+.*`),
"facebook": regexp.MustCompile(`[f|F][a|A][c|C][e|E][b|B][o|O][o|O][k|K].*[=|:=|:|<-].*\w+.*`),
"twitter": regexp.MustCompile(`[t|T][w|W][i|I][t|T][t|T][e|E][r|R].*[=|:=|:|<-].*\w+.*`),
"reddit": regexp.MustCompile(`[r|R][e|E][d|D][d|D][i|I][t|T].*[=|:=|:|<-].*\w+.*`),
"twilio": regexp.MustCompile(`[t|T][w|W][i|I][l|L][i|I][o|O].*[=|:=|:|<-].*\w+.*`),
}
}