Skip to content

Commit

Permalink
Fix validation of multi-valued attribute of primitive values
Browse files Browse the repository at this point in the history
Fixes tmilos#10
  • Loading branch information
ostrolucky committed Oct 25, 2024
1 parent 30827fc commit 2bc55de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Validator/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,16 @@ private function validateByAttributes(array $object, $schemaId, $attributes, arr
if (!$attribute->isMultiValued()) {
$validationResult->add($propertyName, $parentPath, $schemaId, 'Attribute is not defined in schema as multi-valued, but got array');
continue;
} else {
foreach ($value as $item) {
$this->validateByAttributes($item, $schemaId, $attribute->getSubAttributes(), [], $validationResult, $propertyName);
}
foreach ($value as $item) {
if (!is_array($item)) {
if (!$attribute->isValueValid($item)) {
$validationResult->add($propertyName, $parentPath, $schemaId, sprintf('Attribute has invalid value for type "%s"', $attribute->getType()));
}
continue;
}

$this->validateByAttributes($item, $schemaId, $attribute->getSubAttributes(), [], $validationResult, $propertyName);
}
} elseif ($this->isObject($value)) {
if ($attribute->isMultiValued()) {
Expand Down
9 changes: 9 additions & 0 deletions tests/Validator/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public function test_full_user_representation()
$this->assertEquals([], $result->getErrorsAsStrings());
}

public function test_list()
{
$schema = new Schema('customUser');
$schema->addAttribute(AttributeBuilder::create('tags', ScimConstants::ATTRIBUTE_TYPE_STRING)
->setMultiValued(true)->getAttribute(),
);
$this->assertEmpty($this->validator->validate(['tags' => ['foo']], $schema)->getErrors());
}

public function test_enterprise_user_full()
{
$result = $this->validator->validate(
Expand Down

0 comments on commit 2bc55de

Please sign in to comment.