Skip to content

Commit 3fd46be

Browse files
Improved pagesize and max size support, especially for cusor pagination (limosa-io#106)
1 parent 44cfc5f commit 3fd46be

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

config/scim.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
"publish_routes" => true,
55
'omit_main_schema_in_return' => false,
66
'omit_null_values' => true,
7+
8+
'pagination' => [
9+
'defaultPageSize' => 10,
10+
'maxPageSize' => 100,
11+
]
712
];

src/Http/Controllers/ResourceController.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public function index(Request $request, PolicyDecisionPoint $pdp, ResourceType $
219219
}
220220

221221
// Non-negative integer. Specifies the desired maximum number of query results per page, e.g., 10. A negative value SHALL be interpreted as "0". A value of "0" indicates that no resource results are to be returned except for "totalResults".
222-
$count = min(max(0, intVal($request->input('count', 10))), 100);
222+
$count = min(max(0, intVal($request->input('count', config('scim.pagination.defaultPageSize')))), config('scim.pagination.maxPageSize'));
223223

224224
$startIndex = null;
225225
$sortBy = null;
@@ -267,6 +267,14 @@ function (Builder $query) use ($filter, $resourceType) {
267267
throw (new SCIMException('Invalid Cursor'))->setCode(400)->setScimType('invalidCursor');
268268
}
269269
}
270+
271+
$countRaw = $request->input('count');
272+
273+
if($countRaw < 1 || $countRaw > config('scim.pagination.maxPageSize')){
274+
throw (new SCIMException(
275+
sprintf('Count value is invalid. Count value must be between 1 - and maxPageSize (%s) (when using cursor pagination)', config('scim.pagination.maxPageSize'))
276+
))->setCode(400)->setScimType('invalidCount');
277+
}
270278

271279
$resourceObjects = $resourceObjects->cursorPaginate(
272280
$count,

src/Http/Controllers/ServiceProviderController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public function index()
5454
"cursor" => true,
5555
"index" => true,
5656
"defaultPaginationMethod" => "index",
57-
"defaultPageSize" => 10,
58-
"maxPageSize" => 100,
57+
"defaultPageSize" => config('scim.pagination.defaultPageSize'),
58+
"maxPageSize" => config('scim.pagination.maxPageSize'),
5959
"cursorTimeout" => 3600
6060
],
6161
"meta" => [

tests/BasicTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ public function testCursorPaginationFailure()
153153

154154
}
155155

156+
public function testCursorPaginationFailureMaxCount()
157+
{
158+
$response1 = $this->get('/scim/v2/Users?count=200&cursor');
159+
160+
$response1->assertStatus(400);
161+
$response1->assertJson([
162+
'schemas' => ['urn:ietf:params:scim:api:messages:2.0:Error'],
163+
'status' => '400',
164+
'scimType' => 'invalidCount'
165+
]);
166+
167+
}
168+
156169
public function testPagination()
157170
{
158171
$response = $this->get('/scim/v2/Users?startIndex=21&count=20');
@@ -470,4 +483,9 @@ public function testPostTopLevel()
470483
$this->assertEquals('mariejo@example.com', $json['urn:ietf:params:scim:schemas:core:2.0:User']['emails'][0]['value']);
471484
$this->assertEquals('Dr. Marie Jo', $json['urn:ietf:params:scim:schemas:core:2.0:User']['userName']);
472485
}
486+
487+
public function testTotalResultsOnly(){
488+
$response = $this->get('/scim/v2/Users?count=0');
489+
$this->assertTrue(true);
490+
}
473491
}

0 commit comments

Comments
 (0)