handlers/scopes: test for pagination parameters

Note that this already always returned the pagination parameters,
but now we have a test that it does so.
pull/4373/head
Johan Brandhorst-Satzkorn 2 years ago
parent 0c9b963963
commit c7fa171248

@ -185,10 +185,6 @@ func (s *Service) ListScopes(ctx context.Context, req *pbs.ListScopesRequest) (*
if err != nil {
return nil, err
}
// If no scopes match, return an empty response
if len(scopeIds) == 0 {
return &pbs.ListScopesResponse{}, nil
}
pageSize := int(s.maxPageSize)
// Use the requested page size only if it is smaller than

@ -690,7 +690,7 @@ func TestListPagination(t *testing.T) {
return server.NewRepository(ctx, rw, rw, kms)
}
oWithProjects, p2 := iam.TestScopes(t, repo)
oWithProjects, p2 := iam.TestScopes(t, repo, iam.WithSkipDefaultRoleCreation(true))
_, err = repo.DeleteScope(context.Background(), p2.GetPublicId())
require.NoError(t, err)
@ -974,6 +974,28 @@ func TestListPagination(t *testing.T) {
protocmp.IgnoreFields(&pbs.ListScopesResponse{}, "list_token"),
),
)
// Create unauthenticated user
unauthAt := authtoken.TestAuthToken(t, conn, kms, oWithProjects.GetPublicId())
unauthR := iam.TestRole(t, conn, p.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)
_, err = s.ListScopes(ctx, &pbs.ListScopesRequest{
ScopeId: "global",
Recursive: true,
})
require.Error(t, err)
assert.ErrorIs(t, handlers.ForbiddenError(), err)
}
func TestDelete(t *testing.T) {

Loading…
Cancel
Save