Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes content type header validaton #70

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 8 additions & 8 deletions tests/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ class BasicTest extends TestCase
{
public function testGet()
{
$response = $this->get('/scim/v2/Users');
$response = $this->get('/scim/v2/Users', $this->headers);

$response->assertStatus(200);
}

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

$response->assertStatus(200);

Expand All @@ -41,7 +41,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 @@ -57,7 +57,7 @@ public function testPatch()
]
]
]]
]);
], $this->headers);

$response->assertStatus(200);

Expand All @@ -69,13 +69,13 @@ public function testPatch()

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 @@ -91,7 +91,7 @@ public function testPost()
]
]
]
]);
], $this->headers);

$this->assertEquals(
201,
Expand Down
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']);
}
}
9 changes: 9 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ abstract class TestCase extends BaseTestCase

protected $baseUrl = 'http://localhost';

protected $headers = [
'host' => 'localhost',
'user-agent' => 'Symfony',
'accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'accept-language' => 'en-us,en;q=0.5',
'accept-charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'content-type' => 'application/scim+json',
];

protected function setUp(): void
{
parent::setUp();
Expand Down
Loading