diff --git a/main.go b/main.go index cd9a2563..3729355d 100644 --- a/main.go +++ b/main.go @@ -2,11 +2,8 @@ package main import ( "fmt" - _ "fmt" - _ "io/ioutil" "os" "regexp" - _ "time" ) // ExitClean : no leaks have been found diff --git a/options.go b/options.go index 94ee28ea..4b150bee 100644 --- a/options.go +++ b/options.go @@ -28,7 +28,7 @@ Locations Other -t --temp Clone to temporary directory - -c Upper bound on concurrent diffs + --concurrency= Upper bound on concurrent diffs --since= Commit to stop at --b64Entropy= Base64 entropy cutoff (default is 70) --hexEntropy= Hex entropy cutoff (default is 40) @@ -160,19 +160,12 @@ func (opts *Options) parseOptions(args []string) error { for i := 0; i < len(args); i++ { arg := args[i] switch arg { - case "-s": - opts.SinceCommit = opts.nextString(args, &i) case "--strict": opts.Strict = true - case "-b", "--b64Entropy": - opts.B64EntropyCutoff = opts.nextInt(args, &i) - case "-x", "--hexEntropy": - opts.HexEntropyCutoff = opts.nextInt(args, &i) case "-e", "--entropy": opts.Entropy = true case "-c": opts.Concurrency = opts.nextInt(args, &i) - case "-o", "--org": opts.OrgMode = true case "-u", "--user": @@ -181,12 +174,10 @@ func (opts *Options) parseOptions(args []string) error { opts.RepoMode = true case "-l", "--local": opts.LocalMode = true - case "--report-out": opts.ReportOut = true case "--pretty": opts.PrettyPrint = true - case "-t", "--temp": opts.Tmp = true case "-ll": @@ -217,38 +208,44 @@ func (opts *Options) parseOptions(args []string) error { if isGithubTarget(args[i]) { opts.URL = args[i] } else { - fmt.Printf("Unknown option %s\n\n", arg) help() - os.Exit(ExitClean) + return fmt.Errorf("Unknown option %s\n", arg) } } } else { - fmt.Printf("Unknown option %s\n\n", arg) help() - return fmt.Errorf("Unknown option %s\n\n", arg) + return fmt.Errorf("Unknown option %s\n", arg) } } } - err := opts.guards() + // TODO cleanup this logic if !opts.RepoMode && !opts.UserMode && !opts.OrgMode && !opts.LocalMode { if opts.URL != "" { opts.RepoMode = true + err := opts.guards() + if err != nil{ + return err + } return nil } + pwd, _ = os.Getwd() // check if pwd contains a .git, if it does, run local mode dotGitPath := filepath.Join(pwd, ".git") if _, err := os.Stat(dotGitPath); os.IsNotExist(err) { - fmt.Printf("gitleaks has no target") - os.Exit(ExitClean) + return fmt.Errorf("gitleaks has no target: %v", err) } else { opts.LocalMode = true opts.RepoPath = pwd opts.RepoMode = false } + } + err := opts.guards() + if err != nil{ + return err } return err } diff --git a/options_test.go b/options_test.go index e1d66964..f6d9b535 100644 --- a/options_test.go +++ b/options_test.go @@ -85,5 +85,4 @@ func TestGithubTarget(t *testing.T) { if !isGithubTarget("git@github.com:zricethezav/gitleaks.git") { t.Error() } - } diff --git a/owner_test.go b/owner_test.go new file mode 100644 index 00000000..ee9f8cff --- /dev/null +++ b/owner_test.go @@ -0,0 +1,45 @@ +package main + +import ( + "testing" + "os" + "fmt" +) + +func TestOwnerPath(t *testing.T) { + opts, _ = defaultOptions() + p, err := ownerPath("testName") + if err != nil { + t.Error() + } + pwd, _ := os.Getwd() + if pwd != p { + t.Error() + } + opts.ClonePath = "test" + p, err = ownerPath("nameToIgnore") + fmt.Println(p) + if p != "test" { + t.Error() + } +} + +func TestNewOwner(t *testing.T) { + opts, _ = defaultOptions() + owner := newOwner() + + // default options will assume gitleaks is + // running on local mode + pwd, _ := os.Getwd() + if pwd != owner.path { + t.Error() + } + + // fuck on this some more + opts.URL = "github.com/testowner/test" + owner = newOwner() + fmt.Println(owner.path) + if owner.path != pwd + "/testowner" { + t.Error() + } +} diff --git a/repo_test.go b/repo_test.go index 9f0cf5eb..2fcbc9dd 100644 --- a/repo_test.go +++ b/repo_test.go @@ -1,7 +1,6 @@ package main import ( - _ "fmt" "os" "testing" )