Skip to content

Commit

Permalink
Fix validation of unassigned values
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Oct 25, 2024
1 parent 2bc55de commit 9aecffc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Model/Schema/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ public function findAttribute($name)

public function isValueValid($value)
{
// https://datatracker.ietf.org/doc/html/rfc7643#section-2.5
if (!$this->required && in_array($value, [null, [], 'null'], true)) {
return true;
}

switch ($this->type) {
case ScimConstants::ATTRIBUTE_TYPE_STRING: return is_string($value);
case ScimConstants::ATTRIBUTE_TYPE_BOOLEAN: return is_bool($value);
Expand Down
10 changes: 10 additions & 0 deletions tests/Validator/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public function test_list()
$this->assertEmpty($this->validator->validate(['tags' => ['foo']], $schema)->getErrors());
}

/**
* @testWith [{"nickName": null}, []]
* [{"nickName": "null"}, []]
* [{"userName": null}, ["[userName] Attribute has invalid value for type \"string\" [urn:ietf:params:scim:schemas:core:2.0:User]"]]
*/
public function test_unassigned_value(array $data, array $expected)
{
$this->assertEquals($expected, $this->validator->validate($data, $this->schemaBuilder->getUser())->getErrorsAsStrings());
}

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

0 comments on commit 9aecffc

Please sign in to comment.