Fix allowed scope checks and added tests for creating in global scope. (#327)
This commit is contained in:
1 parent
4ae3a52056
commit
c55153ff3d
9 files changed
+109
-18
No files matched your search
@@ -266,8 +266,9 @@ func validateGetRequest(req *pbs.GetUserRequest) error {
|
||||
func validateCreateRequest(req *pbs.CreateUserRequest) error {
|
||||
return handlers.ValidateCreateRequest(req.GetItem(), func() map[string]string {
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(scope.Org.Prefix(), req.GetItem().GetScopeId()) {
|
||||
badFields["scope_id"] = "Invalidly formatted required identifer."
|
||||
if !handlers.ValidId(scope.Org.Prefix(), req.GetItem().GetScopeId()) &&
|
||||
scope.Global.String() != req.GetItem().GetScopeId() {
|
||||
badFields["scope_id"] = "This field is missing or improperly formatted."
|
||||
}
|
||||
return badFields
|
||||
})
|
||||
|
||||
@@ -268,6 +268,25 @@ func TestCreate(t *testing.T) {
|
||||
},
|
||||
errCode: codes.OK,
|
||||
},
|
||||
{
|
||||
name: "Create a valid Global User",
|
||||
req: &pbs.CreateUserRequest{Item: &pb.User{
|
||||
ScopeId: scope.Global.String(),
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "desc"},
|
||||
}},
|
||||
res: &pbs.CreateUserResponse{
|
||||
Uri: fmt.Sprintf("users/%s_", iam.UserPrefix),
|
||||
Item: &pb.User{
|
||||
ScopeId: scope.Global.String(),
|
||||
Scope: &scopes.ScopeInfo{Id: scope.Global.String(), Type: scope.Global.String()},
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "desc"},
|
||||
Version: 1,
|
||||
},
|
||||
},
|
||||
errCode: codes.OK,
|
||||
},
|
||||
{
|
||||
name: "Can't specify Id",
|
||||
req: &pbs.CreateUserRequest{Item: &pb.User{
|
||||
@@ -302,7 +321,7 @@ func TestCreate(t *testing.T) {
|
||||
s, err := users.NewService(repo)
|
||||
require.NoError(err, "Error when getting new user service.")
|
||||
|
||||
got, gErr := s.CreateUser(auth.DisabledAuthTestContext(auth.WithScopeId(defaultUser.GetScopeId())), tc.req)
|
||||
got, gErr := s.CreateUser(auth.DisabledAuthTestContext(auth.WithScopeId(tc.req.GetItem().GetScopeId())), tc.req)
|
||||
assert.Equal(tc.errCode, status.Code(gErr), "CreateUser(%+v) got error %v, wanted %v", tc.req, gErr, tc.errCode)
|
||||
if got != nil {
|
||||
assert.Contains(got.GetUri(), tc.res.Uri)
|
||||
|
||||
Reference in new issue
Block a user