mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-28 20:24:22 +01:00
Audit commits based on date/time parameters (#385)
* time based audit * fixing SIGSEGV * adding options for date and time format + tests * Update repo.go * Update github.go * rebase + tests update
This commit is contained in:
1 parent
3e88ac6726
commit
e0f6399d5c
6 files changed
+151
-1
No files matched your search
@@ -325,6 +325,37 @@ func TestAudit(t *testing.T) {
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_six_path_globally_whitelisted.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo six leaks since date",
|
||||
opts: options.Options{
|
||||
RepoPath: "../test_data/test_repos/test_repo_6",
|
||||
Report: "../test_data/test_local_repo_six_leaks_since_date.json.got",
|
||||
ReportFormat: "json",
|
||||
CommitSince: "2019-10-25",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_six_leaks_since_date.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two leaks until date",
|
||||
opts: options.Options{
|
||||
RepoPath: "../test_data/test_repos/test_repo_6",
|
||||
Report: "../test_data/test_local_repo_six_leaks_until_date.json.got",
|
||||
ReportFormat: "json",
|
||||
CommitUntil: "2019-10-25",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_six_leaks_until_date.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo four leaks timerange commit",
|
||||
opts: options.Options{
|
||||
RepoPath: "../test_data/test_repos/test_repo_4",
|
||||
Report: "../test_data/test_local_repo_four_leaks_commit_timerange.json.got",
|
||||
ReportFormat: "json",
|
||||
CommitSince: "2019-10-25T13:01:27-0400",
|
||||
CommitUntil: "2019-10-25T13:12:32-0400",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_four_leaks_commit_timerange.json",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
+21
-1
@@ -418,9 +418,29 @@ func RegexMatched(f interface{}, re *regexp.Regexp) bool {
|
||||
// gitleaks gets the full git history.
|
||||
func getLogOptions(repo *Repo) (*git.LogOptions, error) {
|
||||
var logOpts git.LogOptions
|
||||
const dateformat string = "2006-01-02"
|
||||
const timeformat string = "2006-01-02T15:04:05-0700"
|
||||
if repo.Manager.Opts.CommitFrom != "" {
|
||||
logOpts.From = plumbing.NewHash(repo.Manager.Opts.CommitFrom)
|
||||
}
|
||||
if repo.Manager.Opts.CommitSince != "" {
|
||||
if t, err := time.Parse(timeformat, repo.Manager.Opts.CommitSince); err == nil {
|
||||
logOpts.Since = &t
|
||||
} else if t, err := time.Parse(dateformat, repo.Manager.Opts.CommitSince); err == nil {
|
||||
logOpts.Since = &t
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if repo.Manager.Opts.CommitUntil != "" {
|
||||
if t, err := time.Parse(timeformat, repo.Manager.Opts.CommitUntil); err == nil {
|
||||
logOpts.Until = &t
|
||||
} else if t, err := time.Parse(dateformat, repo.Manager.Opts.CommitUntil); err == nil {
|
||||
logOpts.Until = &t
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if repo.Manager.Opts.Branch != "" {
|
||||
refs, err := repo.Storer.IterReferences()
|
||||
if err != nil {
|
||||
@@ -449,7 +469,7 @@ func getLogOptions(repo *Repo) (*git.LogOptions, error) {
|
||||
}
|
||||
return &logOpts, nil
|
||||
}
|
||||
if !logOpts.From.IsZero() {
|
||||
if !logOpts.From.IsZero() || logOpts.Since != nil || logOpts.Until != nil {
|
||||
return &logOpts, nil
|
||||
}
|
||||
return &git.LogOptions{All: true}, nil
|
||||
|
||||
Reference in new issue
Block a user