ValidateSingular checks whether the given singular value matches the attribute data type. Unknown attributes in given complex value are ignored. The returned interface contains a (sanitised) version of the given attribute.
(attribute interface{})
| 161 | // ValidateSingular checks whether the given singular value matches the attribute data type. Unknown attributes in |
| 162 | // given complex value are ignored. The returned interface contains a (sanitised) version of the given attribute. |
| 163 | func (a CoreAttribute) ValidateSingular(attribute interface{}) (interface{}, *errors.ScimError) { |
| 164 | switch a.typ { |
| 165 | case attributeDataTypeBinary: |
| 166 | bin, ok := attribute.(string) |
| 167 | if !ok { |
| 168 | return nil, &errors.ScimErrorInvalidValue |
| 169 | } |
| 170 | |
| 171 | match, err := regexp.MatchString(`^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$`, bin) |
| 172 | if err != nil { |
| 173 | panic(err) |
| 174 | } |
| 175 | |
| 176 | if !match { |
| 177 | return nil, &errors.ScimErrorInvalidValue |
| 178 | } |
| 179 | |
| 180 | return bin, nil |
| 181 | case attributeDataTypeBoolean: |
| 182 | b, ok := attribute.(bool) |
| 183 | if !ok { |
| 184 | return nil, &errors.ScimErrorInvalidValue |
| 185 | } |
| 186 | |
| 187 | return b, nil |
| 188 | case attributeDataTypeComplex: |
| 189 | obj, ok := attribute.(map[string]interface{}) |
| 190 | if !ok { |
| 191 | return nil, &errors.ScimErrorInvalidValue |
| 192 | } |
| 193 | |
| 194 | attributes := make(map[string]interface{}) |
| 195 | |
| 196 | for _, sub := range a.subAttributes { |
| 197 | var hit interface{} |
| 198 | var found bool |
| 199 | for k, v := range obj { |
| 200 | if strings.EqualFold(sub.name, k) { |
| 201 | if found { |
| 202 | return nil, &errors.ScimErrorInvalidSyntax |
| 203 | } |
| 204 | found = true |
| 205 | hit = v |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | attr, scimErr := sub.validate(hit) |
| 210 | if scimErr != nil { |
| 211 | return nil, scimErr |
| 212 | } |
| 213 | if attr != nil { |
| 214 | attributes[sub.name] = attr |
| 215 | } |
| 216 | } |
| 217 | return attributes, nil |
| 218 | case attributeDataTypeDateTime: |
| 219 | date, ok := attribute.(string) |
| 220 | if !ok { |
no test coverage detected