internal/auth/oidc: ensure all managed groups are tested on auth (#5242)

Previously, we would list the managed groups with an implied
filter of db.DefaultLimit (10,000), which would incorrectly remove
a user from managed group memberships if there were more
than 10,000 managed groups in an auth method. Explicitly
set the list limit to unlimited to ensure all managed groups are
updated appropriately.
This commit is contained in:
Johan Brandhorst-Satzkorn authored and GitHub committed 2024-11-14 15:47:08 -08:00
1 parent 53e77e313a
commit d830bdd416
3 files changed
+7 -6

No files matched your search

@@ -111,7 +111,7 @@ func (r *Repository) SetManagedGroupMemberships(ctx context.Context, am *AuthMet
msgs = append(msgs, &mgOplogMsg)
}
currentMemberships, err = r.ListManagedGroupMembershipsByMember(ctx, acct.PublicId, WithReader(reader))
currentMemberships, err = r.ListManagedGroupMembershipsByMember(ctx, acct.PublicId, WithReader(reader), WithLimit(-1))
if err != nil {
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to retrieve current managed group memberships before deletion"))
}
@@ -181,7 +181,7 @@ func (r *Repository) SetManagedGroupMemberships(ctx context.Context, am *AuthMet
}
}
currentMemberships, err = r.ListManagedGroupMembershipsByMember(ctx, acct.PublicId, WithReader(reader))
currentMemberships, err = r.ListManagedGroupMembershipsByMember(ctx, acct.PublicId, WithReader(reader), WithLimit(-1))
if err != nil {
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to retrieve current managed group memberships after set"))
}
+1 -1
View File
@@ -193,7 +193,7 @@ func Callback(
}
// Get the set of all managed groups so we can filter
mgs, _, err := r.ListManagedGroups(ctx, am.GetPublicId())
mgs, _, err := r.ListManagedGroups(ctx, am.GetPublicId(), WithLimit(-1))
if err != nil {
return "", errors.Wrap(ctx, err, op)
}
+4 -3
View File
@@ -675,7 +675,8 @@ func Test_ManagedGroupFiltering(t *testing.T) {
return iam.NewRepository(ctx, rw, rw, kmsCache)
}
repoFn := func() (*Repository, error) {
return NewRepository(ctx, rw, rw, kmsCache)
// Set a low limit to test that the managed group listing overrides the limit
return NewRepository(ctx, rw, rw, kmsCache, WithLimit(1))
}
atRepoFn := func() (*authtoken.Repository, error) {
return authtoken.NewRepository(ctx, rw, rw, kmsCache)
@@ -819,7 +820,7 @@ func Test_ManagedGroupFiltering(t *testing.T) {
tp.SetExpectedState(state)
// Set the filters on the MGs for this test. First we need to get the current versions.
currMgs, ttime, err := repo.ListManagedGroups(ctx, testAuthMethod.PublicId)
currMgs, ttime, err := repo.ListManagedGroups(ctx, testAuthMethod.PublicId, WithLimit(-1))
require.NoError(err)
// Transaction timestamp should be within ~10 seconds of now
assert.True(time.Now().Before(ttime.Add(10 * time.Second)))
@@ -860,7 +861,7 @@ func Test_ManagedGroupFiltering(t *testing.T) {
assert.Contains(key.(map[string]any)["payload"], "auth_token_end")
}
// Ensure that we get the expected groups
memberships, err := repo.ListManagedGroupMembershipsByMember(ctx, account.PublicId)
memberships, err := repo.ListManagedGroupMembershipsByMember(ctx, account.PublicId, WithLimit(-1))
require.NoError(err)
assert.Equal(len(tt.matchingMgs), len(memberships))
var matchingIds []string