Skip to content

Commit

Permalink
Added invalidCursor error
Browse files Browse the repository at this point in the history
  • Loading branch information
arietimmerman committed Jan 10, 2025
1 parent cbc6fad commit c073947
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Http/Controllers/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use ArieTimmerman\Laravel\SCIMServer\Tests\Model\User;
use Illuminate\Contracts\Pagination\CursorPaginator;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\Cursor;
use Illuminate\Support\Facades\Validator;

class ResourceController extends Controller
Expand Down Expand Up @@ -259,6 +260,14 @@ function (Builder $query) use ($filter, $resourceType) {
$resourceObjects = $resourceObjects->orderBy('id');
}

if($request->input('cursor')){
$cursor = @Cursor::fromEncoded($request->input('cursor'));

if($cursor == null){
throw (new SCIMException('Invalid Cursor'))->setCode(400)->setScimType('invalidCursor');
}
}

$resourceObjects = $resourceObjects->cursorPaginate(
$count,
cursor: $request->input('cursor')
Expand Down
13 changes: 13 additions & 0 deletions tests/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ public function testCursorPagination()
$this->assertNull($response2->json('startIndex'));
}

public function testCursorPaginationFailure()
{
$response1 = $this->get('/scim/v2/Users?count=60&cursor=invalid');

$response1->assertStatus(400);
$response1->assertJson([
'schemas' => ['urn:ietf:params:scim:api:messages:2.0:Error'],
'status' => '400',
'scimType' => 'invalidCursor'
]);

}

public function testPagination()
{
$response = $this->get('/scim/v2/Users?startIndex=21&count=20');
Expand Down

0 comments on commit c073947

Please sign in to comment.