API Errors: Hide and log internal errors (#411)

This commit is contained in:
Todd Knight authored and GitHub committed 2020-09-23 08:10:27 -07:00
1 parent ac9a7735e1
commit 2f8d7f0a32
27 files changed
+1465 -1205

No files matched your search

@@ -18,7 +18,6 @@ import (
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
const (
@@ -77,7 +76,7 @@ func (s Service) Authenticate(ctx context.Context, req *pbs.AuthenticateRequest)
// Deauthenticate implements the interface pbs.AuthenticationServiceServer.
func (s Service) Deauthenticate(ctx context.Context, req *pbs.DeauthenticateRequest) (*pbs.DeauthenticateResponse, error) {
return nil, status.Error(codes.Unimplemented, "Requested method is unimplemented.")
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Unimplemented, "Requested method is unimplemented.")
}
func (s Service) authenticateWithRepo(ctx context.Context, scopeId, authMethodId, loginName, pw string) (*pba.AuthToken, error) {
@@ -99,7 +98,7 @@ func (s Service) authenticateWithRepo(ctx context.Context, scopeId, authMethodId
return nil, err
}
if acct == nil {
return nil, status.Error(codes.Unauthenticated, "Unable to authenticate.")
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Unauthenticated, "Unable to authenticate.")
}
u, err := iamRepo.LookupUserWithLogin(ctx, acct.GetPublicId(), iam.WithAutoVivify(true))
@@ -2,6 +2,7 @@ package authenticate
import (
"context"
"errors"
"strings"
"testing"
@@ -14,10 +15,10 @@ import (
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
const (
@@ -98,7 +99,7 @@ func TestAuthenticate(t *testing.T) {
return &structpb.Struct{Fields: creds}
}(),
},
wantErr: status.Error(codes.InvalidArgument, "invalid argument"),
wantErr: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
{
name: "no-authmethod",
@@ -111,7 +112,7 @@ func TestAuthenticate(t *testing.T) {
return &structpb.Struct{Fields: creds}
}(),
},
wantErr: status.Error(codes.InvalidArgument, "invalid argument"),
wantErr: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
{
name: "wrong-password",
@@ -126,7 +127,7 @@ func TestAuthenticate(t *testing.T) {
return &structpb.Struct{Fields: creds}
}(),
},
wantErr: status.Error(codes.Unauthenticated, "unauthenticated"),
wantErr: handlers.ApiErrorWithCode(codes.Unauthenticated),
},
{
name: "wrong-login-name",
@@ -141,7 +142,7 @@ func TestAuthenticate(t *testing.T) {
return &structpb.Struct{Fields: creds}
}(),
},
wantErr: status.Error(codes.Unauthenticated, "unauthenticated"),
wantErr: handlers.ApiErrorWithCode(codes.Unauthenticated),
},
}
@@ -154,7 +155,7 @@ func TestAuthenticate(t *testing.T) {
resp, err := s.Authenticate(auth.DisabledAuthTestContext(auth.WithScopeId(o.GetPublicId())), tc.request)
if tc.wantErr != nil {
assert.Error(err)
assert.Equal(status.Code(tc.wantErr), status.Code(err))
assert.Truef(errors.Is(err, tc.wantErr), "Got %#v, wanted %#v", err, tc.wantErr)
return
}
require.NoError(err)