diff --git a/doc/changelog.rst b/doc/changelog.rst index 7f4c3fa..be0cf4b 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,6 +1,13 @@ Changelog ========= +[0.7.2] - Unreleased +-------------------- + +Fixed +^^^^^ +- Skip ``Content-Type`` header validation for 204 responses. :issue:`34` + [0.7.1] - 2025-01-25 -------------------- diff --git a/scim2_client/client.py b/scim2_client/client.py index 63068b2..f1ea455 100644 --- a/scim2_client/client.py +++ b/scim2_client/client.py @@ -290,8 +290,6 @@ def check_response( if raise_scim_errors is None: raise_scim_errors = self.raise_scim_errors - self._check_content_types(headers) - # In addition to returning an HTTP response code, implementers MUST return # the errors in the body of the response in a JSON format # https://datatracker.ietf.org/doc/html/rfc7644.html#section-3.12 @@ -301,6 +299,7 @@ def check_response( response_payload = None else: + self._check_content_types(headers) response_payload = payload if check_response_payload is None: diff --git a/tests/test_delete.py b/tests/test_delete.py index e2eed0d..465e3d5 100644 --- a/tests/test_delete.py +++ b/tests/test_delete.py @@ -21,6 +21,16 @@ def test_delete_user(httpserver, sync_client): assert response is None +def test_delete_user_without_content_type_header(httpserver, sync_client): + """Server returns 204 without Content-Type header, which is valid per RFC 7231.""" + httpserver.expect_request( + "/Users/2819c223-7f76-453a-919d-413861904646", method="DELETE" + ).respond_with_data(status=204) + + response = sync_client.delete(User, "2819c223-7f76-453a-919d-413861904646") + assert response is None + + @pytest.mark.parametrize("code", [400, 401, 403, 404, 412, 500, 501]) def test_errors(httpserver, code, sync_client): """Test error cases defined in RFC7644.""" diff --git a/tests/test_modify.py b/tests/test_modify.py index 6dc8e08..cef4956 100644 --- a/tests/test_modify.py +++ b/tests/test_modify.py @@ -69,6 +69,27 @@ def test_modify_user_204(httpserver, sync_client): assert response is None +def test_modify_user_204_without_content_type_header(httpserver, sync_client): + """Server returns 204 without Content-Type header, which is valid per RFC 7231.""" + httpserver.expect_request( + "/Users/2819c223-7f76-453a-919d-413861904646", method="PATCH" + ).respond_with_data( + "", + status=204, + ) + + operation = PatchOperation( + op=PatchOperation.Op.replace_, path="active", value=False + ) + patch_op = PatchOp[User](operations=[operation]) + + response = sync_client.modify( + User, "2819c223-7f76-453a-919d-413861904646", patch_op + ) + + assert response is None + + def test_modify_user_multiple_operations(httpserver, sync_client): """Test User modification with multiple patch operations.""" httpserver.expect_request(