Преглед на файлове

fix(detect): test all allowlists (#1845)

Richard Gomez преди 9 месеца
родител
ревизия
a2a447c39b
променени са 3 файла, в които са добавени 20 реда и са изтрити 2 реда
  1. 2 2
      detect/detect.go
  2. 7 0
      detect/detect_test.go
  3. 11 0
      testdata/config/valid/allowlist_rule_extend_default.toml

+ 2 - 2
detect/detect.go

@@ -547,10 +547,10 @@ func checkCommitOrPathAllowed(
 			}
 			}
 			// These will be checked later.
 			// These will be checked later.
 			if len(a.Regexes) > 0 {
 			if len(a.Regexes) > 0 {
-				return false, nil
+				continue
 			}
 			}
 			if len(a.StopWords) > 0 {
 			if len(a.StopWords) > 0 {
-				return false, nil
+				continue
 			}
 			}
 
 
 			isAllowed = allTrue(allowlistChecks)
 			isAllowed = allTrue(allowlistChecks)

+ 7 - 0
detect/detect_test.go

@@ -376,6 +376,13 @@ const token = "mockSecret";
 				FilePath: "tmp.go",
 				FilePath: "tmp.go",
 			},
 			},
 		},
 		},
+		"allowlist - ignore path when extending": {
+			cfgName: "valid/allowlist_rule_extend_default",
+			fragment: Fragment{
+				Raw:      `token = "aebfab88-7596-481d-82e8-c60c8f7de0c0"`,
+				FilePath: "path/to/your/problematic/file.js",
+			},
+		},
 		"allowlist - ignore regex": {
 		"allowlist - ignore regex": {
 			cfgName: "valid/allowlist_rule_regex",
 			cfgName: "valid/allowlist_rule_regex",
 			fragment: Fragment{
 			fragment: Fragment{

+ 11 - 0
testdata/config/valid/allowlist_rule_extend_default.toml

@@ -0,0 +1,11 @@
+# https://github.com/gitleaks/gitleaks/issues/1844
+[extend]
+useDefault = true
+
+[[rules]]
+id = "generic-api-key"
+[[rules.allowlists]]
+description = "Exclude a specific file from generic-api-key rule"
+paths = [
+    '''^path/to/your/problematic/file\.js$'''
+]