internal/target: validate token resource type
This commit is contained in:
1 parent
3288f78f12
commit
025ef0d9ca
4 files changed
+39
No files matched your search
@@ -183,6 +183,16 @@ func TestService_List(t *testing.T) {
|
||||
_, err = target.ListPage(ctx, []byte("some hash"), 1, filterFunc, tok, nil)
|
||||
require.ErrorContains(t, err, "missing repo")
|
||||
})
|
||||
t.Run("wrong token resource type", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
filterFunc := func(_ context.Context, t target.Target) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
tok, err := listtoken.NewPagination(ctx, fiveDaysAgo, resource.Session, []byte("some hash"), "some-id", fiveDaysAgo)
|
||||
require.NoError(t, err)
|
||||
_, err = target.ListPage(ctx, []byte("some hash"), 1, filterFunc, tok, repo)
|
||||
require.ErrorContains(t, err, "token did not have a target resource type")
|
||||
})
|
||||
})
|
||||
t.Run("ListRefresh validation", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -251,6 +261,16 @@ func TestService_List(t *testing.T) {
|
||||
_, err = target.ListRefresh(ctx, []byte("some hash"), 1, filterFunc, tok, nil)
|
||||
require.ErrorContains(t, err, "missing repo")
|
||||
})
|
||||
t.Run("wrong token resource type", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
filterFunc := func(_ context.Context, t target.Target) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
tok, err := listtoken.NewStartRefresh(ctx, fiveDaysAgo, resource.Session, []byte("some hash"), fiveDaysAgo, fiveDaysAgo)
|
||||
require.NoError(t, err)
|
||||
_, err = target.ListRefresh(ctx, []byte("some hash"), 1, filterFunc, tok, repo)
|
||||
require.ErrorContains(t, err, "token did not have a target resource type")
|
||||
})
|
||||
})
|
||||
t.Run("ListRefreshPage validation", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -319,6 +339,16 @@ func TestService_List(t *testing.T) {
|
||||
_, err = target.ListRefreshPage(ctx, []byte("some hash"), 1, filterFunc, tok, nil)
|
||||
require.ErrorContains(t, err, "missing repo")
|
||||
})
|
||||
t.Run("wrong token resource type", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
filterFunc := func(_ context.Context, t target.Target) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
tok, err := listtoken.NewRefresh(ctx, fiveDaysAgo, resource.Session, []byte("some hash"), fiveDaysAgo, fiveDaysAgo, fiveDaysAgo, "some other id", fiveDaysAgo)
|
||||
require.NoError(t, err)
|
||||
_, err = target.ListRefreshPage(ctx, []byte("some hash"), 1, filterFunc, tok, repo)
|
||||
require.ErrorContains(t, err, "token did not have a target resource type")
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("simple pagination", func(t *testing.T) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
"github.com/hashicorp/boundary/internal/listtoken"
|
||||
"github.com/hashicorp/boundary/internal/pagination"
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
)
|
||||
|
||||
// ListPage lists up to page size targets, filtering out entries that
|
||||
@@ -39,6 +40,8 @@ func ListPage(
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing token")
|
||||
case repo == nil:
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing repo")
|
||||
case tok.ResourceType != resource.Target:
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "token did not have a target resource type")
|
||||
}
|
||||
if _, ok := tok.Subtype.(*listtoken.PaginationToken); !ok {
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "token did not have a pagination token component")
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
"github.com/hashicorp/boundary/internal/listtoken"
|
||||
"github.com/hashicorp/boundary/internal/pagination"
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
)
|
||||
|
||||
// ListRefresh lists up to page size targets, filtering out entries that
|
||||
@@ -43,6 +44,8 @@ func ListRefresh(
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing token")
|
||||
case repo == nil:
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing repo")
|
||||
case tok.ResourceType != resource.Target:
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "token did not have a target resource type")
|
||||
}
|
||||
rt, ok := tok.Subtype.(*listtoken.StartRefreshToken)
|
||||
if !ok {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
"github.com/hashicorp/boundary/internal/listtoken"
|
||||
"github.com/hashicorp/boundary/internal/pagination"
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
)
|
||||
|
||||
// ListRefreshPage lists up to page size targets, filtering out entries that
|
||||
@@ -43,6 +44,8 @@ func ListRefreshPage(
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing token")
|
||||
case repo == nil:
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing repo")
|
||||
case tok.ResourceType != resource.Target:
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "token did not have a target resource type")
|
||||
}
|
||||
rt, ok := tok.Subtype.(*listtoken.RefreshToken)
|
||||
if !ok {
|
||||
|
||||
Reference in new issue
Block a user