diff --git a/src/gitleaks_test.go b/src/gitleaks_test.go index 57406529..f5c7c1a1 100644 --- a/src/gitleaks_test.go +++ b/src/gitleaks_test.go @@ -64,22 +64,22 @@ func TestGetRepo(t *testing.T) { Repo: "https://github.com/gitleakstest/nope", }, description: "test no repo", - expectedErrMsg: "authentication required", + expectedErrMsg: "repository not found", }, { testOpts: &Options{ Repo: "https://github.com/gitleakstest/private", }, description: "test private repo", - expectedErrMsg: "authentication required", + expectedErrMsg: "repository not found", }, { testOpts: &Options{ Repo: "https://github.com/gitleakstest/private", Disk: true, }, - description: "test private repo", - expectedErrMsg: "authentication required", + description: "test private repo disk", + expectedErrMsg: "repository not found", }, } g := goblin.Goblin(t) diff --git a/src/repo.go b/src/repo.go index 59707a50..c73b3c63 100644 --- a/src/repo.go +++ b/src/repo.go @@ -78,10 +78,17 @@ func (repoInfo *RepoInfo) clone() error { }) } else { // public - repo, err = git.PlainClone(cloneTarget, false, &git.CloneOptions{ + options := &git.CloneOptions{ URL: opts.Repo, Progress: os.Stdout, - }) + } + if os.Getenv("GITHUB_TOKEN") != "" { + options.Auth = &gitHttp.BasicAuth{ + Username: "fakeUsername", // yes, this can be anything except an empty string + Password: os.Getenv("GITHUB_TOKEN"), + } + } + repo, err = git.PlainClone(cloneTarget, false, options) } } else if repoInfo.path != "" { log.Infof("opening %s", repoInfo.path)