Merge pull request #558 from AmitHofree/fix_default_config

Removed unnecessary backslashes in default config
This commit is contained in:
Ramon authored and GitHub committed 2021-10-11 08:17:17 +02:00
commit f338bc584f
4 files changed
+99 -2

No files matched your search

+2 -2
View File
@@ -75,7 +75,7 @@ title = "gitleaks config"
[[rules]]
description = "Google API key"
regex = '''AIza[0-9A-Za-z\\-_]{35}'''
regex = '''AIza[0-9A-Za-z\-_]{35}'''
tags = ["key", "Google"]
[[rules]]
@@ -130,7 +130,7 @@ title = "gitleaks config"
[[rules]]
description = "Square OAuth secret"
regex = '''sq0csp-[0-9A-Za-z\\-_]{43}'''
regex = '''sq0csp-[0-9A-Za-z\-_]{43}'''
tags = ["key", "square"]
[[rules]]
+58
View File
@@ -5,13 +5,71 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/zricethezav/gitleaks/v7/config"
"github.com/zricethezav/gitleaks/v7/options"
"github.com/zricethezav/gitleaks/v7/scan"
)
const repoBasePath = "../testdata/repos/"
const expectPath = "../testdata/expect/"
func TestScan(t *testing.T) {
err := moveDotGit("dotGit", ".git")
if err != nil {
t.Fatal(err)
}
defer moveDotGit(".git", "dotGit")
tests := []struct {
description string
opts options.Options
wantPath string
}{
{
description: "test google api key leak AND square oauth leak",
opts: options.Options{
Path: filepath.Join(repoBasePath, "with_square_and_google"),
Report: filepath.Join(expectPath, "results_square_and_google.json.got"),
ReportFormat: "json",
NoGit: true,
},
wantPath: filepath.Join(expectPath, "results_square_and_google.json"),
},
}
for _, test := range tests {
cfg, err := config.NewConfig(test.opts)
if err != nil {
t.Error(err)
}
scanner, err := scan.NewScanner(test.opts, cfg)
if err != nil {
t.Error(test.description, err)
}
scannerReport, err := scanner.Scan()
if err != nil {
t.Fatal(test.description, err)
}
err = scan.WriteReport(scannerReport, test.opts, cfg)
if err != nil {
t.Error(test.description, err)
}
if test.wantPath != "" {
err := fileCheck(test.wantPath, test.opts.Report)
if err != nil {
t.Error(test.description, err)
}
}
}
}
func moveDotGit(from, to string) error {
repoDirs, err := ioutil.ReadDir("../testdata/repos")
if err != nil {
+36
View File
@@ -0,0 +1,36 @@
[
{
"line": "SQUARE_OAUTH=sq0csp-QZxqK3fHycIxFsjZ7_HoqRN08qY2by3wLXcfJCfsKEg",
"lineNumber": 1,
"offender": "sq0csp-QZxqK3fHycIxFsjZ7_HoqRN08qY2by3wLXcfJCfsKEg",
"offenderEntropy": -1,
"commit": "",
"repo": "",
"repoURL": "",
"leakURL": "",
"rule": "Square OAuth secret",
"commitMessage": "",
"author": "",
"email": "",
"file": ".",
"date": "0001-01-01T00:00:00Z",
"tags": "key, square"
},
{
"line": "GOOGLE_MAPS_KEY=AIzaSyDtz3Di0ZrzeU5ET3UFU0p-xP4bx2FkSrg",
"lineNumber": 3,
"offender": "AIzaSyDtz3Di0ZrzeU5ET3UFU0p-xP4bx2FkSrg",
"offenderEntropy": -1,
"commit": "",
"repo": "",
"repoURL": "",
"leakURL": "",
"rule": "Google API key",
"commitMessage": "",
"author": "",
"email": "",
"file": ".",
"date": "0001-01-01T00:00:00Z",
"tags": "key, Google"
}
]
+3
View File
@@ -0,0 +1,3 @@
SQUARE_OAUTH=sq0csp-QZxqK3fHycIxFsjZ7_HoqRN08qY2by3wLXcfJCfsKEg
GOOGLE_MAPS_KEY=AIzaSyDtz3Di0ZrzeU5ET3UFU0p-xP4bx2FkSrg