Skip to content

Commit 44cfc5f

Browse files
Added invalidCursor error (limosa-io#105)
1 parent cbc6fad commit 44cfc5f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Http/Controllers/ResourceController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ArieTimmerman\Laravel\SCIMServer\Tests\Model\User;
1919
use Illuminate\Contracts\Pagination\CursorPaginator;
2020
use Illuminate\Database\Eloquent\Builder;
21+
use Illuminate\Pagination\Cursor;
2122
use Illuminate\Support\Facades\Validator;
2223

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

263+
if($request->input('cursor')){
264+
$cursor = @Cursor::fromEncoded($request->input('cursor'));
265+
266+
if($cursor == null){
267+
throw (new SCIMException('Invalid Cursor'))->setCode(400)->setScimType('invalidCursor');
268+
}
269+
}
270+
262271
$resourceObjects = $resourceObjects->cursorPaginate(
263272
$count,
264273
cursor: $request->input('cursor')

tests/BasicTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ public function testCursorPagination()
140140
$this->assertNull($response2->json('startIndex'));
141141
}
142142

143+
public function testCursorPaginationFailure()
144+
{
145+
$response1 = $this->get('/scim/v2/Users?count=60&cursor=invalid');
146+
147+
$response1->assertStatus(400);
148+
$response1->assertJson([
149+
'schemas' => ['urn:ietf:params:scim:api:messages:2.0:Error'],
150+
'status' => '400',
151+
'scimType' => 'invalidCursor'
152+
]);
153+
154+
}
155+
143156
public function testPagination()
144157
{
145158
$response = $this->get('/scim/v2/Users?startIndex=21&count=20');

0 commit comments

Comments
 (0)