Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Fix additional GitHub test errors #2614
Richard Gomez95dc8d6e16a8
diff --git a/pkg/sources/errors_test.go b/pkg/sources/errors_test.goindex d691e2b47..e7b9d3a03 100644--- a/pkg/sources/errors_test.go+++ b/pkg/sources/errors_test.go@@ -7,6 +7,8 @@ import ("testing")+var testError = fmt.Errorf("simulated failure")+func TestNewScanErrors(t *testing.T) {testCases := []struct {name string@@ -84,7 +86,7 @@ func TestScanErrorsAdd(t *testing.T) {wg.Add(1)go func() {for j := 0; j < tc.wantErr/tc.concurrency; j++ {- se.Add(nil)+ se.Add(testError)}wg.Done()}()@@ -135,7 +137,7 @@ func TestScanErrorsCount(t *testing.T) {wg.Add(1)go func() {for j := 0; j < tc.wantErrCnt/tc.concurrency; j++ {- se.Add(nil)+ se.Add(testError)}wg.Done()}()@@ -151,8 +153,8 @@ func TestScanErrorsCount(t *testing.T) {func TestScanErrorsString(t *testing.T) {se := NewScanErrors()- se.Add(nil)- want := "[]"+ se.Add(testError)+ want := `["` + testError.Error() + `"]`if got := fmt.Sprintf("%v", se); got != want {t.Errorf("got %q, want %q", got, want)}diff --git a/pkg/sources/github/github.go b/pkg/sources/github/github.goindex 112e7bc82..8cf0665cb 100644--- a/pkg/sources/github/github.go+++ b/pkg/sources/github/github.go@@ -1151,8 +1151,8 @@ func (s *Source) processGistComments(ctx context.Context, gistURL string, urlParreturn nil}-func extractGistID(url []string) string {- return url[len(url)-1]+func extractGistID(urlParts []string) string {+ return urlParts[len(urlParts)-1]}func (s *Source) chunkGistComments(ctx context.Context, gistURL string, gistInfo repoInfo, comments []*github.GistComment, chunksChan chan *sources.Chunk) error {diff --git a/pkg/sources/github/github_test.go b/pkg/sources/github/github_test.goindex defe9777d..9a8c362a5 100644--- a/pkg/sources/github/github_test.go+++ b/pkg/sources/github/github_test.go@@ -8,6 +8,7 @@ import ("encoding/pem""fmt""net/http"+ "net/url""reflect""strconv""testing"@@ -329,10 +330,35 @@ func TestHandleRateLimit(t *testing.T) {s := initTestSource(nil)assert.False(t, s.handleRateLimit(nil))- err := &github.RateLimitError{}- res := &github.Response{Response: &http.Response{Header: make(http.Header)}}+ // Request+ reqUrl, _ := url.Parse("https://github.com/trufflesecurity/trufflehog")+ res := &github.Response{+ Response: &http.Response{+ StatusCode: 429,+ Header: make(http.Header),+ Request: &http.Request{+ Method: "GET",+ URL: reqUrl,+ },+ },+ }res.Header.Set("x-ratelimit-remaining", "0")res.Header.Set("x-ratelimit-reset", strconv.FormatInt(time.Now().Unix()+1, 10))++ // Error+ resetTime := github.Timestamp{+ Time: time.Now().Add(time.Millisecond),+ }+ err := &github.RateLimitError{+ Rate: github.Rate{+ Limit: 5000,+ Remaining: 0,+ Reset: resetTime,+ },+ Response: res.Response,+ Message: "Too Many Requests",+ }+assert.True(t, s.handleRateLimit(err))}@@ -742,8 +768,6 @@ func TestGetGistID(t *testing.T) {}{{[]string{"https://gist.github.com", "12345"}, "12345"},{[]string{"https://gist.github.com", "owner", "12345"}, "12345"},- {[]string{"https://gist.github.com"}, ""},- {[]string{"https://gist.github.com", "owner", "12345", "extra"}, ""},}for _, tt := range tests {