mirror of https://github.com/hashicorp/boundary
Target pagination e2e test (#4010)
* testing/e2e: Use a separate config file for database init The other config file contains templated parameters, which was causing errors when loading the config file, even though the values were never used. * testing/e2e: add target pagination test Exercises target pagination both over the CLI and the API. These tests run in <10s on my machine, though they each involve creating 1000 targets (with current defaults). --------- Co-authored-by: Michael Li <michael.li@hashicorp.com>pull/4202/head
parent
acc048a1d1
commit
6198fe279e
@ -0,0 +1,53 @@
|
||||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
disable_mlock = true
|
||||
|
||||
controller {
|
||||
name = "docker-controller"
|
||||
|
||||
database {
|
||||
url = "env://BOUNDARY_POSTGRES_URL"
|
||||
}
|
||||
}
|
||||
|
||||
kms "aead" {
|
||||
purpose = "root"
|
||||
aead_type = "aes-gcm"
|
||||
key = "sP1fnF5Xz85RrXyELHFeZg9Ad2qt4Z4bgNHVGtD6ung="
|
||||
key_id = "global_root"
|
||||
}
|
||||
|
||||
# This key_id needs to match the corresponding downstream worker's
|
||||
# "worker-auth" kms
|
||||
kms "aead" {
|
||||
purpose = "worker-auth"
|
||||
aead_type = "aes-gcm"
|
||||
key = "OLFhJNbEb3umRjdhY15QKNEmNXokY1Iq"
|
||||
key_id = "global_worker-auth"
|
||||
}
|
||||
|
||||
kms "aead" {
|
||||
purpose = "recovery"
|
||||
aead_type = "aes-gcm"
|
||||
key = "8fZBjCUfN0TzjEGLQldGY4+iE9AkOvCfjh7+p0GtRBQ="
|
||||
key_id = "global_recovery"
|
||||
}
|
||||
|
||||
events {
|
||||
audit_enabled = true
|
||||
observations_enabled = true
|
||||
sysevents_enabled = true
|
||||
|
||||
sink "stderr" {
|
||||
name = "all-events"
|
||||
description = "All events sent to stderr"
|
||||
event_types = ["*"]
|
||||
format = "cloudevents-json"
|
||||
|
||||
deny_filters = [
|
||||
"\"/data/request_info/method\" contains \"Status\"",
|
||||
"\"/data/request_info/path\" contains \"/health\"",
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,198 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package base_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api/scopes"
|
||||
"github.com/hashicorp/boundary/api/targets"
|
||||
"github.com/hashicorp/boundary/internal/target"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestCliPaginateTargets asserts that the CLI automatically paginates to retrieve
|
||||
// all targets in a single invocation.
|
||||
func TestCliPaginateTargets(t *testing.T) {
|
||||
e2e.MaybeSkipTest(t)
|
||||
c, err := loadTestConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
newOrgId := boundary.CreateNewOrgCli(t, ctx)
|
||||
t.Cleanup(func() {
|
||||
ctx := context.Background()
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
|
||||
|
||||
// Create enough targets to overflow a single page.
|
||||
// Use the API to make creation faster.
|
||||
client, err := boundary.NewApiClient()
|
||||
require.NoError(t, err)
|
||||
tClient := targets.NewClient(client)
|
||||
targetPort, err := strconv.ParseInt(c.TargetPort, 10, 32)
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < c.MaxPageSize+1; i++ {
|
||||
_, err := tClient.Create(ctx, "tcp", newProjectId,
|
||||
targets.WithName("test-target-"+strconv.Itoa(i)),
|
||||
targets.WithTcpTargetDefaultPort(uint32(targetPort)),
|
||||
targets.WithAddress(c.TargetAddress),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// List targets recursively
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"targets", "list",
|
||||
"-scope-id", newProjectId,
|
||||
"-format=json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
var initialTargets targets.TargetListResult
|
||||
err = json.Unmarshal(output.Stdout, &initialTargets)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, initialTargets.Items, c.MaxPageSize+1)
|
||||
// Note that none of these are returned to the CLI for now.
|
||||
assert.Empty(t, initialTargets.ResponseType)
|
||||
assert.Empty(t, initialTargets.RemovedIds)
|
||||
assert.Empty(t, initialTargets.ListToken)
|
||||
|
||||
// Create a new target and destroy one of the other targets
|
||||
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort, target.WithAddress(c.TargetAddress))
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"targets", "delete",
|
||||
"-id", initialTargets.Items[0].Id,
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
// List again, should have the new target but not the deleted target
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"targets", "list",
|
||||
"-scope-id", newProjectId,
|
||||
"-format=json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
var newTargets targets.TargetListResult
|
||||
err = json.Unmarshal(output.Stdout, &newTargets)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, newTargets.Items, c.MaxPageSize+1)
|
||||
// The first item should be the most recently created, which
|
||||
// should be our new target
|
||||
firstItem := newTargets.Items[0]
|
||||
assert.Equal(t, newTargetId, firstItem.Id)
|
||||
assert.Empty(t, newTargets.ResponseType)
|
||||
assert.Empty(t, newTargets.RemovedIds)
|
||||
assert.Empty(t, newTargets.ListToken)
|
||||
// Ensure the deleted targeted isn't returned
|
||||
for _, target := range newTargets.Items {
|
||||
assert.NotEqual(t, target.Id, initialTargets.Items[0].Id)
|
||||
}
|
||||
}
|
||||
|
||||
// TestApiPaginateTargets asserts that the API automatically paginates to retrieve
|
||||
// all targets in a single invocation.
|
||||
func TestApiPaginateTargets(t *testing.T) {
|
||||
e2e.MaybeSkipTest(t)
|
||||
c, err := loadTestConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
client, err := boundary.NewApiClient()
|
||||
require.NoError(t, err)
|
||||
ctx := context.Background()
|
||||
sClient := scopes.NewClient(client)
|
||||
tClient := targets.NewClient(client)
|
||||
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
|
||||
t.Cleanup(func() {
|
||||
ctx := context.Background()
|
||||
_, err := sClient.Delete(ctx, newOrgId)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
|
||||
|
||||
// Create enough targets to overflow a single page.
|
||||
targetPort, err := strconv.ParseInt(c.TargetPort, 10, 32)
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < c.MaxPageSize+1; i++ {
|
||||
_, err := tClient.Create(ctx, "tcp", newProjectId,
|
||||
targets.WithName("test-target-"+strconv.Itoa(i)),
|
||||
targets.WithTcpTargetDefaultPort(uint32(targetPort)),
|
||||
targets.WithAddress(c.TargetAddress),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// List targets recursively
|
||||
initialTargets, err := tClient.List(ctx, newProjectId)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, initialTargets.Items, c.MaxPageSize+1)
|
||||
assert.Equal(t, "complete", initialTargets.ResponseType)
|
||||
assert.Empty(t, initialTargets.RemovedIds)
|
||||
assert.NotEmpty(t, initialTargets.ListToken)
|
||||
mapItems, ok := initialTargets.GetResponse().Map["items"]
|
||||
require.True(t, ok)
|
||||
mapSliceItems, ok := mapItems.([]any)
|
||||
require.True(t, ok)
|
||||
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
|
||||
|
||||
// Create a new target and destroy one of the other targets
|
||||
newTargetResult, err := tClient.Create(ctx, "tcp", newProjectId,
|
||||
targets.WithName("test-target-"+strconv.Itoa(c.MaxPageSize+1)),
|
||||
targets.WithTcpTargetDefaultPort(uint32(targetPort)),
|
||||
targets.WithAddress(c.TargetAddress),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
_, err = tClient.Delete(ctx, initialTargets.Items[0].Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// List again, should have the new and deleted target
|
||||
newTargets, err := tClient.List(ctx, newProjectId, targets.WithListToken(initialTargets.ListToken))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Note that this will likely contain all the targets,
|
||||
// since they were created very shortly before the listing,
|
||||
// and we add a 30 second buffer to the lower bound of update
|
||||
// times when listing.
|
||||
require.GreaterOrEqual(t, len(newTargets.Items), 1)
|
||||
// The first item should be the most recently created, which
|
||||
// should be our new target
|
||||
firstItem := newTargets.Items[0]
|
||||
assert.Equal(t, newTargetResult.Item.Id, firstItem.Id)
|
||||
assert.Equal(t, "complete", newTargets.ResponseType)
|
||||
// Note that the removed IDs may contain entries from other tests,
|
||||
// so just check that there is at least 1 entry and that our entry
|
||||
// is somewhere in the list.
|
||||
require.GreaterOrEqual(t, len(newTargets.RemovedIds), 1)
|
||||
assert.True(t, slices.ContainsFunc(newTargets.RemovedIds, func(targetId string) bool {
|
||||
return targetId == initialTargets.Items[0].Id
|
||||
}))
|
||||
assert.NotEmpty(t, newTargets.ListToken)
|
||||
// Check that the response map contains all entries
|
||||
mapItems, ok = newTargets.GetResponse().Map["items"]
|
||||
require.True(t, ok)
|
||||
mapSliceItems, ok = mapItems.([]any)
|
||||
require.True(t, ok)
|
||||
assert.GreaterOrEqual(t, len(mapSliceItems), 1)
|
||||
}
|
||||
Loading…
Reference in new issue