Skip to content

Commit c1b1574

Browse files
committed
feat: check for Schema and ResourceType with invalid ids
1 parent 273fa47 commit c1b1574

5 files changed

Lines changed: 92 additions & 3 deletions

File tree

doc/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Added
88
^^^^^
99
- Restrict expected status codes in checks.
1010
- Check individual :class:`~scim2_models.Schema` and :class:`~scim2_models.ResourceType` endpoints.
11+
- Check for :class:`~scim2_models.Schema` and :class:`~scim2_models.ResourceType` with invalid ids.
1112

1213
Fixed
1314
^^^^^

scim2_tester/resource_types.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import uuid
2+
13
from scim2_models import Error
24
from scim2_models import ResourceType
35

@@ -25,6 +27,8 @@ def check_resource_types_endpoint(conf: CheckConfig) -> list[CheckResult]:
2527
for resource_type in resource_types_result.data:
2628
results.append(check_query_resource_type_by_id(conf, resource_type))
2729

30+
results.append(check_access_invalid_resource_type(conf))
31+
2832
return results
2933

3034

@@ -56,3 +60,37 @@ def check_query_resource_type_by_id(
5660

5761
reason = f"Successfully accessed the /ResourceTypes/{resource_type.id} endpoint."
5862
return CheckResult(conf, status=Status.SUCCESS, reason=reason, data=response)
63+
64+
65+
@checker
66+
def check_access_invalid_resource_type(conf: CheckConfig) -> CheckResult:
67+
probably_invalid_id = str(uuid.uuid4())
68+
response = conf.client.query(
69+
ResourceType,
70+
probably_invalid_id,
71+
expected_status_codes=conf.expected_status_codes or [404],
72+
raise_scim_errors=False,
73+
)
74+
75+
if not isinstance(response, Error):
76+
return CheckResult(
77+
conf,
78+
status=Status.ERROR,
79+
reason=f"/resource_types/{probably_invalid_id} invalid URL did not return an Error object",
80+
data=response,
81+
)
82+
83+
if response.status != 404:
84+
return CheckResult(
85+
conf,
86+
status=Status.ERROR,
87+
reason=f"/resource_types/{probably_invalid_id} invalid URL did return an object, but the status code is {response.status}",
88+
data=response,
89+
)
90+
91+
return CheckResult(
92+
conf,
93+
status=Status.SUCCESS,
94+
reason=f"/resource_types/{probably_invalid_id} invalid URL correctly returned a 404 error",
95+
data=response,
96+
)

scim2_tester/schemas.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import uuid
2+
13
from scim2_models import Error
24
from scim2_models import Schema
35

@@ -25,6 +27,8 @@ def check_schemas_endpoint(conf: CheckConfig) -> list[CheckResult]:
2527
for resource_type in schemas_result.data:
2628
results.append(check_query_schema_by_id(conf, resource_type))
2729

30+
results.append(check_access_invalid_schema(conf))
31+
2832
return results
2933

3034

@@ -56,3 +60,37 @@ def check_query_schema_by_id(conf: CheckConfig, schema: Schema) -> CheckResult:
5660

5761
reason = f"Successfully accessed the /Schemas/{schema.id} endpoint."
5862
return CheckResult(conf, status=Status.SUCCESS, reason=reason, data=response)
63+
64+
65+
@checker
66+
def check_access_invalid_schema(conf: CheckConfig) -> CheckResult:
67+
probably_invalid_id = str(uuid.uuid4())
68+
response = conf.client.query(
69+
Schema,
70+
probably_invalid_id,
71+
expected_status_codes=conf.expected_status_codes or [404],
72+
raise_scim_errors=False,
73+
)
74+
75+
if not isinstance(response, Error):
76+
return CheckResult(
77+
conf,
78+
status=Status.ERROR,
79+
reason=f"/Schemas/{probably_invalid_id} invalid URL did not return an Error object",
80+
data=response,
81+
)
82+
83+
if response.status != 404:
84+
return CheckResult(
85+
conf,
86+
status=Status.ERROR,
87+
reason=f"/Schemas/{probably_invalid_id} invalid URL did return an object, but the status code is {response.status}",
88+
data=response,
89+
)
90+
91+
return CheckResult(
92+
conf,
93+
status=Status.SUCCESS,
94+
reason=f"/Schemas/{probably_invalid_id} invalid URL correctly returned a 404 error",
95+
data=response,
96+
)

tests/test_resource_types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22

33
from scim2_models import Context
4+
from scim2_models import Error
45
from scim2_models import ListResponse
56
from scim2_models import ResourceType
67

@@ -26,6 +27,11 @@ def test_resource_types_endpoint(httpserver, check_config):
2627
status=200,
2728
content_type="application/scim+json",
2829
)
30+
httpserver.expect_request(re.compile(r"^/ResourceTypes/.*$")).respond_with_json(
31+
Error(status=404, detail="ResourceType Not Found").model_dump(),
32+
status=404,
33+
content_type="application/scim+json",
34+
)
2935

3036
results = check_resource_types_endpoint(check_config)
3137

tests/test_schemas.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import re
22

33
from scim2_models import Context
4+
from scim2_models import Error
45
from scim2_models import ListResponse
56
from scim2_models import Schema
67

78
from scim2_tester.schemas import check_schemas_endpoint
89
from scim2_tester.utils import Status
910

1011

11-
def test_schemas_endpoint(httpserver, check_config):
12-
"""Test a fully functional resource types endpoint."""
12+
def test_shemas_endpoint(httpserver, check_config):
13+
"""Test a fully functional schemas endpoint."""
1314
schemas = [model.to_schema() for model in check_config.client.resource_models]
1415
httpserver.expect_request(re.compile(r"^/Schemas$")).respond_with_json(
1516
ListResponse[Schema](
@@ -27,13 +28,18 @@ def test_schemas_endpoint(httpserver, check_config):
2728
status=200,
2829
content_type="application/scim+json",
2930
)
31+
httpserver.expect_request(re.compile(r"^/Schemas/.*$")).respond_with_json(
32+
Error(status=404, detail="Schema Not Found").model_dump(),
33+
status=404,
34+
content_type="application/scim+json",
35+
)
3036

3137
results = check_schemas_endpoint(check_config)
3238

3339
assert all(result.status == Status.SUCCESS for result in results)
3440

3541

36-
def test_resource_missing_query_endpoint(httpserver, check_config):
42+
def test_missing_query_endpoint(httpserver, check_config):
3743
"""Test that individual Schema endpoints are missing."""
3844
schemas = [model.to_schema() for model in check_config.client.resource_models]
3945
httpserver.expect_request(re.compile(r"^/Schemas$")).respond_with_json(

0 commit comments

Comments
 (0)