@@ -773,3 +773,72 @@ async def test_client_get_signed_base_and_extended_cards(
773773
774774 if hasattr (transport , 'close' ):
775775 await transport .close ()
776+
777+
778+ @pytest .mark .asyncio
779+ async def test_jsonrpc_malformed_payload (jsonrpc_setup : TransportSetup ) -> None :
780+ """Integration test to verify that JSON-RPC malformed payloads don't return 500."""
781+ transport = jsonrpc_setup .transport
782+ client = transport .httpx_client
783+ url = transport .url
784+
785+ # 1. Invalid JSON
786+ response = await client .post (url , content = 'not a json' )
787+ assert response .status_code == 200
788+ assert response .json ()['error' ]['code' ] == - 32700 # Parse error
789+
790+ # 2. Wrong types in params
791+ response = await client .post (
792+ url ,
793+ json = {
794+ 'jsonrpc' : '2.0' ,
795+ 'method' : 'SendMessage' ,
796+ 'params' : {'message' : 'should be an object' },
797+ 'id' : 1 ,
798+ },
799+ )
800+ assert response .status_code == 200
801+ assert response .json ()['error' ]['code' ] == - 32602 # Invalid params
802+
803+ await transport .close ()
804+
805+
806+ @pytest .mark .asyncio
807+ @pytest .mark .parametrize (
808+ 'method, path, request_kwargs' ,
809+ [
810+ pytest .param (
811+ 'POST' ,
812+ '/message:send' ,
813+ {'content' : 'not a json' },
814+ id = 'invalid-json' ,
815+ ),
816+ pytest .param (
817+ 'POST' ,
818+ '/message:send' ,
819+ {'json' : {'message' : 'should be an object' }},
820+ id = 'wrong-body-type' ,
821+ ),
822+ pytest .param (
823+ 'GET' ,
824+ '/tasks' ,
825+ {'params' : {'historyLength' : 'not_an_int' }},
826+ id = 'wrong-query-param-type' ,
827+ ),
828+ ],
829+ )
830+ async def test_rest_malformed_payload (
831+ rest_setup : TransportSetup ,
832+ method : str ,
833+ path : str ,
834+ request_kwargs : dict [str , Any ],
835+ ) -> None :
836+ """Integration test to verify that REST malformed payloads don't return 500."""
837+ transport = rest_setup .transport
838+ client = transport .httpx_client
839+ url = transport .url
840+
841+ response = await client .request (method , f'{ url } { path } ' , ** request_kwargs )
842+ assert response .status_code == 400
843+
844+ await transport .close ()
0 commit comments