Skip to content
7 changes: 5 additions & 2 deletions src/Middleware/SCIMHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ class SCIMHeaders
{
public function handle(Request $request, Closure $next)
{
if ($request->method() != 'GET' && stripos($request->header('content-type'), 'application/scim+json') === false && stripos($request->header('content-type'), 'application/json') === false && strlen($request->getContent()) > 0) {
throw new SCIMException(sprintf('The content-type header should be set to "%s"', 'application/scim+json'));
if ($request->method() !== 'GET'
&& strtolower($request->header('content-type') !== 'application/scim+json')
&& strtolower($request->header('content-type') !== 'application/json')) {

throw new SCIMException(sprintf('The content-type header should be set to "%s"', 'application/scim+json'), 400);
}

$response = $next($request);
Expand Down
51 changes: 23 additions & 28 deletions tests/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

namespace ArieTimmerman\Laravel\SCIMServer\Tests;

use ArieTimmerman\Laravel\SCIMServer\ResourceType;
use ArieTimmerman\Laravel\SCIMServer\SCIMConfig;
use ArieTimmerman\Laravel\SCIMServer\Tests\Model\Group;
use Illuminate\Support\Arr;

class BasicTest extends TestCase
{
public function testGet()
{
$response = $this->get('/scim/v2/Users');
$response = $this->get('/scim/v2/Users', $this->headers);

$response->assertStatus(200);
$response->assertJsonCount(10, 'Resources');
Expand Down Expand Up @@ -103,9 +101,7 @@ public function testGetGroupsAttribute()
$response->assertJsonCount(10, 'Resources');
$response->assertJsonStructure([
'Resources' => [
'*' => [

]
'*' => []
]
]);
}
Expand Down Expand Up @@ -151,7 +147,6 @@ public function testCursorPaginationFailure()
'status' => '400',
'scimType' => 'invalidCursor'
]);

}

public function testCursorPaginationFailureMaxCount()
Expand All @@ -164,7 +159,6 @@ public function testCursorPaginationFailureMaxCount()
'status' => '400',
'scimType' => 'invalidCount'
]);

}

public function testPagination()
Expand Down Expand Up @@ -207,7 +201,7 @@ public function testFilter()
$userName = $response->json('Resources')[0]['urn:ietf:params:scim:schemas:core:2.0:User']['userName'];

// Now search for this username
$response = $this->get('/scim/v2/Users?filter=userName eq "'.$userName.'"');
$response = $this->get('/scim/v2/Users?filter=userName eq "' . $userName . '"');
$response->assertStatus(200);

$this->assertEquals(1, count($response->json('Resources')));
Expand All @@ -224,7 +218,7 @@ public function testFilterByGroup()
$userValue = $response->json('Resources')[0]['id'];

