Skip to content

Commit

Permalink
fix: authprovider error message when a user is not found in the auth.…
Browse files Browse the repository at this point in the history
…Manager
  • Loading branch information
DeepDiver1975 authored and rhafer committed Mar 12, 2024
1 parent 3abbe8f commit 04c0a31
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 28 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/fix-authprovider-error-message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Fix error message in authprovider if user is not found

https://github.com/cs3org/reva/pull/4567
30 changes: 9 additions & 21 deletions internal/grpc/services/authprovider/authprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,28 +136,16 @@ func (s *service) Authenticate(ctx context.Context, req *provider.AuthenticateRe
password := req.ClientSecret

u, scope, err := s.authmgr.Authenticate(ctx, username, password)
switch v := err.(type) {
case nil:
log.Info().Msgf("user %s authenticated", u.Id)
return &provider.AuthenticateResponse{
Status: status.NewOK(ctx),
User: u,
TokenScope: scope,
}, nil
case errtypes.InvalidCredentials:
return &provider.AuthenticateResponse{
Status: status.NewPermissionDenied(ctx, v, "wrong password"),
}, nil
case errtypes.NotFound:
log.Debug().Str("client_id", username).Msg("unknown client id")
return &provider.AuthenticateResponse{
Status: status.NewNotFound(ctx, "unknown client id"),
}, nil
default:
err = errors.Wrap(err, "authsvc: error in Authenticate")
if err != nil {
log.Debug().Str("client_id", username).Err(err).Msg("authsvc: error in Authenticate")
return &provider.AuthenticateResponse{
Status: status.NewUnauthenticated(ctx, err, "error authenticating user"),
Status: status.NewStatusFromErrType(ctx, "authsvc: error in Authenticate", err),
}, nil
}

log.Info().Msgf("user %s authenticated", u.Id)
return &provider.AuthenticateResponse{
Status: status.NewOK(ctx),
User: u,
TokenScope: scope,
}, nil
}
14 changes: 7 additions & 7 deletions pkg/errtypes/errtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (e BadRequest) Error() string { return "error: bad request: " + string(e) }
// IsBadRequest implements the IsBadRequest interface.
func (e BadRequest) IsBadRequest() {}

// ChecksumMismatch is the error to use when the sent hash does not match the calculated hash.
// ChecksumMismatch is the error to use when the transmitted hash does not match the calculated hash.
type ChecksumMismatch string

func (e ChecksumMismatch) Error() string { return "error: checksum mismatch: " + string(e) }
Expand Down Expand Up @@ -178,7 +178,7 @@ type NotModified string

func (e NotModified) Error() string { return "error: not modified: " + string(e) }

// NotModified implements the IsNotModified interface.
// IsNotModified implements the IsNotModified interface.
func (e NotModified) IsNotModified() {}

// StatusCode returns StatusInsufficientStorage, this implementation is needed to allow TUS to cast the correct http errors.
Expand All @@ -196,7 +196,7 @@ func (e InsufficientStorage) Body() []byte {
const StatusInsufficientStorage = 507

// IsNotFound is the interface to implement
// to specify that an a resource is not found.
// to specify that a resource is not found.
type IsNotFound interface {
IsNotFound()
}
Expand Down Expand Up @@ -238,7 +238,7 @@ type IsPermissionDenied interface {
}

// IsLocked is the interface to implement
// to specify that an resource is locked.
// to specify that a resource is locked.
type IsLocked interface {
IsLocked()
}
Expand Down Expand Up @@ -279,7 +279,7 @@ type IsInsufficientStorage interface {
IsInsufficientStorage()
}

// NewErrtypeFromStatus maps an rpc status to an errtype
// NewErrtypeFromStatus maps a rpc status to an errtype
func NewErrtypeFromStatus(status *rpc.Status) error {
switch status.Code {
case rpc.Code_CODE_OK:
Expand Down Expand Up @@ -318,7 +318,7 @@ func NewErrtypeFromStatus(status *rpc.Status) error {
}
}

// NewErrtypeFromHTTPStatusCode maps an http status to an errtype
// NewErrtypeFromHTTPStatusCode maps a http status to an errtype
func NewErrtypeFromHTTPStatusCode(code int, message string) error {
switch code {
case http.StatusOK:
Expand Down Expand Up @@ -352,7 +352,7 @@ func NewErrtypeFromHTTPStatusCode(code int, message string) error {
}
}

// NewHTTPStatusCodeFromErrtype maps an errtype to an http status
// NewHTTPStatusCodeFromErrtype maps an errtype to a http status
func NewHTTPStatusCodeFromErrtype(err error) int {
switch err.(type) {
case NotFound:
Expand Down
4 changes: 4 additions & 0 deletions pkg/rgrpc/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,14 @@ func NewStatusFromErrType(ctx context.Context, msg string, err error) *rpc.Statu
switch e := err.(type) {
case nil:
return NewOK(ctx)
case errtypes.NotFound:
return NewNotFound(ctx, msg+": "+err.Error())
case errtypes.IsNotFound:
return NewNotFound(ctx, msg+": "+err.Error())
case errtypes.AlreadyExists:
return NewAlreadyExists(ctx, err, msg+": "+err.Error())
case errtypes.InvalidCredentials:
return NewPermissionDenied(ctx, e, msg+": "+err.Error())
case errtypes.IsInvalidCredentials:
// TODO this maps badly
return NewUnauthenticated(ctx, err, msg+": "+err.Error())
Expand Down

0 comments on commit 04c0a31

Please sign in to comment.