From fd959d15a6898bfb708f75f4df03ce6c675a28b3 Mon Sep 17 00:00:00 2001 From: Johan Brandhorst-Satzkorn Date: Wed, 14 Feb 2024 18:08:58 -0800 Subject: [PATCH] handlers/authtokens: test for pagination parameters Note that this already always returned the pagination parameters, but now we have a test that it does so. --- .../handlers/authtokens/authtoken_service.go | 4 --- .../authtokens/authtoken_service_test.go | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/internal/daemon/controller/handlers/authtokens/authtoken_service.go b/internal/daemon/controller/handlers/authtokens/authtoken_service.go index 12489b539c..8c66454e6b 100644 --- a/internal/daemon/controller/handlers/authtokens/authtoken_service.go +++ b/internal/daemon/controller/handlers/authtokens/authtoken_service.go @@ -103,10 +103,6 @@ func (s Service) ListAuthTokens(ctx context.Context, req *pbs.ListAuthTokensRequ if err != nil { return nil, errors.Wrap(ctx, err, op) } - // If no scopes match, return an empty response - if len(scopeIds) == 0 { - return &pbs.ListAuthTokensResponse{}, nil - } pageSize := int(s.maxPageSize) // Use the requested page size only if it is smaller than diff --git a/internal/daemon/controller/handlers/authtokens/authtoken_service_test.go b/internal/daemon/controller/handlers/authtokens/authtoken_service_test.go index 61937220ed..3ee1892dcc 100644 --- a/internal/daemon/controller/handlers/authtokens/authtoken_service_test.go +++ b/internal/daemon/controller/handlers/authtokens/authtoken_service_test.go @@ -790,6 +790,31 @@ func TestListPagination(t *testing.T) { protocmp.IgnoreFields(&pbs.ListAuthTokensResponse{}, "list_token"), ), ) + + // Create unauthenticated user + unauthAt := authtoken.TestAuthToken(t, conn, kms, orgWithTokens.GetPublicId()) + unauthR := iam.TestRole(t, conn, pwt.GetPublicId()) + _ = iam.TestUserRole(t, conn, unauthR.GetPublicId(), unauthAt.GetIamUserId()) + + // Make a request with the unauthenticated user, + // ensure the response contains the pagination parameters. + requestInfo = authpb.RequestInfo{ + TokenFormat: uint32(auth.AuthTokenTypeBearer), + PublicId: unauthAt.GetPublicId(), + Token: unauthAt.GetToken(), + } + requestContext = context.WithValue(context.Background(), requests.ContextRequestInformationKey, &requests.RequestContext{}) + ctx = auth.NewVerifierContext(requestContext, iamRepoFn, tokenRepoFn, serversRepoFn, kms, &requestInfo) + + got, err = a.ListAuthTokens(ctx, &pbs.ListAuthTokensRequest{ + ScopeId: "global", + Recursive: true, + }) + require.NoError(t, err) + assert.Len(t, got.Items, 1) // There will always be at least one token, the token used to authenticate + assert.Equal(t, "created_time", got.SortBy) + assert.Equal(t, "desc", got.SortDir) + assert.Equal(t, "complete", got.ResponseType) } func TestDeleteSelf(t *testing.T) {