Rename refresh token errors to list error (#4138)

This commit is contained in:
Todd authored and Johan Brandhorst-Satzkorn committed 2024-01-05 07:43:20 -08:00
1 parent a1bc2be136
commit 2d18f82c9f
9 files changed
+21 -21

No files matched your search

+5 -5
View File
@@ -11,11 +11,11 @@ import (
)
var (
ErrNotFound = &Error{Kind: codes.NotFound.String(), response: &Response{resp: &http.Response{StatusCode: http.StatusNotFound}}}
ErrInvalidArgument = &Error{Kind: codes.InvalidArgument.String(), response: &Response{resp: &http.Response{StatusCode: http.StatusBadRequest}}}
ErrPermissionDenied = &Error{Kind: codes.PermissionDenied.String(), response: &Response{resp: &http.Response{StatusCode: http.StatusForbidden}}}
ErrUnauthorized = &Error{Kind: codes.Unauthenticated.String(), response: &Response{resp: &http.Response{StatusCode: http.StatusUnauthorized}}}
ErrInvalidRefreshToken = &Error{Kind: "invalid refresh token", response: &Response{resp: &http.Response{StatusCode: http.StatusBadRequest}}}
ErrNotFound = &Error{Kind: codes.NotFound.String(), response: &Response{resp: &http.Response{StatusCode: http.StatusNotFound}}}
ErrInvalidArgument = &Error{Kind: codes.InvalidArgument.String(), response: &Response{resp: &http.Response{StatusCode: http.StatusBadRequest}}}
ErrPermissionDenied = &Error{Kind: codes.PermissionDenied.String(), response: &Response{resp: &http.Response{StatusCode: http.StatusForbidden}}}
ErrUnauthorized = &Error{Kind: codes.Unauthenticated.String(), response: &Response{resp: &http.Response{StatusCode: http.StatusUnauthorized}}}
ErrInvalidListToken = &Error{Kind: "invalid list token", response: &Response{resp: &http.Response{StatusCode: http.StatusBadRequest}}}
)
// AsServerError returns an api *Error from the provided error. If the provided error
+1 -1
View File
@@ -66,7 +66,7 @@ func testFullFetchRetrievalFunc[T any](t *testing.T, ret []T) func(context.Conte
func testErroringForRefreshTokenRetrievalFunc[T any](t *testing.T, ret []T) func(context.Context, string, string, RefreshTokenValue) ([]T, []string, RefreshTokenValue, error) {
return func(ctx context.Context, s1, s2 string, refToken RefreshTokenValue) ([]T, []string, RefreshTokenValue, error) {
if refToken != "" {
return nil, nil, "", api.ErrInvalidRefreshToken
return nil, nil, "", api.ErrInvalidListToken
}
return ret, nil, "1", nil
}
+2 -2
View File
@@ -35,7 +35,7 @@ func defaultSessionFunc(ctx context.Context, addr, authTok string, refreshTok Re
sClient := sessions.NewClient(client)
l, err := sClient.List(ctx, "global", sessions.WithIncludeTerminated(true), sessions.WithRecursive(true), sessions.WithListToken(string(refreshTok)))
if err != nil {
if api.ErrInvalidRefreshToken.Is(err) {
if api.ErrInvalidListToken.Is(err) {
return nil, nil, "", err
}
return nil, nil, "", errors.Wrap(ctx, err, op)
@@ -82,7 +82,7 @@ func (r *Repository) refreshSessions(ctx context.Context, u *user, tokens map[Au
var retErr error
for at, t := range tokens {
resp, removedIds, newRefreshToken, err = opts.withSessionRetrievalFunc(ctx, u.Address, t, oldRefreshTokenVal)
if api.ErrInvalidRefreshToken.Is(err) {
if api.ErrInvalidListToken.Is(err) {
if err := r.deleteRefreshToken(ctx, u, resourceType); err != nil {
return errors.Wrap(ctx, err, op)
}
+2 -2
View File
@@ -35,7 +35,7 @@ func defaultTargetFunc(ctx context.Context, addr, authTok string, refreshTok Ref
tarClient := targets.NewClient(client)
l, err := tarClient.List(ctx, "global", targets.WithRecursive(true), targets.WithListToken(string(refreshTok)))
if err != nil {
if api.ErrInvalidRefreshToken.Is(err) {
if api.ErrInvalidListToken.Is(err) {
return nil, nil, "", err
}
return nil, nil, "", errors.Wrap(ctx, err, op)
@@ -81,7 +81,7 @@ func (r *Repository) refreshTargets(ctx context.Context, u *user, tokens map[Aut
var retErr error
for at, t := range tokens {
resp, removedIds, newRefreshTokenVal, err = opts.withTargetRetrievalFunc(ctx, u.Address, t, oldRefreshTokenVal)
if api.ErrInvalidRefreshToken.Is(err) {
if api.ErrInvalidListToken.Is(err) {
if err := r.deleteRefreshToken(ctx, u, resourceType); err != nil {
return errors.Wrap(ctx, err, op)
}
@@ -218,7 +218,7 @@ func backendErrorToApiError(inErr error) *ApiError {
return NotFoundErrorf(genericNotFoundMsg)
case errors.Match(errors.T(errors.AccountAlreadyAssociated), inErr):
return InvalidArgumentErrorf(inErr.Error(), nil)
case errors.Match(errors.T(errors.InvalidRefreshToken), inErr):
case errors.Match(errors.T(errors.InvalidListToken), inErr):
return invalidRefreshTokenError(inErr)
case errors.Match(errors.T(errors.InvalidFieldMask), inErr), errors.Match(errors.T(errors.EmptyFieldMask), inErr):
return InvalidArgumentErrorf("Error in provided request", map[string]string{"update_mask": "Invalid update mask provided."})
@@ -220,14 +220,14 @@ func TestApiErrorHandler(t *testing.T) {
},
},
{
name: "Invalid refresh token error",
err: errors.New(ctx, errors.InvalidRefreshToken, errors.Op("test.op"), "this is a test invalid refresh token error"),
name: "Invalid list token error",
err: errors.New(ctx, errors.InvalidListToken, errors.Op("test.op"), "this is a test invalid list token error"),
expected: ApiError{
Status: http.StatusBadRequest,
Inner: &pb.Error{
Kind: "invalid refresh token",
Kind: "invalid list token",
Op: "test.op",
Message: "this is a test invalid refresh token error",
Message: "this is a test invalid list token error",
},
},
},
+1 -1
View File
@@ -67,7 +67,7 @@ const (
Closed = 134 // Closed represents an error when an operation cannot be completed because the thing being operated on is closed
ChecksumMismatch = 135 // ChecksumMismatch represents an error when a checksum is mismatched
InvalidRefreshToken Code = 136 // InvalidRefreshToken represents an error where the provided refresh token is invalid
InvalidListToken Code = 136 // InvalidListToken represents an error where the provided list token is invalid
AuthAttemptExpired Code = 198 // AuthAttemptExpired represents an expired authentication attempt
AuthMethodInactive Code = 199 // AuthMethodInactive represents an error that means the auth method is not active.
+3 -3
View File
@@ -416,9 +416,9 @@ func TestCode_Both_String_Info(t *testing.T) {
want: InvalidConfiguration,
},
{
name: "InvalidRefreshToken",
c: InvalidRefreshToken,
want: InvalidRefreshToken,
name: "InvalidListToken",
c: InvalidListToken,
want: InvalidListToken,
},
}
for _, tt := range tests {
+2 -2
View File
@@ -347,8 +347,8 @@ var errorCodeInfo = map[Code]Info{
Message: "invalid configuration",
Kind: Configuration,
},
InvalidRefreshToken: {
Message: "invalid refresh token",
InvalidListToken: {
Message: "invalid list token",
Kind: Parameter,
},
}