@@ -36,7 +36,8 @@ all() ->
3636 stream_producer_crash ,
3737 stream_non_200_status ,
3838 callback_crash ,
39- json_content_type
39+ json_content_type ,
40+ malformed_body
4041 ].
4142
4243% %%-----------------------------------------------------------------------------
@@ -952,6 +953,50 @@ json_content_type(_Conf) ->
952953
953954 ok .
954955
956+ malformed_body (_Conf ) ->
957+ meck :new ([erf_callback ], [non_strict , no_link ]),
958+
959+ meck :expect (
960+ erf_callback ,
961+ create_foo ,
962+ fun (_Request ) ->
963+ {201 , [], <<" bar" >>}
964+ end
965+ ),
966+
967+ {ok , _Pid } = erf :start_link (#{
968+ spec_path => filename :join (
969+ [code :lib_dir (erf ), " test" , <<" fixtures/with_refs_oas_3_0_spec.json" >>]
970+ ),
971+ callback => erf_callback ,
972+ port => 8789 ,
973+ name => erf_server
974+ }),
975+
976+ {ok , {{" HTTP/1.1" , 400 , " Bad Request" }, Headers , Body }} =
977+ httpc :request (
978+ post ,
979+ {" http://localhost:8789/1/foo" , [], " application/json" , <<" {oops" >>},
980+ [],
981+ [{body_format , binary }]
982+ ),
983+
984+ ? assertEqual (" application/json" , proplists :get_value (" content-type" , Headers )),
985+ ? assertEqual (
986+ #{
987+ <<" title" >> => <<" Bad Request" >>,
988+ <<" status" >> => 400 ,
989+ <<" detail" >> => <<" Failed to read request" >>
990+ },
991+ json :decode (Body )
992+ ),
993+
994+ ok = erf :stop (erf_server ),
995+
996+ meck :unload (erf_callback ),
997+
998+ ok .
999+
9551000% %%-----------------------------------------------------------------------------
9561001% %% INTERNAL HELPERS
9571002% %%-----------------------------------------------------------------------------
0 commit comments