mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 13:14:22 +01:00
ref is not ordered... so the depth option is wack
This commit is contained in:
1 parent
230a52e3e3
commit
fa27d32bfe
2 files changed
+41
-25
No files matched your search
@@ -660,6 +660,7 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
g.Describe("TestAuditRepo", func() {
|
g.Describe("TestAuditRepo", func() {
|
||||||
g.It(test.description, func() {
|
g.It(test.description, func() {
|
||||||
|
auditDone = false
|
||||||
opts = test.testOpts
|
opts = test.testOpts
|
||||||
// settin da globs
|
// settin da globs
|
||||||
if test.whiteListFiles != nil {
|
if test.whiteListFiles != nil {
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ type entropyRange struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const defaultGithubURL = "https://api.github.com/"
|
const defaultGithubURL = "https://api.github.com/"
|
||||||
const version = "1.23.0"
|
const version = "1.24.0"
|
||||||
const errExit = 2
|
const errExit = 2
|
||||||
const leakExit = 1
|
const leakExit = 1
|
||||||
const defaultConfig = `
|
const defaultConfig = `
|
||||||
@@ -226,6 +226,7 @@ var (
|
|||||||
totalCommits int64
|
totalCommits int64
|
||||||
commitMap = make(map[string]bool)
|
commitMap = make(map[string]bool)
|
||||||
cMutex = &sync.Mutex{}
|
cMutex = &sync.Mutex{}
|
||||||
|
auditDone bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -488,6 +489,7 @@ func auditGitRepo(repo *RepoDescriptor) ([]Leak, error) {
|
|||||||
return leaks, err
|
return leaks, err
|
||||||
}
|
}
|
||||||
err = refs.ForEach(func(ref *plumbing.Reference) error {
|
err = refs.ForEach(func(ref *plumbing.Reference) error {
|
||||||
|
fmt.Println(ref.Name())
|
||||||
if ref.Name().IsTag() {
|
if ref.Name().IsTag() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -500,29 +502,6 @@ func auditGitRepo(repo *RepoDescriptor) ([]Leak, error) {
|
|||||||
return leaks, err
|
return leaks, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// externalConfig will attempt to load a pinned ".gitleaks.toml" configuration file
|
|
||||||
// from a remote or local repo. Use the --repo-config option to trigger this.
|
|
||||||
func externalConfig(repo *RepoDescriptor) error {
|
|
||||||
var config Config
|
|
||||||
wt, err := repo.repository.Worktree()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
f, err := wt.Filesystem.Open(".gitleaks.toml")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := toml.DecodeReader(f, &config); err != nil {
|
|
||||||
return fmt.Errorf("problem loading config: %v", err)
|
|
||||||
}
|
|
||||||
f.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
updateConfig(config)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// auditGitReference beings the audit for a git reference. This function will
|
// auditGitReference beings the audit for a git reference. This function will
|
||||||
// traverse the git reference and audit each line of each diff.
|
// traverse the git reference and audit each line of each diff.
|
||||||
func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
||||||
@@ -535,6 +514,9 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
|||||||
mutex = &sync.Mutex{}
|
mutex = &sync.Mutex{}
|
||||||
semaphore chan bool
|
semaphore chan bool
|
||||||
)
|
)
|
||||||
|
if auditDone {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
repoName = repo.name
|
repoName = repo.name
|
||||||
if opts.Threads != 0 {
|
if opts.Threads != 0 {
|
||||||
threads = opts.Threads
|
threads = opts.Threads
|
||||||
@@ -549,7 +531,10 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
err = cIter.ForEach(func(c *object.Commit) error {
|
err = cIter.ForEach(func(c *object.Commit) error {
|
||||||
if c == nil || (opts.Depth != 0 && commitCount == opts.Depth) {
|
if c == nil || (opts.Depth != 0 && commitCount == opts.Depth) || auditDone {
|
||||||
|
if commitCount == opts.Depth {
|
||||||
|
auditDone = true
|
||||||
|
}
|
||||||
return storer.ErrStop
|
return storer.ErrStop
|
||||||
}
|
}
|
||||||
commitCount = commitCount + 1
|
commitCount = commitCount + 1
|
||||||
@@ -563,9 +548,15 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
|||||||
if commitMap[c.Hash.String()] {
|
if commitMap[c.Hash.String()] {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.Commit == c.Hash.String() {
|
||||||
|
auditDone = true
|
||||||
|
}
|
||||||
|
|
||||||
cMutex.Lock()
|
cMutex.Lock()
|
||||||
commitMap[c.Hash.String()] = true
|
commitMap[c.Hash.String()] = true
|
||||||
cMutex.Unlock()
|
cMutex.Unlock()
|
||||||
|
fmt.Println(c.Hash.String())
|
||||||
totalCommits = totalCommits + 1
|
totalCommits = totalCommits + 1
|
||||||
|
|
||||||
fIter, err := c.Files()
|
fIter, err := c.Files()
|
||||||
@@ -694,6 +685,7 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
|||||||
|
|
||||||
// stop audit if we are at commitStop
|
// stop audit if we are at commitStop
|
||||||
if c.Hash.String() == opts.CommitStop {
|
if c.Hash.String() == opts.CommitStop {
|
||||||
|
auditDone = true
|
||||||
return storer.ErrStop
|
return storer.ErrStop
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,6 +856,29 @@ func discoverRepos(ownerPath string) ([]*RepoDescriptor, error) {
|
|||||||
return repos, err
|
return repos, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// externalConfig will attempt to load a pinned ".gitleaks.toml" configuration file
|
||||||
|
// from a remote or local repo. Use the --repo-config option to trigger this.
|
||||||
|
func externalConfig(repo *RepoDescriptor) error {
|
||||||
|
var config Config
|
||||||
|
wt, err := repo.repository.Worktree()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f, err := wt.Filesystem.Open(".gitleaks.toml")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := toml.DecodeReader(f, &config); err != nil {
|
||||||
|
return fmt.Errorf("problem loading config: %v", err)
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
updateConfig(config)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// setLogLevel sets log level for gitleaks. Default is Warning
|
// setLogLevel sets log level for gitleaks. Default is Warning
|
||||||
func setLogs() {
|
func setLogs() {
|
||||||
switch opts.Log {
|
switch opts.Log {
|
||||||
|
|||||||
Reference in new issue
Block a user