Skip to content

Commit 0d0814b

Browse files
committed
fix: list the supported methods in 405 answers
1 parent 696fdaa commit 0d0814b

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎scim2_server/provider.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from werkzeug.datastructures import ETags
3737
from werkzeug.exceptions import Forbidden
3838
from werkzeug.exceptions import HTTPException
39+
from werkzeug.exceptions import MethodNotAllowed
3940
from werkzeug.exceptions import NotFound
4041
from werkzeug.exceptions import NotImplemented as WerkzeugNotImplemented
4142
from werkzeug.exceptions import PreconditionFailed
@@ -828,7 +829,11 @@ def wsgi_app(self, request: Request, environ: "WSGIEnvironment") -> Response:
828829
self.log.exception(e)
829830
return e.get_response(environ)
830831
except Exception as e:
831-
return self.make_error(self.error_from(e))
832+
response = self.make_error(self.error_from(e))
833+
if isinstance(e, MethodNotAllowed) and e.valid_methods:
834+
# RFC 9110 §15.5.6: a 405 answer lists the supported methods.
835+
response.headers["Allow"] = ", ".join(sorted(e.valid_methods))
836+
return response
832837

833838
def __call__(
834839
self, environ: "WSGIEnvironment", start_response: "StartResponse"

‎tests/test_provider.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@ def test_unsupported_method_on_a_reserved_endpoint(self, wsgi, method, path):
112112

113113
assert r.status_code == 405
114114

115+
@pytest.mark.parametrize(
116+
("method", "path", "allowed"),
117+
[
118+
("POST", "/v2/Schemas", "GET, HEAD"),
119+
("GET", "/v2/Bulk", "POST"),
120+
],
121+
)
122+
def test_method_not_allowed_lists_the_supported_methods(
123+
self, wsgi, method, path, allowed
124+
):
125+
"""A 405 answer tells the methods the endpoint supports."""
126+
r = wsgi.request(method, path)
127+
128+
assert r.headers["Allow"] == allowed
129+
115130
def test_unknown_resource_endpoint(self, wsgi):
116131
"""An endpoint that is neither reserved nor served answers 404."""
117132
r = wsgi.get("/v2/SchemasArchive")

0 commit comments

Comments
 (0)