From 2ba97d0fa3c1f1442aee4caf86239ef126ac8414 Mon Sep 17 00:00:00 2001 From: Zachary Rice Date: Tue, 2 Oct 2018 12:34:05 -0500 Subject: [PATCH] fixing audit repo bug (#101) * fixing audit repo bug * bumping version --- CHANGELOG.md | 4 ++++ gitleaks_test.go | 24 ++++++++++++++++++++++++ main.go | 14 ++++++++------ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aa6b36a..8473cf6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ CHANGELOG ========= +1.7.1 +----- +- Fixing bug where single repos were not being audited + 1.7.0 ----- - Exit code == 2 on error diff --git a/gitleaks_test.go b/gitleaks_test.go index dd7164be..4e2e9aef 100644 --- a/gitleaks_test.go +++ b/gitleaks_test.go @@ -239,6 +239,30 @@ func TestRunAudit(t *testing.T) { numLeaks: 0, expectedErrMsg: "unable to generate ssh key: open reallyreallyreallyreallywrongpath: no such file or directory", }, + { + testOpts: Options{ + Repo: "https://github.com/gitleakstest/gronit.git", + }, + description: "test leak", + numLeaks: 2, + expectedErrMsg: "", + }, + { + testOpts: Options{ + Repo: "https://github.com/gitleakstest/h1domains.git", + }, + description: "test clean", + numLeaks: 0, + expectedErrMsg: "", + }, + { + testOpts: Options{ + Repo: "https://github.com/gitleakstest/empty.git", + }, + description: "test empty", + numLeaks: 0, + expectedErrMsg: "reference not found", + }, } g := goblin.Goblin(t) for _, test := range tests { diff --git a/main.go b/main.go index 28d9df1f..77709696 100644 --- a/main.go +++ b/main.go @@ -119,7 +119,7 @@ type Config struct { } const defaultGithubURL = "https://api.github.com/" -const version = "1.7.0" +const version = "1.7.1" const errExit = 2 const leakExit = 1 const defaultConfig = ` @@ -194,10 +194,6 @@ func main() { fmt.Println(version) os.Exit(0) } - if err != nil { - log.Error(err) - os.Exit(errExit) - } leaks, err := run() if err != nil { log.Error(err) @@ -245,7 +241,13 @@ func run() ([]Leak, error) { func startAudits() ([]Leak, error) { var leaks []Leak // start audits - if opts.OwnerPath != "" { + if opts.Repo != "" || opts.RepoPath != "" { + repo, err := getRepo() + if err != nil { + return leaks, err + } + return auditRepo(repo) + } else if opts.OwnerPath != "" { repos, err := discoverRepos(opts.OwnerPath) if err != nil { return leaks, err