@@ -164,7 +164,7 @@ def _patch_handle_non_streaming_common(
164164def dummy_request_fixture () -> Request :
165165 """Minimal FastAPI Request with authorized_actions for responses endpoint."""
166166 req = Request (scope = {"type" : "http" , "headers" : []})
167- req .state .authorized_actions = {Action .QUERY , Action .READ_OTHERS_CONVERSATIONS }
167+ req .state .authorized_actions = {Action .RESPONSES , Action .READ_OTHERS_CONVERSATIONS }
168168 return req
169169
170170
@@ -636,6 +636,40 @@ async def test_tool_choice_none_without_tools_does_not_load_server_tools(
636636 assert call_kwargs ["request" ].tools is None
637637 assert call_kwargs ["request" ].tool_choice is None
638638
639+ @pytest .mark .asyncio
640+ async def test_responses_endpoint_rejects_without_responses_action (
641+ self ,
642+ mocker : MockerFixture ,
643+ ) -> None :
644+ """Verify that requests lacking Action.RESPONSES are rejected with 403.
645+
646+ Constructs a request whose authorized_actions includes Action.QUERY and
647+ Action.READ_OTHERS_CONVERSATIONS but NOT Action.RESPONSES, then asserts
648+ the @authorize(Action.RESPONSES) decorator raises HTTPException 403.
649+ """
650+ req = Request (scope = {"type" : "http" , "headers" : []})
651+ req .state .authorized_actions = {Action .QUERY , Action .READ_OTHERS_CONVERSATIONS }
652+
653+ mock_role_resolver = mocker .AsyncMock ()
654+ mock_role_resolver .resolve_roles = mocker .AsyncMock (return_value = set ())
655+
656+ mock_access_resolver = mocker .Mock ()
657+ mock_access_resolver .check_access .return_value = False
658+
659+ mocker .patch (
660+ "authorization.middleware.get_authorization_resolvers" ,
661+ return_value = (mock_role_resolver , mock_access_resolver ),
662+ )
663+
664+ with pytest .raises (HTTPException ) as exc_info :
665+ await responses_endpoint_handler (
666+ request = req ,
667+ responses_request = ResponsesRequest (input = "Hello" ),
668+ auth = MOCK_AUTH ,
669+ mcp_headers = {},
670+ )
671+ assert exc_info .value .status_code == 403
672+
639673
640674class TestHandleNonStreamingResponse :
641675 """Unit tests for handle_non_streaming_response."""
0 commit comments