@ -50,43 +50,33 @@ func Test_NewPaginationToken(t *testing.T) {
} ,
} ,
{
name : "missing grants hash" ,
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : nil ,
lastItemId : "some id" ,
lastItemCreateTime : fiveDaysAgo ,
wantErrString : "missing grants hash" ,
wantErrCode : errors . InvalidParameter ,
} ,
{
name : "new created time" ,
createdTime : fiveDaysAgo . AddDate ( 1 , 0 , 0 ) ,
name : "missing create time" ,
createdTime : time . Time { } ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
lastItemId : "some id" ,
lastItemCreateTime : fiveDaysAgo ,
wantErrString : " create time is in the futur e",
wantErrString : "missing create time" ,
wantErrCode : errors . InvalidParameter ,
} ,
{
name : " old created tim e",
createdTime : fiveDaysAgo .AddDate ( - 1 , 0 , 0 ) ,
typ : resource . Target ,
name : "missing resource type" ,
createdTime : fiveDaysAgo ,
typ : resource . Unknown ,
grantsHash : [ ] byte ( "some hash" ) ,
lastItemId : "some id" ,
lastItemCreateTime : fiveDaysAgo ,
wantErrString : " create time is too old ",
wantErrString : " missing resource type ",
wantErrCode : errors . InvalidParameter ,
} ,
{
name : " new updated time ",
name : " missing grants hash ",
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
grantsHash : nil ,
lastItemId : "some id" ,
lastItemCreateTime : fiveDaysAgo .AddDate ( 1 , 0 , 0 ) ,
wantErrString : " last item create time is in the future ",
lastItemCreateTime : fiveDaysAgo ,
wantErrString : " missing grants hash ",
wantErrCode : errors . InvalidParameter ,
} ,
{
@ -100,13 +90,13 @@ func Test_NewPaginationToken(t *testing.T) {
wantErrCode : errors . InvalidParameter ,
} ,
{
name : " new last item updated time",
name : " missing last item create time",
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
lastItemId : "some id" ,
lastItemCreateTime : fiveDaysAgo. AddDate ( 1 , 0 , 0 ) ,
wantErrString : " last item create time is in the futur e",
lastItemCreateTime : time. Time { } ,
wantErrString : " missing last item create time",
wantErrCode : errors . InvalidParameter ,
} ,
}
@ -130,23 +120,23 @@ func Test_NewStartRefreshToken(t *testing.T) {
t . Parallel ( )
fiveDaysAgo := time . Now ( ) . AddDate ( 0 , 0 , - 5 )
tests := [ ] struct {
name string
createdTime time . Time
typ resource . Type
grantsHash [ ] byte
previousDeletedIdsTime time . Time
p haseLowerBound time . Time
want * listtoken . Token
wantErrString string
wantErrCode errors . Code
name string
createdTime time . Time
typ resource . Type
grantsHash [ ] byte
previousDeletedIdsTime time . Time
p reviousPhaseUpperBound time . Time
want * listtoken . Token
wantErrString string
wantErrCode errors . Code
} {
{
name : "valid list+start-refresh token" ,
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
previousDeletedIdsTime : fiveDaysAgo ,
p haseLowerBound: fiveDaysAgo ,
name : "valid list+start-refresh token" ,
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
previousDeletedIdsTime : fiveDaysAgo ,
p reviousPhaseUpperBound: fiveDaysAgo ,
want : & listtoken . Token {
CreateTime : fiveDaysAgo ,
ResourceType : resource . Target ,
@ -158,61 +148,61 @@ func Test_NewStartRefreshToken(t *testing.T) {
} ,
} ,
{
name : "missing grants hash ",
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : nil ,
previousDeletedIdsTime : fiveDaysAgo ,
p haseLowerBound: fiveDaysAgo ,
wantErrString : "missing grants hash ",
wantErrCode : errors . InvalidParameter ,
name : "missing create time ",
createdTime : time . Time { } ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
previousDeletedIdsTime : fiveDaysAgo ,
p reviousPhaseUpperBound: fiveDaysAgo ,
wantErrString : "missing create time ",
wantErrCode : errors . InvalidParameter ,
} ,
{
name : "new created tim e",
createdTime : fiveDaysAgo . AddDate ( 1 , 0 , 0 ) ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
previousDeletedIdsTime : fiveDaysAgo ,
p haseLowerBound: fiveDaysAgo ,
wantErrString : "create time is in the futur e",
wantErrCode : errors . InvalidParameter ,
name : "missing resource typ e",
createdTime : fiveDaysAgo ,
typ : resource . Unknown ,
grantsHash : [ ] byte ( "some hash" ) ,
previousDeletedIdsTime : fiveDaysAgo ,
p reviousPhaseUpperBound: fiveDaysAgo ,
wantErrString : "missing resource typ e",
wantErrCode : errors . InvalidParameter ,
} ,
{
name : "old created time ",
createdTime : fiveDaysAgo . AddDate ( - 1 , 0 , 0 ) ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
previousDeletedIdsTime : fiveDaysAgo ,
p haseLowerBound: fiveDaysAgo ,
wantErrString : "create time is too old ",
wantErrCode : errors . InvalidParameter ,
name : "missing grants hash ",
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : nil ,
previousDeletedIdsTime : fiveDaysAgo ,
p reviousPhaseUpperBound: fiveDaysAgo ,
wantErrString : "missing grants hash ",
wantErrCode : errors . InvalidParameter ,
} ,
{
name : "new previous deleted ids time",
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
previousDeletedIdsTime : fiveDaysAgo . AddDate ( 1 , 0 , 0 ) ,
p haseLowerBound: fiveDaysAgo ,
wantErrString : " previous deleted ids time is in the futur e",
wantErrCode : errors . InvalidParameter ,
name : "missing previous deleted ids time",
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
previousDeletedIdsTime : time . Time { } ,
p reviousPhaseUpperBound: fiveDaysAgo ,
wantErrString : " missing previous deleted ids time",
wantErrCode : errors . InvalidParameter ,
} ,
{
name : "new previous phase upper bound",
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
previousDeletedIdsTime : fiveDaysAgo ,
p haseLowerBound: fiveDaysAgo . AddDate ( 1 , 0 , 0 ) ,
wantErrString : " previous phase upper bound is in the future ",
wantErrCode : errors . InvalidParameter ,
name : "missing previous phase upper bound",
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
previousDeletedIdsTime : fiveDaysAgo ,
p reviousPhaseUpperBound: time . Time { } ,
wantErrString : " missing previous phase upper bound",
wantErrCode : errors . InvalidParameter ,
} ,
}
for _ , tt := range tests {
tt := tt
t . Run ( tt . name , func ( t * testing . T ) {
t . Parallel ( )
got , err := listtoken . NewStartRefresh ( context . Background ( ) , tt . createdTime , tt . typ , tt . grantsHash , tt . previousDeletedIdsTime , tt . p haseLow erBound)
got , err := listtoken . NewStartRefresh ( context . Background ( ) , tt . createdTime , tt . typ , tt . grantsHash , tt . previousDeletedIdsTime , tt . p reviousPhaseUpp erBound)
if tt . wantErrString != "" {
require . ErrorContains ( t , err , tt . wantErrString )
require . Equal ( t , errors . Convert ( err ) . Code , tt . wantErrCode )
@ -267,98 +257,85 @@ func Test_NewRefreshToken(t *testing.T) {
} ,
} ,
{
name : "missing grants hash ",
createdTime : fiveDaysAgo ,
name : "missing create time ",
createdTime : time. Time { } ,
typ : resource . Target ,
grantsHash : nil ,
grantsHash : [ ] byte ( "some hash" ) ,
phaseUpperBound : timeNow ,
phaseLowerBound : fiveDaysAgo ,
previousDeleteIdsTime : fiveDaysAgo ,
lastItemId : "some id" ,
lastItemUpdateTime : fourDaysAgo ,
wantErrString : "missing grants hash ",
wantErrString : "missing create time ",
wantErrCode : errors . InvalidParameter ,
} ,
{
name : " new created tim e",
createdTime : fiveDaysAgo .AddDate ( 1 , 0 , 0 ) ,
typ : resource . Target ,
name : " missing resource typ e",
createdTime : fiveDaysAgo ,
typ : resource . Unknown ,
grantsHash : [ ] byte ( "some hash" ) ,
phaseUpperBound : timeNow ,
phaseLowerBound : fiveDaysAgo ,
previousDeleteIdsTime : fiveDaysAgo ,
lastItemId : "some id" ,
lastItemUpdateTime : fourDaysAgo ,
wantErrString : " create time is in the futur e",
wantErrString : " missing resource typ e",
wantErrCode : errors . InvalidParameter ,
} ,
{
name : " old created time ",
createdTime : fiveDaysAgo .AddDate ( - 1 , 0 , 0 ) ,
name : " missing grants hash ",
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
grantsHash : nil ,
phaseUpperBound : timeNow ,
phaseLowerBound : fiveDaysAgo ,
previousDeleteIdsTime : fiveDaysAgo ,
lastItemId : "some id" ,
lastItemUpdateTime : fourDaysAgo ,
wantErrString : " create time is too old ",
wantErrString : " missing grants hash ",
wantErrCode : errors . InvalidParameter ,
} ,
{
name : " new previous deleted ids time",
name : " missing previous deleted ids time",
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
phaseUpperBound : timeNow ,
phaseLowerBound : fiveDaysAgo ,
previousDeleteIdsTime : fiveDaysAgo. AddDate ( 1 , 0 , 0 ) ,
previousDeleteIdsTime : time. Time { } ,
lastItemId : "some id" ,
lastItemUpdateTime : fourDaysAgo ,
wantErrString : " previous deleted ids time is in the futur e",
wantErrString : " missing previous deleted ids time",
wantErrCode : errors . InvalidParameter ,
} ,
{
name : " phase upper bound in future ",
name : " missing phase upper bound",
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
phaseUpperBound : time Now. AddDate ( 1 , 0 , 0 ) ,
phaseUpperBound : time . Time { } ,
phaseLowerBound : fiveDaysAgo ,
previousDeleteIdsTime : fiveDaysAgo ,
lastItemId : "some id" ,
lastItemUpdateTime : fourDaysAgo ,
wantErrString : " phase upper bound is in the future ",
wantErrString : " missing phase upper bound",
wantErrCode : errors . InvalidParameter ,
} ,
{
name : " phase lower bound in future ",
name : " missing phase lower bound",
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
phaseUpperBound : timeNow ,
phaseLowerBound : fiveDaysAgo . AddDate ( 1 , 0 , 0 ) ,
previousDeleteIdsTime : fiveDaysAgo ,
lastItemId : "some id" ,
lastItemUpdateTime : fourDaysAgo ,
wantErrString : "phase lower bound is in the future" ,
wantErrCode : errors . InvalidParameter ,
} ,
{
name : "phase lower bound newer than upper bound" ,
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
phaseUpperBound : fiveDaysAgo ,
phaseLowerBound : timeNow ,
phaseLowerBound : time . Time { } ,
previousDeleteIdsTime : fiveDaysAgo ,
lastItemId : "some id" ,
lastItemUpdateTime : fourDaysAgo ,
wantErrString : " phase lower bound is after phase upp er bound",
wantErrString : "missing phase lower bound" ,
wantErrCode : errors . InvalidParameter ,
} ,
{
name : "missing last item ID ",
name : "missing last item id" ,
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
@ -370,19 +347,6 @@ func Test_NewRefreshToken(t *testing.T) {
wantErrString : "missing last item ID" ,
wantErrCode : errors . InvalidParameter ,
} ,
{
name : "last item update time in future" ,
createdTime : fiveDaysAgo ,
typ : resource . Target ,
grantsHash : [ ] byte ( "some hash" ) ,
phaseUpperBound : timeNow ,
phaseLowerBound : fiveDaysAgo ,
previousDeleteIdsTime : fiveDaysAgo ,
lastItemId : "some id" ,
lastItemUpdateTime : fourDaysAgo . AddDate ( 1 , 0 , 0 ) ,
wantErrString : "last item update time is in the future" ,
wantErrCode : errors . InvalidParameter ,
} ,
}
for _ , tt := range tests {
tt := tt
@ -463,18 +427,6 @@ func Test_ValidateListToken(t *testing.T) {
wantErrString : "grants have changed since list token was issued" ,
wantErrCode : errors . InvalidListToken ,
} ,
{
name : "created in the future" ,
token : & listtoken . Token {
CreateTime : time . Now ( ) . AddDate ( 1 , 0 , 0 ) ,
ResourceType : resource . Target ,
GrantsHash : [ ] byte ( "some hash" ) ,
} ,
grantsHash : [ ] byte ( "some hash" ) ,
resourceType : resource . Target ,
wantErrString : "list token was created in the future" ,
wantErrCode : errors . InvalidListToken ,
} ,
{
name : "expired" ,
token : & listtoken . Token {
@ -569,7 +521,7 @@ func Test_ValidatePaginationToken(t *testing.T) {
} ,
grantsHash : [ ] byte ( "some hash" ) ,
resourceType : resource . Target ,
wantErrString : "list token's pagination component's last item was created in the future ",
wantErrString : "list token's pagination component's last item was created after the token ",
wantErrCode : errors . InvalidListToken ,
} ,
}
@ -629,22 +581,6 @@ func Test_ValidateStartRefreshToken(t *testing.T) {
wantErrString : "list token's start refresh component's previous phase upper bound was before its creation time" ,
wantErrCode : errors . InvalidListToken ,
} ,
{
name : "previous phase upper bound in future" ,
token : & listtoken . Token {
CreateTime : fiveDaysAgo ,
ResourceType : resource . Target ,
GrantsHash : [ ] byte ( "some hash" ) ,
Subtype : & listtoken . StartRefreshToken {
PreviousDeletedIdsTime : fiveDaysAgo ,
PreviousPhaseUpperBound : fiveDaysAgo . AddDate ( 1 , 0 , 0 ) ,
} ,
} ,
grantsHash : [ ] byte ( "some hash" ) ,
resourceType : resource . Target ,
wantErrString : "list token's start refresh component's previous phase upper bound was in the future" ,
wantErrCode : errors . InvalidListToken ,
} ,
{
name : "previous deleted ids time before create time" ,
token : & listtoken . Token {
@ -661,22 +597,6 @@ func Test_ValidateStartRefreshToken(t *testing.T) {
wantErrString : "list token's start refresh component previous deleted ids time was before its creation time" ,
wantErrCode : errors . InvalidListToken ,
} ,
{
name : "previous deleted ids time in future" ,
token : & listtoken . Token {
CreateTime : fiveDaysAgo ,
ResourceType : resource . Target ,
GrantsHash : [ ] byte ( "some hash" ) ,
Subtype : & listtoken . StartRefreshToken {
PreviousDeletedIdsTime : fiveDaysAgo . AddDate ( 1 , 0 , 0 ) ,
PreviousPhaseUpperBound : fiveDaysAgo ,
} ,
} ,
grantsHash : [ ] byte ( "some hash" ) ,
resourceType : resource . Target ,
wantErrString : "list token's start refresh component previous deleted ids time was in the future" ,
wantErrCode : errors . InvalidListToken ,
} ,
}
for _ , tt := range tests {
tt := tt
@ -759,25 +679,6 @@ func Test_ValidateRefreshToken(t *testing.T) {
wantErrString : "list token's refresh component's phase upper bound was before the phase lower bound" ,
wantErrCode : errors . InvalidListToken ,
} ,
{
name : "phase upper bound in future" ,
token : & listtoken . Token {
CreateTime : fiveDaysAgo ,
ResourceType : resource . Target ,
GrantsHash : [ ] byte ( "some hash" ) ,
Subtype : & listtoken . RefreshToken {
PhaseUpperBound : fiveDaysAgo . AddDate ( 1 , 0 , 0 ) ,
PreviousDeletedIdsTime : fiveDaysAgo ,
PhaseLowerBound : fiveDaysAgo ,
LastItemId : "some id" ,
LastItemUpdateTime : fiveDaysAgo ,
} ,
} ,
grantsHash : [ ] byte ( "some hash" ) ,
resourceType : resource . Target ,
wantErrString : "list token's refresh component's phase upper bound was in the future" ,
wantErrCode : errors . InvalidListToken ,
} ,
{
name : "phase lower bound before create time" ,
token : & listtoken . Token {
@ -797,25 +698,6 @@ func Test_ValidateRefreshToken(t *testing.T) {
wantErrString : "list token's refresh component's phase lower bound was before its creation time" ,
wantErrCode : errors . InvalidListToken ,
} ,
{
name : "phase lower bound in future" ,
token : & listtoken . Token {
CreateTime : fiveDaysAgo ,
ResourceType : resource . Target ,
GrantsHash : [ ] byte ( "some hash" ) ,
Subtype : & listtoken . RefreshToken {
PhaseUpperBound : fiveDaysAgo ,
PreviousDeletedIdsTime : fiveDaysAgo ,
PhaseLowerBound : fiveDaysAgo . AddDate ( 1 , 0 , 0 ) ,
LastItemId : "some id" ,
LastItemUpdateTime : fiveDaysAgo ,
} ,
} ,
grantsHash : [ ] byte ( "some hash" ) ,
resourceType : resource . Target ,
wantErrString : "list token's refresh component's phase lower bound was in the future" ,
wantErrCode : errors . InvalidListToken ,
} ,
{
name : "previous deleted ids time before create time" ,
token : & listtoken . Token {
@ -835,25 +717,6 @@ func Test_ValidateRefreshToken(t *testing.T) {
wantErrString : "list token's refresh component previous deleted ids time was before its creation time" ,
wantErrCode : errors . InvalidListToken ,
} ,
{
name : "previous deleted ids time in future" ,
token : & listtoken . Token {
CreateTime : fiveDaysAgo ,
ResourceType : resource . Target ,
GrantsHash : [ ] byte ( "some hash" ) ,
Subtype : & listtoken . RefreshToken {
PhaseUpperBound : fiveDaysAgo ,
PreviousDeletedIdsTime : fiveDaysAgo . AddDate ( 1 , 0 , 0 ) ,
PhaseLowerBound : fiveDaysAgo ,
LastItemId : "some id" ,
LastItemUpdateTime : fiveDaysAgo ,
} ,
} ,
grantsHash : [ ] byte ( "some hash" ) ,
resourceType : resource . Target ,
wantErrString : "list token's refresh component previous deleted ids time was in the future" ,
wantErrCode : errors . InvalidListToken ,
} ,
{
name : "emtpy last item id" ,
token : & listtoken . Token {
@ -873,25 +736,6 @@ func Test_ValidateRefreshToken(t *testing.T) {
wantErrString : "list token's refresh component missing last item ID" ,
wantErrCode : errors . InvalidListToken ,
} ,
{
name : "last item update in future" ,
token : & listtoken . Token {
CreateTime : fiveDaysAgo ,
ResourceType : resource . Target ,
GrantsHash : [ ] byte ( "some hash" ) ,
Subtype : & listtoken . RefreshToken {
PhaseUpperBound : fiveDaysAgo ,
PreviousDeletedIdsTime : fiveDaysAgo ,
PhaseLowerBound : fiveDaysAgo ,
LastItemId : "some id" ,
LastItemUpdateTime : fiveDaysAgo . AddDate ( 1 , 0 , 0 ) ,
} ,
} ,
grantsHash : [ ] byte ( "some hash" ) ,
resourceType : resource . Target ,
wantErrString : "list token's refresh component's last item was updated in the future" ,
wantErrCode : errors . InvalidListToken ,
} ,
}
for _ , tt := range tests {
tt := tt