Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
bug fix: UnitErr and UnitOK called for the same repo (#4681)
Mustansir2fdab87df9a8
diff --git a/pkg/sources/github/github.go b/pkg/sources/github/github.goindex 00549df61..27832de46 100644--- a/pkg/sources/github/github.go+++ b/pkg/sources/github/github.go@@ -410,6 +410,7 @@ func (s *Source) Enumerate(ctx context.Context, reporter sources.UnitReporter) eif err := dedupeReporter.UnitErr(ctx, err); err != nil {return err}+ continue}if err := dedupeReporter.UnitOk(ctx, RepoUnit{Name: name, URL: url}); err != nil {return errdiff --git a/pkg/sources/github/github_test.go b/pkg/sources/github/github_test.goindex 31708c4ab..f28660aa2 100644--- a/pkg/sources/github/github_test.go+++ b/pkg/sources/github/github_test.go@@ -1149,3 +1149,37 @@ func noopReporter() sources.UnitReporter {},}}++// This tests reproduces a bug where both VisitUnit and VisitErr were called+// for the same repository when caching the repository info failed.+func TestFixBothUnitErrAndUnitOKCalled(t *testing.T) {+ cache := simple.NewCache[string]()+ cache.Set("myorg/myrepo", "an invalid url that will cause an error")+ s := &Source{+ filteredRepoCache: &filteredRepoCache{+ Cache: cache,+ },+ conn: &sourcespb.GitHub{+ Repositories: []string{"myorg/myrepo"},+ },+ orgsCache: simple.NewCache[string](),+ }++ var okCalled, errCalled bool+ reporter := sources.VisitorReporter{+ VisitUnit: func(ctx context.Context, su sources.SourceUnit) error {+ okCalled = true+ return nil+ },+ VisitErr: func(ctx context.Context, err error) error {+ errCalled = true+ return nil+ },+ }+ err := s.Enumerate(context.Background(), reporter)+ require.NoError(t, err)++ // expectation is that only VisitErr is called+ assert.True(t, errCalled)+ assert.False(t, okCalled)+}