Skip to content

Commit

Permalink
Backport: Fix address not returning on 10001+ list value (#3644)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferai committed Aug 30, 2023
1 parent d64d6c4 commit 89b770f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Canonical reference for changes, improvements, and bugfixes for Boundary.

## Next

### Bug Fixes

* 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)

### New and Improved
Expand Down
15 changes: 12 additions & 3 deletions internal/target/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
39 changes: 39 additions & 0 deletions internal/target/tcp/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

0 comments on commit 89b770f

Please sign in to comment.