(attribute interface{})
| 303 | } |
| 304 | |
| 305 | func (a CoreAttribute) validate(attribute interface{}) (interface{}, *errors.ScimError) { |
| 306 | // whether or not the attribute is required. |
| 307 | if attribute == nil { |
| 308 | if !a.required { |
| 309 | return nil, nil |
| 310 | } |
| 311 | |
| 312 | // the attribute is not present but required. |
| 313 | return nil, &errors.ScimErrorInvalidValue |
| 314 | } |
| 315 | |
| 316 | // whether the value of the attribute can be (re)defined |
| 317 | // readOnly: the attribute SHALL NOT be modified. |
| 318 | if a.mutability == attributeMutabilityReadOnly { |
| 319 | return nil, nil |
| 320 | } |
| 321 | |
| 322 | if !a.multiValued { |
| 323 | return a.ValidateSingular(attribute) |
| 324 | } |
| 325 | |
| 326 | switch arr := attribute.(type) { |
| 327 | case map[string]interface{}: |
| 328 | // return false if the multivalued attribute is empty. |
| 329 | if a.required && len(arr) == 0 { |
| 330 | return nil, &errors.ScimErrorInvalidValue |
| 331 | } |
| 332 | |
| 333 | validMap := map[string]interface{}{} |
| 334 | for k, v := range arr { |
| 335 | for _, sub := range a.subAttributes { |
| 336 | if !strings.EqualFold(sub.name, k) { |
| 337 | continue |
| 338 | } |
| 339 | _, scimErr := sub.validate(v) |
| 340 | if scimErr != nil { |
| 341 | return nil, scimErr |
| 342 | } |
| 343 | validMap[sub.name] = v |
| 344 | } |
| 345 | } |
| 346 | return validMap, nil |
| 347 | |
| 348 | case []interface{}: |
| 349 | // return false if the multivalued attribute is empty. |
| 350 | if a.required && len(arr) == 0 { |
| 351 | return nil, &errors.ScimErrorInvalidValue |
| 352 | } |
| 353 | |
| 354 | var attributes []interface{} |
| 355 | for _, ele := range arr { |
| 356 | attr, scimErr := a.ValidateSingular(ele) |
| 357 | if scimErr != nil { |
| 358 | return nil, scimErr |
| 359 | } |
| 360 | attributes = append(attributes, attr) |
| 361 | } |
| 362 | return attributes, nil |
no test coverage detected