@@ -566,6 +566,41 @@ class StreamableHTTPTransportTest < ActiveSupport::TestCase
566
566
assert_not @transport . instance_variable_get ( :@sessions ) . key? ( session_id )
567
567
end
568
568
569
+ test "responds with 405 for unsupported methods" do
570
+ request = create_rack_request (
571
+ "PUT" ,
572
+ "/" ,
573
+ { } ,
574
+ )
575
+
576
+ response = @transport . handle_request ( request )
577
+ assert_equal 405 , response [ 0 ]
578
+ assert_equal ( { "Content-Type" => "application/json" } , response [ 1 ] )
579
+
580
+ body = JSON . parse ( response [ 2 ] [ 0 ] )
581
+ assert_equal "Method not allowed" , body [ "error" ]
582
+ end
583
+
584
+ test "handle post request with a standard error" do
585
+ request = create_rack_request (
586
+ "POST" ,
587
+ "/" ,
588
+ { "CONTENT_TYPE" => "application/json" } ,
589
+ { jsonrpc : "2.0" , method : "initialize" , id : "4567" } . to_json ,
590
+ )
591
+
592
+ @transport . define_singleton_method ( :extract_session_id ) do |_request |
593
+ raise StandardError , "Test error"
594
+ end
595
+
596
+ response = @transport . handle_request ( request )
597
+ assert_equal 500 , response [ 0 ]
598
+ assert_equal ( { "Content-Type" => "application/json" } , response [ 1 ] )
599
+
600
+ body = JSON . parse ( response [ 2 ] [ 0 ] )
601
+ assert_equal "Internal server error" , body [ "error" ]
602
+ end
603
+
569
604
private
570
605
571
606
def create_rack_request ( method , path , headers , body = nil )
0 commit comments