Skip to content

Commit

Permalink
Improved pagesize and max size support, especially for cusor pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
arietimmerman committed Jan 11, 2025
1 parent 44cfc5f commit 578dec9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
5 changes: 5 additions & 0 deletions config/scim.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
"publish_routes" => true,
'omit_main_schema_in_return' => false,
'omit_null_values' => true,

'pagination' => [
'defaultPageSize' => 10,
'maxPageSize' => 100,
]
];
10 changes: 9 additions & 1 deletion src/Http/Controllers/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function index(Request $request, PolicyDecisionPoint $pdp, ResourceType $
}

// 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".
$count = min(max(0, intVal($request->input('count', 10))), 100);
$count = min(max(0, intVal($request->input('count', config('scim.pagination.defaultPageSize')))), config('scim.pagination.maxPageSize'));

$startIndex = null;
$sortBy = null;
Expand Down Expand Up @@ -267,6 +267,14 @@ function (Builder $query) use ($filter, $resourceType) {
throw (new SCIMException('Invalid Cursor'))->setCode(400)->setScimType('invalidCursor');
}
}

$countRaw = $request->input('count');

if($countRaw < 1 || $countRaw > config('scim.pagination.maxPageSize')){
throw (new SCIMException(
sprintf('Count value is invalid. Count value must be between 1 - and maxPageSize (%s) (when using cursor pagination)', config('scim.pagination.maxPageSize'))
))->setCode(400)->setScimType('invalidCount');
}

$resourceObjects = $resourceObjects->cursorPaginate(
$count,
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/ServiceProviderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function index()
"cursor" => true,
"index" => true,
"defaultPaginationMethod" => "index",
"defaultPageSize" => 10,
"maxPageSize" => 100,
"defaultPageSize" => config('scim.pagination.defaultPageSize'),
"maxPageSize" => config('scim.pagination.maxPageSize'),
"cursorTimeout" => 3600
],
"meta" => [
Expand Down
18 changes: 18 additions & 0 deletions tests/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ public function testCursorPaginationFailure()

}

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

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

}

public function testPagination()
{
$response = $this->get('/scim/v2/Users?startIndex=21&count=20');
Expand Down Expand Up @@ -470,4 +483,9 @@ public function testPostTopLevel()
$this->assertEquals('[email protected]', $json['urn:ietf:params:scim:schemas:core:2.0:User']['emails'][0]['value']);
$this->assertEquals('Dr. Marie Jo', $json['urn:ietf:params:scim:schemas:core:2.0:User']['userName']);
}

public function testTotalResultsOnly(){
$response = $this->get('/scim/v2/Users?count=0');
$this->assertTrue(true);
}
}

0 comments on commit 578dec9

Please sign in to comment.