ValidatePatchOperation validates an individual operation and its related value.
(operation string, operationValue map[string]interface{}, isExtension bool)
| 78 | |
| 79 | // ValidatePatchOperation validates an individual operation and its related value. |
| 80 | func (s Schema) ValidatePatchOperation(operation string, operationValue map[string]interface{}, isExtension bool) *errors.ScimError { |
| 81 | for k, v := range operationValue { |
| 82 | var attr *CoreAttribute |
| 83 | var scimErr *errors.ScimError |
| 84 | |
| 85 | for _, attribute := range s.Attributes { |
| 86 | if strings.EqualFold(attribute.name, k) { |
| 87 | attr = &attribute |
| 88 | break |
| 89 | } |
| 90 | if isExtension && strings.EqualFold(s.ID+":"+attribute.name, k) { |
| 91 | attr = &attribute |
| 92 | break |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // Attribute does not exist in the schema, thus it is an invalid request. |
| 97 | // Immutable attrs can only be added and Readonly attrs cannot be patched |
| 98 | if attr == nil || cannotBePatched(operation, *attr) { |
| 99 | return &errors.ScimErrorInvalidValue |
| 100 | } |
| 101 | |
| 102 | // "remove" operations simply have to exist |
| 103 | if operation != "remove" { |
| 104 | _, scimErr = attr.validate(v) |
| 105 | } |
| 106 | |
| 107 | if scimErr != nil { |
| 108 | return scimErr |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return nil |
| 113 | } |
| 114 | |
| 115 | // ValidatePatchOperationValue validates an individual operation and its related value. |
| 116 | func (s Schema) ValidatePatchOperationValue(operation string, operationValue map[string]interface{}) *errors.ScimError { |
no test coverage detected