From f4587aaf05aeb52378dfe152d9ca043a828d1ce5 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Tue, 29 Aug 2023 16:21:23 -0400 Subject: [PATCH] Fix address not returning on 10001+ list value Fixes ICU-10786 --- CHANGELOG.md | 6 +++- internal/target/repository.go | 15 ++++++++-- internal/target/tcp/repository_test.go | 39 ++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cdb7f9804..271fa2f34c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,11 @@ Canonical reference for changes, improvements, and bugfixes for Boundary. ### Bug Fixes -* LDAP auth methods: allow bind-dn and bind-password to be updated independently. ([PR](https://github.com/hashicorp/boundary/pull/3511)) +* LDAP auth methods: allow bind-dn and bind-password to be updated + independently. ([PR](https://github.com/hashicorp/boundary/pull/3511)) +* targets: Fix address field not being populated if the number of targets on a + list returns more than 10000 entries + ([PR](https://github.com/hashicorp/boundary/pull/3644)) ## 0.13.1 (2023/07/10) diff --git a/internal/target/repository.go b/internal/target/repository.go index af38693ec8..f0fd1197a6 100644 --- a/internal/target/repository.go +++ b/internal/target/repository.go @@ -250,8 +250,12 @@ func (r *Repository) ListTargets(ctx context.Context, opt ...Option) ([]Target, } var foundTargets []*targetView - err := r.reader.SearchWhere(ctx, &foundTargets, strings.Join(where, " or "), args, - db.WithLimit(limit)) + err := r.reader.SearchWhere(ctx, + &foundTargets, + strings.Join(where, " or "), + args, + db.WithLimit(limit), + ) if err != nil { return nil, errors.Wrap(ctx, err, op) } @@ -263,7 +267,12 @@ func (r *Repository) ListTargets(ctx context.Context, opt ...Option) ([]Target, addresses := map[string]string{} var foundAddresses []*Address - err = r.reader.SearchWhere(ctx, &foundAddresses, "target_id in (?)", []any{targetIds}) + err = r.reader.SearchWhere(ctx, + &foundAddresses, + "target_id in (?)", + []any{targetIds}, + db.WithLimit(limit), + ) if err != nil { return nil, errors.Wrap(ctx, err, op) } diff --git a/internal/target/tcp/repository_test.go b/internal/target/tcp/repository_test.go index f4a576ecf9..c4091dc757 100644 --- a/internal/target/tcp/repository_test.go +++ b/internal/target/tcp/repository_test.go @@ -271,3 +271,42 @@ func TestRepository_DeleteTarget(t *testing.T) { }) } } + +func TestRepository_ListRoles_Above_Default_Count(t *testing.T) { + t.Parallel() + ctx := context.Background() + conn, _ := db.TestSetup(t, "postgres") + wrapper := db.TestWrapper(t) + testKms := kms.TestKms(t, conn, wrapper) + iamRepo := iam.TestRepo(t, conn, wrapper) + + _, proj := iam.TestScopes(t, iamRepo) + + numToCreate := db.DefaultLimit + 5 + var total int + for i := 0; i < numToCreate; i++ { + tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), fmt.Sprintf("proj1-%d", i), target.WithAddress("1.2.3.4")) + total++ + } + require.Equal(t, numToCreate, total) + + rw := db.New(conn) + repo, err := target.NewRepository(ctx, rw, rw, testKms, + target.WithPermissions([]perms.Permission{ + { + ScopeId: proj.PublicId, + Resource: resource.Target, + Action: action.List, + All: true, + }, + })) + require.NoError(t, err) + + got, err := repo.ListTargets(ctx, target.WithLimit(-1)) + require.NoError(t, err) + assert.Equal(t, total, len(got)) + + for _, tar := range got { + assert.Equal(t, "1.2.3.4", tar.GetAddress()) + } +}