validateRemove validates the remove operation contained within the validator based on on Section 3.5.2.2 in RFC 7644. More info: https://datatracker.ietf.org/doc/html/rfc7644#section-3.5.2.2
()
| 11 | // validateRemove validates the remove operation contained within the validator based on on Section 3.5.2.2 in RFC 7644. |
| 12 | // More info: https://datatracker.ietf.org/doc/html/rfc7644#section-3.5.2.2 |
| 13 | func (v OperationValidator) validateRemove() (interface{}, error) { |
| 14 | // If "path" is unspecified, the operation fails with HTTP status code 400 and a "scimType" error code of "noTarget". |
| 15 | if v.Path == nil { |
| 16 | return nil, &errors.ScimError{ |
| 17 | ScimType: errors.ScimTypeNoTarget, |
| 18 | Status: http.StatusBadRequest, |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | refAttr, err := v.getRefAttribute(v.Path.AttributePath) |
| 23 | if err != nil { |
| 24 | return nil, err |
| 25 | } |
| 26 | if v.Path.ValueExpression != nil { |
| 27 | if err := f.NewFilterValidator(v.Path.ValueExpression, schema.Schema{ |
| 28 | Attributes: f.MultiValuedFilterAttributes(*refAttr), |
| 29 | }).Validate(); err != nil { |
| 30 | return nil, err |
| 31 | } |
| 32 | } |
| 33 | if subAttrName := v.Path.SubAttributeName(); subAttrName != "" { |
| 34 | refSubAttr, err := v.getRefSubAttribute(refAttr, subAttrName) |
| 35 | if err != nil { |
| 36 | return nil, err |
| 37 | } |
| 38 | refAttr = refSubAttr |
| 39 | } |
| 40 | if v.value == nil { |
| 41 | return nil, nil |
| 42 | } |
| 43 | if !refAttr.MultiValued() { |
| 44 | attr, scimErr := refAttr.ValidateSingular(v.value) |
| 45 | if scimErr != nil { |
| 46 | return nil, scimErr |
| 47 | } |
| 48 | return attr, nil |
| 49 | } |
| 50 | |
| 51 | if list, ok := v.value.([]interface{}); ok { |
| 52 | var attrs []interface{} |
| 53 | for _, value := range list { |
| 54 | attr, scimErr := refAttr.ValidateSingular(value) |
| 55 | if scimErr != nil { |
| 56 | return nil, scimErr |
| 57 | } |
| 58 | attrs = append(attrs, attr) |
| 59 | } |
| 60 | return attrs, nil |
| 61 | } |
| 62 | |
| 63 | attr, scimErr := refAttr.ValidateSingular(v.value) |
| 64 | if scimErr != nil { |
| 65 | return nil, scimErr |
| 66 | } |
| 67 | return []interface{}{attr}, nil |
| 68 | } |
no test coverage detected