Scopes type field and types in updates allowed (#335)

This commit is contained in:
Todd Knight authored and GitHub committed 2020-09-08 16:04:19 -07:00
1 parent c3ecea172d
commit 99d5456d7a
16 files changed
+309 -42

No files matched your search

@@ -362,8 +362,17 @@ func validateCreateRequest(req *pbs.CreateAuthMethodRequest) error {
func validateUpdateRequest(req *pbs.UpdateAuthMethodRequest) error {
return handlers.ValidateUpdateRequest(password.AuthMethodPrefix, req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
if req.GetItem().GetType() != "" {
badFields["type"] = "This is a read only field and cannot be specified in an update request."
switch auth.SubtypeFromId(req.GetId()) {
case auth.PasswordSubtype:
if req.GetItem().GetType() != "" && auth.SubtypeFromType(req.GetItem().GetType()) != auth.PasswordSubtype {
badFields["type"] = "Cannot modify resource type."
}
pwAttrs := &pb.PasswordAuthMethodAttributes{}
if err := handlers.StructToProto(req.GetItem().GetAttributes(), pwAttrs); err != nil {
badFields["attributes"] = "Attribute fields do not match the expected format."
}
default:
badFields["id"] = "Incorrectly formatted identifier."
}
return badFields
})
@@ -529,6 +529,7 @@ func TestUpdate(t *testing.T) {
Item: &pb.AuthMethod{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: "password",
},
},
res: &pbs.UpdateAuthMethodResponse{
@@ -550,11 +551,12 @@ func TestUpdate(t *testing.T) {
name: "Multiple Paths in single string",
req: &pbs.UpdateAuthMethodRequest{
UpdateMask: &field_mask.FieldMask{
Paths: []string{"name,description"},
Paths: []string{"name,description,type"},
},
Item: &pb.AuthMethod{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: "password",
},
},
res: &pbs.UpdateAuthMethodResponse{
@@ -604,6 +606,17 @@ func TestUpdate(t *testing.T) {
},
errCode: codes.InvalidArgument,
},
{
name: "Cant change type",
req: &pbs.UpdateAuthMethodRequest{
UpdateMask: &field_mask.FieldMask{Paths: []string{"name", "type"}},
Item: &pb.AuthMethod{
Name: &wrapperspb.StringValue{Value: "updated name"},
Type: "oidc",
},
},
errCode: codes.InvalidArgument,
},
{
name: "Unset Name",
req: &pbs.UpdateAuthMethodRequest{