mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 21:24:21 +01:00
cleaning up some comments
This commit is contained in:
1 parent
a0f72a4e35
commit
b4c2f8e69c
2 files changed
+17
-20
No files matched your search
+16
-17
@@ -3,16 +3,18 @@ package audit
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sergi/go-diff/diffmatchpatch"
|
|
||||||
"github.com/zricethezav/gitleaks/config"
|
|
||||||
"github.com/zricethezav/gitleaks/manager"
|
|
||||||
"github.com/zricethezav/gitleaks/options"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/zricethezav/gitleaks/config"
|
||||||
|
"github.com/zricethezav/gitleaks/manager"
|
||||||
|
"github.com/zricethezav/gitleaks/options"
|
||||||
|
|
||||||
|
"github.com/sergi/go-diff/diffmatchpatch"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testRepoBase = "../test_data/test_repos/"
|
const testRepoBase = "../test_data/test_repos/"
|
||||||
@@ -79,7 +81,7 @@ func TestAudit(t *testing.T) {
|
|||||||
RepoPath: "../test_data/test_repos/test_repo_2",
|
RepoPath: "../test_data/test_repos/test_repo_2",
|
||||||
Report: "../test_data/test_local_repo_two_leaks_commit_from.json.got",
|
Report: "../test_data/test_local_repo_two_leaks_commit_from.json.got",
|
||||||
ReportFormat: "json",
|
ReportFormat: "json",
|
||||||
CommitFrom: "996865bb912f3bc45898a370a13aadb315014b55",
|
CommitFrom: "996865bb912f3bc45898a370a13aadb315014b55",
|
||||||
},
|
},
|
||||||
wantPath: "../test_data/test_local_repo_two_leaks_commit_from.json",
|
wantPath: "../test_data/test_local_repo_two_leaks_commit_from.json",
|
||||||
},
|
},
|
||||||
@@ -89,7 +91,7 @@ func TestAudit(t *testing.T) {
|
|||||||
RepoPath: "../test_data/test_repos/test_repo_2",
|
RepoPath: "../test_data/test_repos/test_repo_2",
|
||||||
Report: "../test_data/test_local_repo_two_leaks_commit_to.json.got",
|
Report: "../test_data/test_local_repo_two_leaks_commit_to.json.got",
|
||||||
ReportFormat: "json",
|
ReportFormat: "json",
|
||||||
CommitTo: "996865bb912f3bc45898a370a13aadb315014b55",
|
CommitTo: "996865bb912f3bc45898a370a13aadb315014b55",
|
||||||
},
|
},
|
||||||
wantPath: "../test_data/test_local_repo_two_leaks_commit_to.json",
|
wantPath: "../test_data/test_local_repo_two_leaks_commit_to.json",
|
||||||
},
|
},
|
||||||
@@ -99,8 +101,8 @@ func TestAudit(t *testing.T) {
|
|||||||
RepoPath: "../test_data/test_repos/test_repo_2",
|
RepoPath: "../test_data/test_repos/test_repo_2",
|
||||||
Report: "../test_data/test_local_repo_two_leaks_commit_range.json.got",
|
Report: "../test_data/test_local_repo_two_leaks_commit_range.json.got",
|
||||||
ReportFormat: "json",
|
ReportFormat: "json",
|
||||||
CommitFrom: "d8ac0b73aeeb45843319cdc5ce506516eb49bf7a",
|
CommitFrom: "d8ac0b73aeeb45843319cdc5ce506516eb49bf7a",
|
||||||
CommitTo: "51f6dcf6b89b93f4075ba92c400b075631a6cc93",
|
CommitTo: "51f6dcf6b89b93f4075ba92c400b075631a6cc93",
|
||||||
},
|
},
|
||||||
wantPath: "../test_data/test_local_repo_two_leaks_commit_range.json",
|
wantPath: "../test_data/test_local_repo_two_leaks_commit_range.json",
|
||||||
},
|
},
|
||||||
@@ -345,8 +347,10 @@ func TestAuditUncommited(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fileCheck(wantPath, gotPath string) error {
|
func fileCheck(wantPath, gotPath string) error {
|
||||||
var gotLeaks []manager.Leak
|
var (
|
||||||
var wantLeaks []manager.Leak
|
gotLeaks []manager.Leak
|
||||||
|
wantLeaks []manager.Leak
|
||||||
|
)
|
||||||
want, err := ioutil.ReadFile(wantPath)
|
want, err := ioutil.ReadFile(wantPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -357,7 +361,6 @@ func fileCheck(wantPath, gotPath string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO compare JSONs
|
|
||||||
err = json.Unmarshal(got, &gotLeaks)
|
err = json.Unmarshal(got, &gotLeaks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -368,18 +371,14 @@ func fileCheck(wantPath, gotPath string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(gotLeaks, func(i, j int) bool { return (gotLeaks)[i].Commit < (gotLeaks)[j].Commit})
|
sort.Slice(gotLeaks, func(i, j int) bool { return (gotLeaks)[i].Commit < (gotLeaks)[j].Commit })
|
||||||
sort.Slice(wantLeaks, func(i, j int) bool { return (wantLeaks)[i].Commit < (wantLeaks)[j].Commit})
|
sort.Slice(wantLeaks, func(i, j int) bool { return (wantLeaks)[i].Commit < (wantLeaks)[j].Commit })
|
||||||
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(gotLeaks, wantLeaks) {
|
if !reflect.DeepEqual(gotLeaks, wantLeaks) {
|
||||||
dmp := diffmatchpatch.New()
|
dmp := diffmatchpatch.New()
|
||||||
diffs := dmp.DiffMain(string(want), string(got), false)
|
diffs := dmp.DiffMain(string(want), string(got), false)
|
||||||
return fmt.Errorf("does not equal: %s", dmp.DiffPrettyText(diffs))
|
return fmt.Errorf("does not equal: %s", dmp.DiffPrettyText(diffs))
|
||||||
// return fmt.Errorf("does not equal: %s", cmp.Diff(gotLeaks, wantLeaks))
|
|
||||||
}
|
}
|
||||||
//if strings.Trim(string(want), "\n") != strings.Trim(string(got), "\n") {
|
|
||||||
//}
|
|
||||||
if err := os.Remove(gotPath); err != nil {
|
if err := os.Remove(gotPath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -18,12 +18,10 @@ import (
|
|||||||
"gopkg.in/src-d/go-git.v4/plumbing/object"
|
"gopkg.in/src-d/go-git.v4/plumbing/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxLineLen = 200
|
|
||||||
|
|
||||||
// Inspect patch accepts a patch, commit, and repo. If the patches contains files that are
|
// Inspect patch accepts a patch, commit, and repo. If the patches contains files that are
|
||||||
// binary, then gitleaks will skip auditing that file OR if a file is matched on
|
// binary, then gitleaks will skip auditing that file OR if a file is matched on
|
||||||
// whitelisted files set in the configuration. If a global rule for files is defined and a filename
|
// whitelisted files set in the configuration. If a global rule for files is defined and a filename
|
||||||
// matches said global rule, then a laek is sent to the manager.
|
// matches said global rule, then a leak is sent to the manager.
|
||||||
// After that, file chunks are created which are then inspected by InspectString()
|
// After that, file chunks are created which are then inspected by InspectString()
|
||||||
func inspectPatch(patch *object.Patch, c *object.Commit, repo *Repo) {
|
func inspectPatch(patch *object.Patch, c *object.Commit, repo *Repo) {
|
||||||
for _, f := range patch.FilePatches() {
|
for _, f := range patch.FilePatches() {
|
||||||
|
|||||||
Reference in new issue
Block a user