Allow target type field to be included in an update. (#412)
This commit is contained in:
1 parent
2f8d7f0a32
commit
278902db1a
4 files changed
+10
-21
No files matched your search
@@ -448,7 +448,7 @@ func validateUpdateRequest(req *pbs.UpdateAccountRequest) error {
|
||||
switch auth.SubtypeFromId(req.GetId()) {
|
||||
case auth.PasswordSubtype:
|
||||
if req.GetItem().GetType() != "" && req.GetItem().GetType() != auth.PasswordSubtype.String() {
|
||||
badFields["type"] = "Cannot modify resource type."
|
||||
badFields["type"] = "Cannot modify the resource type."
|
||||
}
|
||||
pwAttrs := &pb.PasswordAccountAttributes{}
|
||||
if err := handlers.StructToProto(req.GetItem().GetAttributes(), pwAttrs); err != nil {
|
||||
|
||||
@@ -365,7 +365,7 @@ func validateUpdateRequest(req *pbs.UpdateAuthMethodRequest) error {
|
||||
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."
|
||||
badFields["type"] = "Cannot modify the resource type."
|
||||
}
|
||||
pwAttrs := &pb.PasswordAuthMethodAttributes{}
|
||||
if err := handlers.StructToProto(req.GetItem().GetAttributes(), pwAttrs); err != nil {
|
||||
|
||||
@@ -749,8 +749,11 @@ func validateUpdateRequest(req *pbs.UpdateTargetRequest) error {
|
||||
if req.GetItem().GetSessionMaxSeconds() != nil && req.GetItem().GetSessionMaxSeconds().GetValue() == 0 {
|
||||
badFields["session_max_seconds"] = "This must be greater than zero."
|
||||
}
|
||||
switch target.SubtypeFromType(req.GetItem().GetType()) {
|
||||
switch target.SubtypeFromId(req.GetItem().GetType()) {
|
||||
case target.TcpSubType:
|
||||
if req.GetItem().GetType() != "" && target.SubtypeFromType(req.GetItem().GetType()) != target.TcpSubType {
|
||||
badFields["type"] = "Cannot modify the resource type."
|
||||
}
|
||||
tcpAttrs := &pb.TcpTargetAttributes{}
|
||||
if err := handlers.StructToProto(req.GetItem().GetAttributes(), tcpAttrs); err != nil {
|
||||
badFields["attributes"] = "Attribute fields do not match the expected format."
|
||||
@@ -759,9 +762,6 @@ func validateUpdateRequest(req *pbs.UpdateTargetRequest) error {
|
||||
badFields["attributes.default_port"] = "This optional field cannot be set to 0."
|
||||
}
|
||||
}
|
||||
if req.GetItem().GetType() != "" {
|
||||
badFields["type"] = "This field cannot be updated."
|
||||
}
|
||||
return badFields
|
||||
})
|
||||
}
|
||||
|
||||
@@ -462,13 +462,14 @@ func TestUpdate(t *testing.T) {
|
||||
name: "Update an Existing Target",
|
||||
req: &pbs.UpdateTargetRequest{
|
||||
UpdateMask: &field_mask.FieldMask{
|
||||
Paths: []string{"name", "description", "session_max_seconds", "session_connection_limit"},
|
||||
Paths: []string{"name", "description", "session_max_seconds", "session_connection_limit", "type"},
|
||||
},
|
||||
Item: &pb.Target{
|
||||
Name: wrapperspb.String("name"),
|
||||
Description: wrapperspb.String("desc"),
|
||||
SessionMaxSeconds: wrapperspb.UInt32(3600),
|
||||
SessionConnectionLimit: wrapperspb.Int32(5),
|
||||
Type: target.TcpSubType.String(),
|
||||
},
|
||||
},
|
||||
res: &pbs.UpdateTargetResponse{
|
||||
@@ -494,11 +495,12 @@ func TestUpdate(t *testing.T) {
|
||||
name: "Multiple Paths in single string",
|
||||
req: &pbs.UpdateTargetRequest{
|
||||
UpdateMask: &field_mask.FieldMask{
|
||||
Paths: []string{"name,description"},
|
||||
Paths: []string{"name,description,type"},
|
||||
},
|
||||
Item: &pb.Target{
|
||||
Name: wrapperspb.String("name"),
|
||||
Description: wrapperspb.String("desc"),
|
||||
Type: target.TcpSubType.String(),
|
||||
},
|
||||
},
|
||||
res: &pbs.UpdateTargetResponse{
|
||||
@@ -721,19 +723,6 @@ func TestUpdate(t *testing.T) {
|
||||
res: nil,
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
},
|
||||
{
|
||||
name: "Valid mask, cant specify type",
|
||||
req: &pbs.UpdateTargetRequest{
|
||||
UpdateMask: &field_mask.FieldMask{
|
||||
Paths: []string{"name"},
|
||||
},
|
||||
Item: &pb.Target{
|
||||
Type: "Unknown",
|
||||
},
|
||||
},
|
||||
res: nil,
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user