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
@@ -378,8 +378,10 @@ func validateGetRequest(req *pbs.GetGroupRequest) error {
|
||||
func validateCreateRequest(req *pbs.CreateGroupRequest) error {
|
||||
return handlers.ValidateCreateRequest(req.GetItem(), func() map[string]string {
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(scope.Org.Prefix(), req.GetItem().GetScopeId()) && !handlers.ValidId(scope.Project.Prefix(), req.GetItem().GetScopeId()) {
|
||||
badFields["scope_id"] = "Incorrectly formatted identifier."
|
||||
if !handlers.ValidId(scope.Org.Prefix(), req.GetItem().GetScopeId()) &&
|
||||
!handlers.ValidId(scope.Project.Prefix(), req.GetItem().GetScopeId()) &&
|
||||
scope.Global.String() != req.GetItem().GetScopeId() {
|
||||
badFields["scope_id"] = "This field is missing or improperly formatted."
|
||||
}
|
||||
return badFields
|
||||
})
|
||||
|
||||
@@ -441,6 +441,25 @@ func TestCreate(t *testing.T) {
|
||||
},
|
||||
errCode: codes.OK,
|
||||
},
|
||||
{
|
||||
name: "Create a global Group",
|
||||
req: &pbs.CreateGroupRequest{Item: &pb.Group{
|
||||
ScopeId: scope.Global.String(),
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "desc"},
|
||||
}},
|
||||
res: &pbs.CreateGroupResponse{
|
||||
Uri: fmt.Sprintf("groups/%s_", iam.GroupPrefix),
|
||||
Item: &pb.Group{
|
||||
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: "Create a valid Project Scoped Group",
|
||||
req: &pbs.CreateGroupRequest{
|
||||
|
||||
Reference in new issue
Block a user