// SCIM Patch request
$response = $this->patch('/scim/v2/Groups/' . $groupValue, [
$response = $this->patchJson('/scim/v2/Groups/' . $groupValue, [
"schemas" => [
"urn:ietf:params:scim:api:messages:2.0:PatchOp",
],
Expand All @@ -241,10 +235,10 @@ public function testFilterByGroup()

$response->assertStatus(200);

$this->assertTrue(Group::find($groupValue)->members->pluck('id')->contains($userValue), 'User was not added to the group');
$this->assertTrue(Group::find($groupValue)->members->pluck('id')->contains($userValue), 'User was not added to the group');

// SCIM Patch remove member request
$response = $this->patch('/scim/v2/Groups/' . $groupValue, [
$response = $this->patchJson('/scim/v2/Groups/' . $groupValue, [
"schemas" => [
"urn:ietf:params:scim:api:messages:2.0:PatchOp",
],
Expand All @@ -271,7 +265,7 @@ public function testSearch()
$userName = $response->json('Resources')[0]['urn:ietf:params:scim:schemas:core:2.0:User']['userName'];

// Now search for this username
$response = $this->get('/scim/v2/Users?filter=userName eq "'.$userName.'"');
$response = $this->get('/scim/v2/Users?filter=userName eq "' . $userName . '"');
$response->assertStatus(200);

$this->assertEquals(1, count($response->json('Resources')));
Expand All @@ -292,7 +286,7 @@ public function testGroupAssignment()

public function testPut()
{
$response = $this->put('/scim/v2/Users/1', [
$response = $this->putJson('/scim/v2/Users/1', [
"id" => "1",
"meta" => [
"resourceType" => "User",
Expand All @@ -318,7 +312,7 @@ public function testPut()
]
]
]
]);
], $this->headers);

$response->assertStatus(200);

Expand All @@ -331,7 +325,7 @@ public function testPut()

public function testPatch()
{
$response = $this->patch('/scim/v2/Users/2', [
$response = $this->patchJson('/scim/v2/Users/2', [
"schemas" => [
"urn:ietf:params:scim:api:messages:2.0:PatchOp",
],
Expand All @@ -340,13 +334,13 @@ public function testPatch()
"path" => "emails",
"value" => [
[
"value" => "[email protected]",
"type" => "work",
"primary" => true
"value" => "[email protected]",
"type" => "work",
"primary" => true
]
]
]]
]);
], $this->headers);

$response->assertStatus(200);

Expand All @@ -358,7 +352,7 @@ public function testPatch()

public function testPatchMultiple()
{
$response = $this->patch('/scim/v2/Users/2', [
$response = $this->patchJson('/scim/v2/Users/2', [
"schemas" => [
"urn:ietf:params:scim:api:messages:2.0:PatchOp",
],
Expand All @@ -384,7 +378,7 @@ public function testPatchMultiple()

public function testPatchMultipleReplace()
{
$response = $this->patch('/scim/v2/Users/2', [
$response = $this->patchJson('/scim/v2/Users/2', [
"schemas" => [
"urn:ietf:params:scim:api:messages:2.0:PatchOp",
],
Expand All @@ -410,7 +404,7 @@ public function testPatchMultipleReplace()

public function testPatchUsername()
{
$response = $this->patch('/scim/v2/Users/4', [
$response = $this->patchJson('/scim/v2/Users/4', [
"schemas" => [
"urn:ietf:params:scim:api:messages:2.0:PatchOp",
],
Expand All @@ -431,13 +425,13 @@ public function testPatchUsername()

public function testDelete()
{
$response = $this->delete('/scim/v2/Users/1');
$response = $this->deleteJson('/scim/v2/Users/1', [], $this->headers);
$response->assertStatus(204);
}

public function testPost()
{
$response = $this->post('/scim/v2/Users', [
$response = $this->postJson('/scim/v2/Users', [
// "id" => 1,
"schemas" => [
"urn:ietf:params:scim:schemas:core:2.0:User",
Expand All @@ -453,7 +447,7 @@ public function testPost()
]
]
]
]);
], $this->headers);

$this->assertEquals(
201,
Expand All @@ -471,7 +465,7 @@ public function testPost()

public function testPostTopLevel()
{
$response = $this->post('/scim/v2/Users', [
$response = $this->postJson('/scim/v2/Users', [
// "id" => 1,
"schemas" => [
"urn:ietf:params:scim:schemas:core:2.0:User",
Expand Down Expand Up @@ -502,7 +496,8 @@ public function testPostTopLevel()
$this->assertEquals('Dr. Marie Jo', $json['urn:ietf:params:scim:schemas:core:2.0:User']['userName']);
}

public function testTotalResultsOnly(){
public function testTotalResultsOnly()
{
$response = $this->get('/scim/v2/Users?count=0');
$this->assertTrue(true);
}
Expand Down
19 changes: 7 additions & 12 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@

namespace ArieTimmerman\Laravel\SCIMServer\Tests;

use ArieTimmerman\Laravel\SCIMServer\ResourceType;
use ArieTimmerman\Laravel\SCIMServer\SCIMConfig;
use ArieTimmerman\Laravel\SCIMServer\Tests\Model\Role;
use Illuminate\Support\Arr;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class ConfigTest extends TestCase
{


protected function setUp(): void
{
parent::setUp();

// set scim.omit_null_values to true

}

protected function createUser(){
return $this->post('/scim/v2/Users', [
protected function createUser()
{
return $this->postJson('/scim/v2/Users', [
// "id" => 1,
"schemas" => [
"urn:ietf:params:scim:schemas:core:2.0:User",
Expand Down Expand Up @@ -86,8 +82,8 @@ public function testDoNotOmitNullValues()
$this->assertArrayHasKey('urn:ietf:params:scim:schemas:core:2.0:User', $response->json());

$expected = [
"employeeNumber" => null
"employeeNumber" => null

];

$this->assertEquals($expected, Arr::get($response->json(), 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User'));
Expand All @@ -111,5 +107,4 @@ public function testOmitNullValues()
$expected = null;
$this->assertEquals($expected, Arr::get($response->json(), 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User'));
}

}
2 changes: 1 addition & 1 deletion tests/CustomSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function getEnvironmentSetUp($app)

public function testPost()
{
$response = $this->post('/scim/v2/Users', [
$response = $this->postJson('/scim/v2/Users', [
// "id" => 1,
"schemas" => [
"urn:ietf:params:scim:schemas:core:2.0:User",
Expand Down
34 changes: 34 additions & 0 deletions tests/ErrorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace ArieTimmerman\Laravel\SCIMServer\Tests;

class ErrorTest extends TestCase
{
public function testHeader()
{
$response = $this->putJson('/scim/v2/Users/1', [
"id" => 1,
"schemas" => [
"urn:ietf:params:scim:schemas:core:2.0:User",
],
"urn:ietf:params:scim:schemas:core:2.0:User" => [
"userName" => "Dr. John Smith",
"emails" => [
[
"value" => "[email protected]",
"type" => "other",
"primary" => true
]
]
]
], ['content-type' => 'invalid-content-type']);

$response->assertStatus(400);

$json = $response->json();

$this->assertEquals('urn:ietf:params:scim:api:messages:2.0:Error', $json['schemas'][0]);
$this->assertEquals('The content-type header should be set to "application/scim+json"', $json['detail']);
$this->assertEquals('invalidValue', $json['scimType']);
}
}
21 changes: 12 additions & 9 deletions tests/GroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ public function testGet()
]);
}

public function testCreate(){
$response = $this->post('/scim/v2/Groups', [
public function testCreate()
{
$response = $this->postJson('/scim/v2/Groups', [
'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:Group'], // Required
'urn:ietf:params:scim:schemas:core:2.0:Group' => [
'displayName' => 'TestGroup'
Expand All @@ -67,11 +68,11 @@ public function testCreate(){

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

}

public function testCreateWithMembers(){
$response = $this->post('/scim/v2/Groups', [
public function testCreateWithMembers()
{
$response = $this->postJson('/scim/v2/Groups', [
'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:Group'], // Required
'urn:ietf:params:scim:schemas:core:2.0:Group' => [
'displayName' => 'TestGroup',
Expand Down Expand Up @@ -101,8 +102,9 @@ public function testCreateWithMembers(){
$this->assertNotNull(Group::where('displayName', 'TestGroup')->first());
}

public function testBulk(){
$response = $this->post('/scim/v2/Bulk', [
public function testBulk()
{
$response = $this->postJson('/scim/v2/Bulk', [
'schemas' => ['urn:ietf:params:scim:api:messages:2.0:BulkRequest'], // Required
'Operations' => [
[
Expand Down Expand Up @@ -143,8 +145,9 @@ public function testBulk(){
$this->assertNotNull(Group::where('displayName', 'TestGroup2')->first());
}

public function testGroupCreationFailure(){
$response = $this->post('/scim/v2/Groups', []);
public function testGroupCreationFailure()
{
$response = $this->postJson('/scim/v2/Groups', []);
$response->assertStatus(400);
}
}
Loading