Update API codes (#336)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-09-08 23:57:26 -04:00
1 parent 99d5456d7a
commit f94f21fd97
74 files changed
+1557 -1802

No files matched your search

@@ -130,11 +130,11 @@ func (s Service) DeleteAuthMethod(ctx context.Context, req *pbs.DeleteAuthMethod
if authResults.Error != nil {
return nil, authResults.Error
}
existed, err := s.deleteFromRepo(ctx, authResults.Scope.GetId(), req.GetId())
_, err := s.deleteFromRepo(ctx, authResults.Scope.GetId(), req.GetId())
if err != nil {
return nil, err
}
return &pbs.DeleteAuthMethodResponse{Existed: existed}, nil
return nil, nil
}
func (s Service) getFromRepo(ctx context.Context, id string) (*pb.AuthMethod, error) {
@@ -279,7 +279,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
return res
}
if scp == nil {
res.Error = handlers.ForbiddenError()
res.Error = handlers.NotFoundError()
return res
}
default:
@@ -294,7 +294,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
return res
}
if authMeth == nil {
res.Error = handlers.ForbiddenError()
res.Error = handlers.NotFoundError()
return res
}
parentId = authMeth.GetScopeId()
@@ -382,8 +382,12 @@ func validateDeleteRequest(req *pbs.DeleteAuthMethodRequest) error {
return handlers.ValidateDeleteRequest(password.AuthMethodPrefix, req, handlers.NoopValidatorFn)
}
func validateListRequest(_ *pbs.ListAuthMethodsRequest) error {
func validateListRequest(req *pbs.ListAuthMethodsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(scope.Org.Prefix(), req.GetScopeId()) &&
req.GetScopeId() != scope.Global.String() {
badFields["scope_id"] = "This field must be a valid project scope id."
}
if len(badFields) > 0 {
return handlers.InvalidArgumentErrorf("Improperly formatted identifier.", badFields)
}
@@ -80,7 +80,7 @@ func TestGet(t *testing.T) {
scopeId: o.GetPublicId(),
req: &pbs.GetAuthMethodRequest{Id: password.AuthMethodPrefix + "_DoesntExis"},
res: nil,
errCode: codes.PermissionDenied,
errCode: codes.NotFound,
},
{
name: "Wrong id prefix",
@@ -186,11 +186,10 @@ func TestList(t *testing.T) {
res: &pbs.ListAuthMethodsResponse{},
errCode: codes.OK,
},
// TODO: When an auth method doesn't exist, we should return a 404 instead of an empty list.
{
name: "Unfound Auth Method",
scopeId: password.AuthMethodPrefix + "_DoesntExis",
errCode: codes.PermissionDenied,
scopeId: "o_DoesntExis",
errCode: codes.NotFound,
},
}
for _, tc := range cases {
@@ -236,9 +235,6 @@ func TestDelete(t *testing.T) {
req: &pbs.DeleteAuthMethodRequest{
Id: am.GetPublicId(),
},
res: &pbs.DeleteAuthMethodResponse{
Existed: true,
},
errCode: codes.OK,
},
{
@@ -246,14 +242,13 @@ func TestDelete(t *testing.T) {
req: &pbs.DeleteAuthMethodRequest{
Id: password.AuthMethodPrefix + "_doesntexis",
},
errCode: codes.PermissionDenied,
errCode: codes.NotFound,
},
{
name: "Bad AuthMethod Id formatting",
req: &pbs.DeleteAuthMethodRequest{
Id: "bad_format",
},
res: nil,
errCode: codes.InvalidArgument,
},
}
@@ -290,12 +285,11 @@ func TestDelete_twice(t *testing.T) {
req := &pbs.DeleteAuthMethodRequest{
Id: am.GetPublicId(),
}
got, gErr := s.DeleteAuthMethod(auth.DisabledAuthTestContext(auth.WithScopeId(o.GetPublicId())), req)
_, gErr := s.DeleteAuthMethod(auth.DisabledAuthTestContext(auth.WithScopeId(o.GetPublicId())), req)
assert.NoError(gErr, "First attempt")
assert.True(got.GetExisted(), "Expected existed to be true for the first delete.")
got, gErr = s.DeleteAuthMethod(auth.DisabledAuthTestContext(auth.WithScopeId(o.GetPublicId())), req)
_, gErr = s.DeleteAuthMethod(auth.DisabledAuthTestContext(auth.WithScopeId(o.GetPublicId())), req)
assert.Error(gErr, "Second attempt")
assert.Equal(codes.PermissionDenied, status.Code(gErr), "Expected permission denied for the second delete.")
assert.Equal(codes.NotFound, status.Code(gErr), "Expected permission denied for the second delete.")
}
func TestCreate(t *testing.T) {
@@ -705,7 +699,7 @@ func TestUpdate(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
},
},
errCode: codes.PermissionDenied,
errCode: codes.NotFound,
},
{
name: "Cant change Id",