11import uuid
22
3+ from scim2_client import SCIMClientError
34from scim2_models import Error
45from scim2_models import ResourceType
6+ from scim2_models import Schema
57
68from ..utils import CheckContext
79from ..utils import CheckResult
810from ..utils import Status
911from ..utils import checker
12+ from ._discovery_utils import _test_discovery_endpoint_methods
1013
1114
12- def resource_types_endpoint (context : CheckContext ) -> list [CheckResult ]:
15+ def _resource_types_endpoint (context : CheckContext ) -> list [CheckResult ]:
1316 """Orchestrate validation of the ResourceTypes discovery endpoint.
1417
1518 Runs comprehensive tests on the ``/ResourceTypes`` endpoint including listing
@@ -28,12 +31,6 @@ def resource_types_endpoint(context: CheckContext) -> list[CheckResult]:
2831
2932 "Service providers MUST provide this endpoint."
3033
31- .. todo::
32-
33- - Check POST/PUT/PATCH/DELETE on the endpoint
34- - Check that query parameters are ignored
35- - Check that a 403 response is returned if a filter is passed
36- - Check that the `schema` attribute exists and is available.
3734 """
3835 resource_types_result = query_all_resource_types (context )
3936 results = [resource_types_result ]
@@ -42,11 +39,89 @@ def resource_types_endpoint(context: CheckContext) -> list[CheckResult]:
4239 for resource_type in resource_types_result .data :
4340 results .append (query_resource_type_by_id (context , resource_type ))
4441
42+ # Validate that all ResourceType schemas are accessible
43+ results .extend (resource_types_schema_validation (context ))
44+
4545 results .append (access_invalid_resource_type (context ))
4646
4747 return results
4848
4949
50+ @checker ("discovery" , "resource-types" )
51+ def resource_types_endpoint_methods (
52+ context : CheckContext ,
53+ ) -> list [CheckResult ]:
54+ """Validate that unsupported HTTP methods return 405 Method Not Allowed.
55+
56+ Tests that POST, PUT, PATCH, and DELETE methods on the ``/ResourceTypes``
57+ endpoint correctly return HTTP 405 Method Not Allowed status, as only GET is supported.
58+
59+ **Status:**
60+
61+ - :attr:`~scim2_tester.Status.SUCCESS`: All unsupported methods return 405 status
62+ - :attr:`~scim2_tester.Status.ERROR`: One or more methods return unexpected status
63+
64+ .. pull-quote:: :rfc:`RFC 7644 Section 4 - Discovery <7644#section-4>`
65+
66+ "An HTTP GET to this endpoint is used to discover the types of resources
67+ available on a SCIM service provider."
68+
69+ Only GET method is specified, other methods should return appropriate errors.
70+ """
71+ return _test_discovery_endpoint_methods (context , "/ResourceTypes" )
72+
73+
74+ @checker ("discovery" , "resource-types" )
75+ def resource_types_schema_validation (
76+ context : CheckContext ,
77+ ) -> list [CheckResult ]:
78+ """Validate that ResourceType schemas exist and are accessible.
79+
80+ Tests that all :class:`~scim2_models.ResourceType` objects returned by the
81+ ``/ResourceTypes`` endpoint reference valid schemas that can be retrieved
82+ from the ``/Schemas`` endpoint.
83+
84+ **Status:**
85+
86+ - :attr:`~scim2_tester.Status.SUCCESS`: All ResourceType schemas are accessible
87+ - :attr:`~scim2_tester.Status.ERROR`: One or more ResourceType schemas are missing or inaccessible
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+ """
94+ response = context .client .query (
95+ ResourceType , expected_status_codes = context .conf .expected_status_codes or [200 ]
96+ )
97+
98+ results = []
99+ for resource_type in response .resources :
100+ schema_id = resource_type .schema_
101+ try :
102+ schema_response = context .client .query (
103+ Schema ,
104+ schema_id ,
105+ expected_status_codes = context .conf .expected_status_codes or [200 ],
106+ )
107+ results .append (
108+ CheckResult (
109+ status = Status .SUCCESS ,
110+ reason = f"ResourceType '{ resource_type .name } ' schema '{ schema_id } ' is accessible" ,
111+ data = schema_response ,
112+ )
113+ )
114+ except SCIMClientError as e :
115+ results .append (
116+ CheckResult (
117+ status = Status .ERROR ,
118+ reason = f"ResourceType '{ resource_type .name } ' schema '{ schema_id } ' is not accessible: { str (e )} " ,
119+ )
120+ )
121+
122+ return results
123+
124+
50125@checker ("discovery" , "resource-types" )
51126def query_all_resource_types (context : CheckContext ) -> CheckResult :
52127 """Validate retrieval of all available resource types.
0 commit comments