Skip to content

Find, verify, and analyze leaked credentials

Separate org listing error from finding 0 members error cases (#3654)

trufflesteeeve3c69bbc74f57
diff --git a/pkg/sources/github/github.go b/pkg/sources/github/github.go
index 680a7b42f..ebf5d4501 100644
--- a/pkg/sources/github/github.go
+++ b/pkg/sources/github/github.go
@@ -958,8 +958,11 @@ func (s *Source) addMembersByOrg(ctx context.Context, org string) error {
if s.handleRateLimit(ctx, err) {
continue
}
- if err != nil || len(members) == 0 {
- return fmt.Errorf("could not list organization members: account may not have access to list organization members %w", err)
+ if err != nil {
+ return fmt.Errorf("could not list organization (%q) members: account may not have access to list organization members: %w", org, err)
+ }
+ if len(members) == 0 {
+ return fmt.Errorf("organization (%q) had 0 members: account may not have access to list organization members", org)
}
logger.V(2).Info("Listed members", "page", opts.Page, "last_page", res.LastPage)
diff --git a/pkg/sources/github/github_test.go b/pkg/sources/github/github_test.go
index 3eda8bdba..ee49c1dc0 100644
--- a/pkg/sources/github/github_test.go
+++ b/pkg/sources/github/github_test.go
@@ -13,6 +13,7 @@ import (
"reflect"
"slices"
"strconv"
+ "strings"
"testing"
"time"
@@ -207,6 +208,41 @@ func TestAddMembersByOrg(t *testing.T) {
assert.True(t, gock.IsDone())
}
+func TestAddMembersByOrg_AuthFailure(t *testing.T) {
+ defer gock.Off()
+
+ gock.New("https://api.github.com").
+ Get("/orgs/org1/members").
+ Reply(401).
+ JSON([]map[string]string{{
+ "message": "Bad credentials",
+ "documentation_url": "https://docs.github.com/rest",
+ "status": "401",
+ }})
+
+ s := initTestSource(&sourcespb.GitHub{Credential: &sourcespb.GitHub_Unauthenticated{}})
+ err := s.addMembersByOrg(context.Background(), "org1")
+ assert.True(t, strings.HasPrefix(err.Error(), "could not list organization"))
+ assert.False(t, gock.HasUnmatchedRequest())
+ assert.True(t, gock.IsDone())
+}
+
+func TestAddMembersByOrg_NoMembers(t *testing.T) {
+ defer gock.Off()
+
+ gock.New("https://api.github.com").
+ Get("/orgs/org1/members").
+ Reply(200).
+ JSON([]map[string]string{})
+
+ s := initTestSource(&sourcespb.GitHub{Credential: &sourcespb.GitHub_Unauthenticated{}})
+ err := s.addMembersByOrg(context.Background(), "org1")
+
+ assert.Equal(t, fmt.Sprintf("organization (%q) had 0 members: account may not have access to list organization members", "org1"), err.Error())
+ assert.False(t, gock.HasUnmatchedRequest())
+ assert.True(t, gock.IsDone())
+}
+
func TestAddMembersByApp(t *testing.T) {
defer gock.Off()