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,88 @@ 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+ results .extend (resource_types_schema_validation (context ))
43+
4544 results .append (access_invalid_resource_type (context ))
4645
4746 return results
4847
4948
49+ @checker ("discovery" , "resource-types" )
50+ def resource_types_endpoint_methods (
51+ context : CheckContext ,
52+ ) -> list [CheckResult ]:
53+ """Validate that unsupported HTTP methods return 405 Method Not Allowed.
54+
55+ Tests that POST, PUT, PATCH, and DELETE methods on the ``/ResourceTypes``
56+ endpoint correctly return HTTP 405 Method Not Allowed status, as only GET is supported.
57+
58+ **Status:**
59+
60+ - :attr:`~scim2_tester.Status.SUCCESS`: All unsupported methods return 405 status
61+ - :attr:`~scim2_tester.Status.ERROR`: One or more methods return unexpected status
62+
63+ .. pull-quote:: :rfc:`RFC 7644 Section 4 - Discovery <7644#section-4>`
64+
65+ "An HTTP GET to this endpoint is used to discover the types of resources
66+ available on a SCIM service provider."
67+
68+ Only GET method is specified, other methods should return appropriate errors.
69+ """
70+ return _test_discovery_endpoint_methods (context , "/ResourceTypes" )
71+
72+
73+ @checker ("discovery" , "resource-types" )
74+ def resource_types_schema_validation (
75+ context : CheckContext ,
76+ ) -> list [CheckResult ]:
77+ """Validate that ResourceType schemas exist and are accessible.
78+
79+ Tests that all :class:`~scim2_models.ResourceType` objects returned by the
80+ ``/ResourceTypes`` endpoint reference valid schemas that can be retrieved
81+ from the ``/Schemas`` endpoint.
82+
83+ **Status:**
84+
85+ - :attr:`~scim2_tester.Status.SUCCESS`: All ResourceType schemas are accessible
86+ - :attr:`~scim2_tester.Status.ERROR`: One or more ResourceType schemas are missing or inaccessible
87+
88+ .. pull-quote:: :rfc:`RFC 7644 Section 4 - Discovery <7644#section-4>`
89+
90+ "Each resource type defines the endpoint, the core schema URI that defines
91+ the resource, and any supported schema extensions."
92+ """
93+ response = context .client .query (
94+ ResourceType , expected_status_codes = context .conf .expected_status_codes or [200 ]
95+ )
96+
97+ results = []
98+ for resource_type in response .resources :
99+ schema_id = resource_type .schema_
100+ try :
101+ schema_response = context .client .query (
102+ Schema ,
103+ schema_id ,
104+ expected_status_codes = context .conf .expected_status_codes or [200 ],
105+ )
106+ results .append (
107+ CheckResult (
108+ status = Status .SUCCESS ,
109+ reason = f"ResourceType '{ resource_type .name } ' schema '{ schema_id } ' is accessible" ,
110+ data = schema_response ,
111+ )
112+ )
113+ except SCIMClientError as e :
114+ results .append (
115+ CheckResult (
116+ status = Status .ERROR ,
117+ reason = f"ResourceType '{ resource_type .name } ' schema '{ schema_id } ' is not accessible: { str (e )} " ,
118+ )
119+ )
120+
121+ return results
122+
123+
50124@checker ("discovery" , "resource-types" )
51125def query_all_resource_types (context : CheckContext ) -> CheckResult :
52126 """Validate retrieval of all available resource types.
0 commit comments