diff --git a/mitmproxy2swagger/test_mitmproxy2swagger.py b/mitmproxy2swagger/test_mitmproxy2swagger.py index 8c15585..f179be6 100644 --- a/mitmproxy2swagger/test_mitmproxy2swagger.py +++ b/mitmproxy2swagger/test_mitmproxy2swagger.py @@ -50,6 +50,24 @@ def test_mitmproxy2swagger_generates_swagger_from_mitmproxy_flow_file_with_form_ ) +def test_mitmproxy2swagger_generates_swagger_from_har_file_with_form_data(): + # Regression test for https://github.com/alufers/mitmproxy2swagger/pull/174 + # HAR bodies are already decoded strings; calling .decode() on them raised AttributeError + data = mitmproxy2swagger_e2e_test( + "testdata/form_data_har.har", + "https://httpbin.org/", + ) + assert data is not None + + assert ( + get_nested_key( + data, + "paths./post.post.requestBody.content.application/x-www-form-urlencoded.schema", + ) + is not None + ) + + def test_mitmproxy2swagger_generates_swagger_from_mitmproxy_flow_file_with_generic_keys(): data = mitmproxy2swagger_e2e_test( "testdata/generic_keys_flows", diff --git a/testdata/form_data_har.har b/testdata/form_data_har.har new file mode 100644 index 0000000..866bb03 --- /dev/null +++ b/testdata/form_data_har.har @@ -0,0 +1,41 @@ +{ + "log": { + "version": "1.2", + "creator": { "name": "test", "version": "1.0" }, + "entries": [ + { + "request": { + "method": "POST", + "url": "https://httpbin.org/post", + "headers": [ + { "name": "Content-Type", "value": "application/x-www-form-urlencoded" } + ], + "postData": { + "mimeType": "application/x-www-form-urlencoded", + "text": "username=alice&password=secret" + }, + "queryString": [], + "cookies": [], + "headersSize": -1, + "bodySize": 29 + }, + "response": { + "status": 200, + "statusText": "OK", + "headers": [ + { "name": "Content-Type", "value": "application/json" } + ], + "cookies": [], + "content": { "size": 2, "mimeType": "application/json", "text": "{}" }, + "redirectURL": "", + "headersSize": -1, + "bodySize": 2 + }, + "cache": {}, + "timings": { "send": 0, "wait": 1, "receive": 1 }, + "startedDateTime": "2024-01-01T00:00:00.000Z", + "time": 2 + } + ] + } +}