mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 05:24:22 +01:00
more coverage
This commit is contained in:
1 parent
c019a9d80d
commit
2fadf219d9
5 files changed
+59
-22
No files matched your search
@@ -2,11 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "fmt"
|
|
||||||
_ "io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
_ "time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExitClean : no leaks have been found
|
// ExitClean : no leaks have been found
|
||||||
|
|||||||
+14
-17
@@ -28,7 +28,7 @@ Locations
|
|||||||
|
|
||||||
Other
|
Other
|
||||||
-t --temp Clone to temporary directory
|
-t --temp Clone to temporary directory
|
||||||
-c <INT> Upper bound on concurrent diffs
|
--concurrency=<INT> Upper bound on concurrent diffs
|
||||||
--since=<STR> Commit to stop at
|
--since=<STR> Commit to stop at
|
||||||
--b64Entropy=<INT> Base64 entropy cutoff (default is 70)
|
--b64Entropy=<INT> Base64 entropy cutoff (default is 70)
|
||||||
--hexEntropy=<INT> Hex entropy cutoff (default is 40)
|
--hexEntropy=<INT> Hex entropy cutoff (default is 40)
|
||||||
@@ -160,19 +160,12 @@ func (opts *Options) parseOptions(args []string) error {
|
|||||||
for i := 0; i < len(args); i++ {
|
for i := 0; i < len(args); i++ {
|
||||||
arg := args[i]
|
arg := args[i]
|
||||||
switch arg {
|
switch arg {
|
||||||
case "-s":
|
|
||||||
opts.SinceCommit = opts.nextString(args, &i)
|
|
||||||
case "--strict":
|
case "--strict":
|
||||||
opts.Strict = true
|
opts.Strict = true
|
||||||
case "-b", "--b64Entropy":
|
|
||||||
opts.B64EntropyCutoff = opts.nextInt(args, &i)
|
|
||||||
case "-x", "--hexEntropy":
|
|
||||||
opts.HexEntropyCutoff = opts.nextInt(args, &i)
|
|
||||||
case "-e", "--entropy":
|
case "-e", "--entropy":
|
||||||
opts.Entropy = true
|
opts.Entropy = true
|
||||||
case "-c":
|
case "-c":
|
||||||
opts.Concurrency = opts.nextInt(args, &i)
|
opts.Concurrency = opts.nextInt(args, &i)
|
||||||
|
|
||||||
case "-o", "--org":
|
case "-o", "--org":
|
||||||
opts.OrgMode = true
|
opts.OrgMode = true
|
||||||
case "-u", "--user":
|
case "-u", "--user":
|
||||||
@@ -181,12 +174,10 @@ func (opts *Options) parseOptions(args []string) error {
|
|||||||
opts.RepoMode = true
|
opts.RepoMode = true
|
||||||
case "-l", "--local":
|
case "-l", "--local":
|
||||||
opts.LocalMode = true
|
opts.LocalMode = true
|
||||||
|
|
||||||
case "--report-out":
|
case "--report-out":
|
||||||
opts.ReportOut = true
|
opts.ReportOut = true
|
||||||
case "--pretty":
|
case "--pretty":
|
||||||
opts.PrettyPrint = true
|
opts.PrettyPrint = true
|
||||||
|
|
||||||
case "-t", "--temp":
|
case "-t", "--temp":
|
||||||
opts.Tmp = true
|
opts.Tmp = true
|
||||||
case "-ll":
|
case "-ll":
|
||||||
@@ -217,38 +208,44 @@ func (opts *Options) parseOptions(args []string) error {
|
|||||||
if isGithubTarget(args[i]) {
|
if isGithubTarget(args[i]) {
|
||||||
opts.URL = args[i]
|
opts.URL = args[i]
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Unknown option %s\n\n", arg)
|
|
||||||
help()
|
help()
|
||||||
os.Exit(ExitClean)
|
return fmt.Errorf("Unknown option %s\n", arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Unknown option %s\n\n", arg)
|
|
||||||
help()
|
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.RepoMode && !opts.UserMode && !opts.OrgMode && !opts.LocalMode {
|
||||||
if opts.URL != "" {
|
if opts.URL != "" {
|
||||||
opts.RepoMode = true
|
opts.RepoMode = true
|
||||||
|
err := opts.guards()
|
||||||
|
if err != nil{
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pwd, _ = os.Getwd()
|
pwd, _ = os.Getwd()
|
||||||
// check if pwd contains a .git, if it does, run local mode
|
// check if pwd contains a .git, if it does, run local mode
|
||||||
dotGitPath := filepath.Join(pwd, ".git")
|
dotGitPath := filepath.Join(pwd, ".git")
|
||||||
|
|
||||||
if _, err := os.Stat(dotGitPath); os.IsNotExist(err) {
|
if _, err := os.Stat(dotGitPath); os.IsNotExist(err) {
|
||||||
fmt.Printf("gitleaks has no target")
|
return fmt.Errorf("gitleaks has no target: %v", err)
|
||||||
os.Exit(ExitClean)
|
|
||||||
} else {
|
} else {
|
||||||
opts.LocalMode = true
|
opts.LocalMode = true
|
||||||
opts.RepoPath = pwd
|
opts.RepoPath = pwd
|
||||||
opts.RepoMode = false
|
opts.RepoMode = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err := opts.guards()
|
||||||
|
if err != nil{
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,5 +85,4 @@ func TestGithubTarget(t *testing.T) {
|
|||||||
if !isGithubTarget("git@github.com:zricethezav/gitleaks.git") {
|
if !isGithubTarget("git@github.com:zricethezav/gitleaks.git") {
|
||||||
t.Error()
|
t.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user