Skip to content

Commit 83e1476

Browse files
committed
doc: better documentation for the checkers
1 parent 6e54e11 commit 83e1476

10 files changed

Lines changed: 256 additions & 53 deletions

File tree

scim2_tester/checkers/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from .misc import random_url
1414
from .resource import resource_type_tests
1515
from .resource_delete import object_deletion
16-
from .resource_get import model_from_resource_type
1716
from .resource_get import object_query
1817
from .resource_get import object_query_without_id
1918
from .resource_post import object_creation
@@ -48,6 +47,4 @@
4847
"resource_type_tests",
4948
# Miscellaneous checkers
5049
"random_url",
51-
# Utilities
52-
"model_from_resource_type",
5350
]

scim2_tester/checkers/misc.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,26 @@
1111

1212
@checker("misc")
1313
def random_url(context: CheckContext) -> CheckResult:
14-
"""Check that a request to a random URL returns a 404 Error object."""
14+
"""Validate server error handling for non-existent endpoints.
15+
16+
Tests that the server properly returns a :class:`~scim2_models.Error` object with HTTP 404 status
17+
when accessing invalid or non-existent URLs, ensuring compliance with SCIM
18+
error handling requirements.
19+
20+
**Status:**
21+
22+
- :attr:`~scim2_tester.Status.SUCCESS`: Server returns valid :class:`~scim2_models.Error` object with 404 status
23+
- :attr:`~scim2_tester.Status.ERROR`: Server returns non-:class:`~scim2_models.Error` object or incorrect status code
24+
25+
.. pull-quote:: :rfc:`RFC 7644 Section 3.12 - Error Response Handling <7644#section-3.12>`
26+
27+
"When returning HTTP error status codes other than a '401' 'Unauthorized',
28+
'403' 'Forbidden', or '404' 'Not Found', the server SHOULD return
29+
a SCIM error response."
30+
31+
For 404 responses specifically, servers SHOULD return proper :class:`~scim2_models.Error`
32+
objects to maintain consistent error handling across all endpoints.
33+
"""
1534
probably_invalid_url = f"/{str(uuid.uuid4())}"
1635
response: Any = context.client.query(
1736
url=probably_invalid_url, raise_scim_errors=False

scim2_tester/checkers/resource.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ..utils import CheckResult
55
from ..utils import Status
66
from .resource_delete import object_deletion
7-
from .resource_get import model_from_resource_type
7+
from .resource_get import _model_from_resource_type
88
from .resource_get import object_query
99
from .resource_get import object_query_without_id
1010
from .resource_post import object_creation
@@ -15,13 +15,24 @@ def resource_type_tests(
1515
context: CheckContext,
1616
resource_type: ResourceType,
1717
) -> list[CheckResult]:
18-
"""Orchestrate CRUD tests for a resource type.
18+
"""Orchestrate comprehensive CRUD testing for a specific resource type.
1919
20-
:param context: The check context containing the SCIM client and configuration
21-
:param resource_type: The ResourceType object to test
22-
:returns: A list of check results for all tested operations
20+
Runs the complete suite of CRUD operations (Create, Read, Update, Delete)
21+
on a given resource type to validate full lifecycle management compliance.
22+
23+
**Status:**
24+
25+
- :attr:`~scim2_tester.Status.SUCCESS`: All CRUD operations completed successfully
26+
- :attr:`~scim2_tester.Status.ERROR`: One or more CRUD operations failed or no schema found
27+
28+
.. pull-quote:: :rfc:`RFC 7644 Section 3 - SCIM Protocol <7644#section-3>`
29+
30+
"SCIM is intended to reduce the cost and complexity of user management
31+
operations by providing a common user schema and extension model, as
32+
well as binding documents to provide patterns for exchanging this schema
33+
using standard protocols."
2334
"""
24-
model = model_from_resource_type(context, resource_type)
35+
model = _model_from_resource_type(context, resource_type)
2536
if not model:
2637
return [
2738
CheckResult(

scim2_tester/checkers/resource_delete.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,23 @@
1010

1111
@checker("crud:delete")
1212
def object_deletion(context: CheckContext, model: type[Resource[Any]]) -> CheckResult:
13-
"""Test object deletion with automatic cleanup.
13+
"""Validate SCIM resource deletion via DELETE requests.
1414
15-
Creates a test object specifically for deletion testing, performs the
16-
delete operation, and verifies the object no longer exists.
15+
Tests that resources can be successfully deleted using DELETE method and
16+
verifies that the resource no longer exists after deletion.
1717
18-
:param context: The check context containing the SCIM client and configuration
19-
:param model: The Resource model class to test
20-
:returns: The result of the check operation
18+
**Status:**
19+
20+
- :attr:`~scim2_tester.Status.SUCCESS`: Resource deleted successfully and no longer accessible
21+
- :attr:`~scim2_tester.Status.ERROR`: Deletion failed or resource still exists after deletion
22+
23+
.. pull-quote:: :rfc:`RFC 7644 Section 3.6 - Deleting Resources <7644#section-3.6>`
24+
25+
"Clients request resource removal via HTTP DELETE requests to the
26+
resource endpoint (e.g., ``/Users/{id}`` or ``/Groups/{id}``)."
27+
28+
"In response to a successful DELETE, the server SHALL return HTTP status
29+
code 204 (No Content)."
2130
"""
2231
test_obj = context.resource_manager.create_and_register(model)
2332

scim2_tester/checkers/resource_get.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@
99
from ..utils import checker
1010

1111

12-
def model_from_resource_type(
12+
def _model_from_resource_type(
1313
context: CheckContext, resource_type: ResourceType
1414
) -> type[Resource[Any]] | None:
15-
"""Return the Resource model class from a given ResourceType.
15+
"""Resolve Resource model class from ResourceType metadata.
1616
17-
ResourceType.name contains the resource type name (e.g., "User", "Group").
18-
This function looks up the corresponding model class from the client.
19-
20-
:param context: The check context containing the SCIM client and configuration
21-
:param resource_type: The ResourceType object containing metadata
22-
:returns: The Resource model class, or None if not found
17+
Maps a :class:`~scim2_models.ResourceType` object (containing schema URIs and metadata) to the
18+
corresponding Python model class registered in the SCIM client.
2319
"""
2420
for resource_model in context.client.resource_models:
2521
if resource_model.model_fields["schemas"].default[0] == resource_type.schema_:
@@ -30,14 +26,23 @@ def model_from_resource_type(
3026

3127
@checker("crud:read")
3228
def object_query(context: CheckContext, model: type[Resource[Any]]) -> CheckResult:
33-
"""Test object query by ID with automatic cleanup.
29+
"""Validate SCIM resource retrieval by ID via GET requests.
30+
31+
Tests that individual resources can be successfully retrieved using GET method
32+
on the resource endpoint with specific resource ID, with automatic cleanup.
33+
34+
**Status:**
35+
36+
- :attr:`~scim2_tester.Status.SUCCESS`: Resource retrieved successfully with valid data
37+
- :attr:`~scim2_tester.Status.ERROR`: Failed to retrieve or received invalid response
3438
35-
Creates a temporary test object, queries it by ID to validate the
36-
read operation.
39+
.. pull-quote:: :rfc:`RFC 7644 Section 3.4.1 - Retrieving a Known Resource <7644#section-3.4.1>`
3740
38-
:param context: The check context containing the SCIM client and configuration
39-
:param model: The Resource model class to test
40-
:returns: The result of the check operation
41+
"Clients retrieve a known resource using an HTTP GET request to the resource
42+
endpoint, such as ``/Users/{id}`` or ``/Groups/{id}``."
43+
44+
"If successful, the server responds with HTTP status code 200 (OK) and includes
45+
the target resource within the response body."
4146
"""
4247
test_obj = context.resource_manager.create_and_register(model)
4348

@@ -58,14 +63,21 @@ def object_query(context: CheckContext, model: type[Resource[Any]]) -> CheckResu
5863
def object_query_without_id(
5964
context: CheckContext, model: type[Resource[Any]]
6065
) -> CheckResult:
61-
"""Test object listing without ID with automatic cleanup.
66+
"""Validate SCIM resource listing via GET requests without ID.
67+
68+
Tests that resources can be successfully listed using GET method on the
69+
collection endpoint, validating bulk retrieval with automatic cleanup.
70+
71+
**Status:**
72+
73+
- :attr:`~scim2_tester.Status.SUCCESS`: Resources listed successfully, created resource found
74+
- :attr:`~scim2_tester.Status.ERROR`: Failed to list resources or created resource not found
6275
63-
Creates a temporary test object, performs a list/search operation to
64-
validate bulk retrieval.
76+
.. pull-quote:: :rfc:`RFC 7644 Section 3.4.2 - List/Query Resources <7644#section-3.4.2>`
6577
66-
:param context: The check context containing the SCIM client and configuration
67-
:param model: The Resource model class to test
68-
:returns: The result of the check operation
78+
"To query resources, clients send GET requests to the resource endpoint
79+
(e.g., ``/Users`` or ``/Groups``). The response to a successful query
80+
operation SHALL be a JSON structure that matches the ListResponse schema."
6981
"""
7082
test_obj = context.resource_manager.create_and_register(model)
7183

scim2_tester/checkers/resource_post.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,24 @@
1010

1111
@checker("crud:create")
1212
def object_creation(context: CheckContext, model: type[Resource[Any]]) -> CheckResult:
13-
"""Test object creation with automatic cleanup.
13+
"""Validate SCIM resource creation via POST requests.
1414
15-
Creates a test object of the specified model type, validates the creation
16-
operation.
15+
Tests that resources can be successfully created using POST method on the
16+
appropriate resource endpoint, with automatic cleanup after validation.
17+
Creates a test object with all required fields populated with valid data.
1718
18-
:param context: The check context containing the SCIM client and configuration
19-
:param model: The Resource model class to test
20-
:returns: The result of the check operation
19+
**Status:**
20+
21+
- :attr:`~scim2_tester.Status.SUCCESS`: Resource created successfully with valid response
22+
- :attr:`~scim2_tester.Status.ERROR`: Creation failed due to client/server error
23+
24+
.. pull-quote:: :rfc:`RFC 7644 Section 3.3 - Creating Resources <7644#section-3.3>`
25+
26+
"To create new resources, clients send HTTP POST requests to the resource
27+
endpoint, such as ``/Users`` or ``/Groups``."
28+
29+
"If the resource is successfully created, the server SHALL return a ``201``
30+
'Created' response code with the newly created resource."
2131
"""
2232
created_obj = context.resource_manager.create_and_register(model)
2333

scim2_tester/checkers/resource_put.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,23 @@
1414
def object_replacement(
1515
context: CheckContext, model: type[Resource[Any]]
1616
) -> CheckResult:
17-
"""Test object replacement (PUT) with automatic cleanup.
17+
"""Validate SCIM resource replacement via PUT requests.
1818
19-
Creates a test object, modifies its mutable fields, performs a replacement
20-
operation to validate the update functionality.
19+
Tests that resources can be successfully replaced using PUT method, modifying
20+
mutable fields and validating the complete resource replacement operation.
2121
22-
:param context: The check context containing the SCIM client and configuration
23-
:param model: The Resource model class to test
24-
:returns: The result of the check operation
22+
**Status:**
23+
24+
- :attr:`~scim2_tester.Status.SUCCESS`: Resource replaced successfully with valid response
25+
- :attr:`~scim2_tester.Status.ERROR`: Replacement failed due to client/server error
26+
27+
.. pull-quote:: :rfc:`RFC 7644 Section 3.5.1 - Replacing Resources <7644#section-3.5.1>`
28+
29+
"To replace a resource's attributes, clients issue an HTTP PUT request
30+
to the resource endpoint (e.g., ``/Users/{id}`` or ``/Groups/{id}``)."
31+
32+
"If successful, the server responds with HTTP status code 200 (OK) and
33+
includes the updated resource within the response body."
2534
"""
2635
test_obj = context.resource_manager.create_and_register(model)
2736

scim2_tester/checkers/resource_types.py

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,28 @@
1010

1111

1212
def resource_types_endpoint(context: CheckContext) -> list[CheckResult]:
13-
"""As described in RFC7644 §4 <rfc7644#section-4>`, `/ResourceTypes` is a mandatory endpoint, and should only be accessible by GET.
13+
"""Orchestrate validation of the ResourceTypes discovery endpoint.
14+
15+
Runs comprehensive tests on the ``/ResourceTypes`` endpoint including listing
16+
all resource types, querying individual types by ID, and error handling for
17+
invalid requests.
18+
19+
**Status:**
20+
21+
- :attr:`~scim2_tester.Status.SUCCESS`: All sub-checks completed successfully
22+
- :attr:`~scim2_tester.Status.ERROR`: One or more sub-checks failed
23+
24+
.. pull-quote:: :rfc:`RFC 7644 Section 4 - Discovery <7644#section-4>`
25+
26+
"An HTTP GET to this endpoint is used to discover the types of resources
27+
available on a SCIM service provider (e.g., Users and Groups)."
28+
29+
"Service providers MUST provide this endpoint."
1430
1531
.. todo::
1632
1733
- Check POST/PUT/PATCH/DELETE on the endpoint
1834
- Check that query parameters are ignored
19-
- Check that query parameters are ignored
2035
- Check that a 403 response is returned if a filter is passed
2136
- Check that the `schema` attribute exists and is available.
2237
"""
@@ -34,6 +49,21 @@ def resource_types_endpoint(context: CheckContext) -> list[CheckResult]:
3449

3550
@checker("discovery", "resource-types")
3651
def query_all_resource_types(context: CheckContext) -> CheckResult:
52+
"""Validate retrieval of all available resource types.
53+
54+
Tests that the ``/ResourceTypes`` endpoint returns a list of all supported
55+
resource types with their metadata, schemas, and endpoint information.
56+
57+
**Status:**
58+
59+
- :attr:`~scim2_tester.Status.SUCCESS`: Endpoint returns valid list of :class:`~scim2_models.ResourceType` objects
60+
- :attr:`~scim2_tester.Status.ERROR`: Endpoint is inaccessible or returns invalid response
61+
62+
.. pull-quote:: :rfc:`RFC 7644 Section 4 - Discovery <7644#section-4>`
63+
64+
"An HTTP GET to this endpoint is used to discover the types of resources
65+
available on a SCIM service provider (e.g., Users and Groups)."
66+
"""
3767
response = context.client.query(
3868
ResourceType, expected_status_codes=context.conf.expected_status_codes or [200]
3969
)
@@ -46,6 +76,21 @@ def query_all_resource_types(context: CheckContext) -> CheckResult:
4676
def query_resource_type_by_id(
4777
context: CheckContext, resource_type: ResourceType
4878
) -> CheckResult:
79+
"""Validate individual ResourceType retrieval by ID.
80+
81+
Tests that specific resource types can be retrieved using GET requests
82+
to ``/ResourceTypes/{id}`` with their complete metadata and configuration.
83+
84+
**Status:**
85+
86+
- :attr:`~scim2_tester.Status.SUCCESS`: :class:`~scim2_models.ResourceType` retrieved successfully with valid data
87+
- :attr:`~scim2_tester.Status.ERROR`: Failed to retrieve or received invalid response
88+
89+
.. pull-quote:: :rfc:`RFC 7644 Section 4 - Discovery <7644#section-4>`
90+
91+
"Each resource type defines the endpoint, the core schema URI that defines
92+
the resource, and any supported schema extensions."
93+
"""
4994
response = context.client.query(
5095
ResourceType,
5196
resource_type.id,
@@ -60,6 +105,20 @@ def query_resource_type_by_id(
60105

61106
@checker("discovery", "resource-types")
62107
def access_invalid_resource_type(context: CheckContext) -> CheckResult:
108+
"""Validate error handling for non-existent resource type IDs.
109+
110+
Tests that accessing ``/ResourceTypes/{invalid_id}`` with a non-existent resource
111+
type ID returns appropriate :class:`~scim2_models.Error` object with 404 status.
112+
113+
**Status:**
114+
115+
- :attr:`~scim2_tester.Status.SUCCESS`: Server returns :class:`~scim2_models.Error` object with 404 status
116+
- :attr:`~scim2_tester.Status.ERROR`: Server returns non-:class:`~scim2_models.Error` object or incorrect status
117+
118+
.. pull-quote:: :rfc:`RFC 7644 Section 3.12 - Error Response Handling <7644#section-3.12>`
119+
120+
"When returning HTTP error status codes, the server SHOULD return a SCIM error response."
121+
"""
63122
probably_invalid_id = str(uuid.uuid4())
64123
response = context.client.query(
65124
ResourceType,

0 commit comments

Comments
 (0)