Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
arietimmerman committed Jul 5, 2024
1 parent 1e1ddb7 commit da866f6
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 14 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
}
],
"require": {
"php": "^7.0|^8.0",
"php": "^^8.0",
"illuminate/database": "^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/support": "^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/console": "^7.0|^8.0|^9.0|^10.0|^11.0",
"tmilos/scim-schema": "^0.1.0",
"tmilos/scim-filter-parser": "^1.3"
"tmilos/scim-filter-parser": "^1.3",
"cloudstek/scim-filter-parser": "^3.0"
},
"classmap": [
"database/migrations"
Expand Down
120 changes: 119 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
backupGlobals="false"
backupStaticProperties="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
>
<testsuites>
<testsuite name="Unit tests">
Expand Down
6 changes: 6 additions & 0 deletions src/Http/Controllers/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public static function createFromSCIM($resourceType, $input, PolicyDecisionPoint
$resourceObject = $resourceType->getFactory()();

$resourceType->getMapping()->replace($input, $resourceObject);

//validate
$newObject = Helper::flatten(Helper::objectToSCIMArray($resourceObject, $resourceType), $resourceType->getSchema());

$flattened = self::validateScim($resourceType, $newObject, $resourceObject);

$resourceObject->save();

return $resourceObject;
Expand Down
8 changes: 4 additions & 4 deletions src/SCIMConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function doRead(&$object, $attributes = [])
'scim.resource',
[
'resourceType' => 'Users',
'resourceObject' => $object->id
'resourceObject' => $object->id ?? "not-saved"
]
);
}
Expand Down Expand Up @@ -127,7 +127,7 @@ protected function doRead(&$object, $attributes = [])
'scim.resource',
[
'resourceType' => 'Group',
'resourceObject' => $object->id
'resourceObject' => $object->id ?? "not-saved"
]
);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ protected function doRead(&$object, $attributes = [])
'scim.resource',
[
'resourceType' => 'Groups',
'resourceObject' => $object->id
'resourceObject' => $object->id ?? "not-saved"
]
);
}
Expand All @@ -205,7 +205,7 @@ protected function doRead(&$object, $attributes = [])
'scim.resource',
[
'resourceType' => 'Users',
'resourceObject' => $object->id
'resourceObject' => $object->id ?? "not-saved"
]
);
}
Expand Down
59 changes: 54 additions & 5 deletions tests/GroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace ArieTimmerman\Laravel\SCIMServer\Tests;

use ArieTimmerman\Laravel\SCIMServer\Attribute\Attribute;
use ArieTimmerman\Laravel\SCIMServer\SCIMConfig;
use ArieTimmerman\Laravel\SCIMServer\Tests\Model\Group;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Expand Down Expand Up @@ -52,16 +51,66 @@ public function testGet()
public function testCreate(){
$response = $this->post('/scim/v2/Groups', [
'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:Group'], // Required
'name' => 'testgroup1',
'displayName' => 'TestGroup'
'urn:ietf:params:scim:schemas:core:2.0:Group' => [
'name' => 'testgroup1',
'displayName' => 'TestGroup'
]
]);

$response->assertJsonStructure([
'id',
'urn:ietf:params:scim:schemas:core:2.0:Group' => [
'name',
'displayName'
]

]);

$this->assertNotNull(Group::find($response->json('id')));
$this->assertNotNull(Group::where('name', 'testgroup1')->first());

}

public function testBulk(){
$response = $this->post('/scim/v2/Bulk', [
'schemas' => ['urn:ietf:params:scim:api:messages:2.0:BulkRequest'], // Required
'Operations' => [
[
'method' => 'POST',
'path' => '/Groups',
'data' => [
'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:Group'], // Required
'urn:ietf:params:scim:schemas:core:2.0:Group' => [
'name' => 'testgroup1',
'displayName' => 'TestGroup'
]
]
],
[
'method' => 'POST',
'path' => '/Groups',
'data' => [
'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:Group'], // Required
'urn:ietf:params:scim:schemas:core:2.0:Group' => [
'name' => 'testgroup2',
'displayName' => 'TestGroup2'
]
]
]
]
]);

$response->assertJsonStructure([
'schemas',
'Operations' => [
'*' => [
'method',
'location',
'status'
]
]
]);

// confirm testgroup1 exists
$this->assertNotNull(Group::where('name', 'testgroup2')->first());
}
}
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected function setUp(): void
// timestamp columns
$table->timestamps();
$table->string('name')->nullable();
$table->string('displayName')->nullable();
});

Schema::create('group_user', function (Blueprint $table) {
Expand Down

0 comments on commit da866f6

Please sign in to comment.