Dredd: Multipart not passing formdata to endpoint

Created on 18 May 2017  路  7Comments  路  Source: apiaryio/dredd

Hi everybody,

Im using Dredd to test our Jersey-powered API and absolutely love it. However I cannot figure out how to send valid and complete multipart form data to a file upload endpoint we have using Dredd. Im pretty sure the endpoint works correctly since the application (AngularJS) works perfectly.

In my API blueprint, I have these lines (copied directly from Chrome):

### Create a New Route using datafile upload [POST /areas/{areaId}/routes/datafile]

+ Request (multipart/form-data; boundary=---WebKitFormBoundaryvkZWodTjTABclggB)

        ------WebKitFormBoundaryvkZWodTjTABclggB
        Content-Disposition: form-data; name="dataFile"; filename="yoso.txt"
        Content-Type: text/plain


        ------WebKitFormBoundaryvkZWodTjTABclggB
        Content-Disposition: form-data; name="route"

        {"name":"Whatever"}
        ------WebKitFormBoundaryvkZWodTjTABclggB--

The server side looks as following (for Java fans):

@Path("areas/{areaId}/routes/datafile")
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
Response createRoute(@PathParam("areaId") Long areaId,
     @FormDataParam("dataFile") InputStream dataFile,
     @FormDataParam("dataFile") FormDataContentDisposition dataFileHeader,
     @FormDataParam("route") String routeJSON);

To me, it seems that Dredd does not pass the formdata correctly thus the server returns error 500.

Im using Dredd version v3.4.4 (Windows_NT 10.0.15063; x64).

Ive read lots of various how-tos and SO topics, including the official guide but Im still struggling with it. In case you need more information, feel free to ask.

Thanks

bug

Most helpful comment

@fidransky Thanks for reporting this! This is a bug. I was able to reproduce the problem. Steps to reproduce:

  1. Create a public API project on apiary.io
  2. Use following API Blueprint:
FORMAT: 1A

# Test Form Data API

# POST /data

+ Request (multipart/form-data;boundary=---BOUNDARY)

    + Body

            ---BOUNDARY
            Content-Disposition: form-data; name="text"
            Content-Type: text/plain

            Hello
            ---BOUNDARY
            Content-Disposition: form-data; name="json"; filename="filename.json"
            Content-Type: application/json

            {"test": 42}
            ---BOUNDARY--

+ Response 200 (application/json)

    + Body

            {"test": "OK"}

  1. Save the API project.
  2. Go to Traffic Inspector, copy the URL of the Mock Server.
  3. Verify Mock Server works correctly (should return HTTP 200):
curl --include \
     --request POST \
     --header "Content-Type: multipart/form-data;boundary=---BOUNDARY" \
     --data-binary "---BOUNDARY
Content-Disposition: form-data; name=\"text\"
Content-Type: text/plain

Hello
---BOUNDARY
Content-Disposition: form-data; name=\"json\"; filename=\"filename.json\"
Content-Type: application/json

{\"test\": 42}
---BOUNDARY--" \
'https://private-xxxxxx-abcdefg.apiary-mock.com/data'
  1. Go to your local terminal and use Dredd with the same API Blueprint and with the address of the Mock Server. Use --level=silly to see all details.
  2. Dredd hangs on About to perform an HTTP request to the server under test: ... for a long time.
  3. Dredd successfully finishes testing, reporting that the responses do not match, because the Mock Server returns HTML page with <title>Application Error</title> and HTTP 500 status code. That means unlike in our previous curl call, Dredd performed an invalid call the Mock Server isn't able to process.

I don't think there's any kind of test for sending multipart/form-data. So the first step to fix this would be to add a failing test for this.

All 7 comments

@fidransky Thanks for reporting this! This is a bug. I was able to reproduce the problem. Steps to reproduce:

  1. Create a public API project on apiary.io
  2. Use following API Blueprint:
FORMAT: 1A

# Test Form Data API

# POST /data

+ Request (multipart/form-data;boundary=---BOUNDARY)

    + Body

            ---BOUNDARY
            Content-Disposition: form-data; name="text"
            Content-Type: text/plain

            Hello
            ---BOUNDARY
            Content-Disposition: form-data; name="json"; filename="filename.json"
            Content-Type: application/json

            {"test": 42}
            ---BOUNDARY--

+ Response 200 (application/json)

    + Body

            {"test": "OK"}

  1. Save the API project.
  2. Go to Traffic Inspector, copy the URL of the Mock Server.
  3. Verify Mock Server works correctly (should return HTTP 200):
curl --include \
     --request POST \
     --header "Content-Type: multipart/form-data;boundary=---BOUNDARY" \
     --data-binary "---BOUNDARY
Content-Disposition: form-data; name=\"text\"
Content-Type: text/plain

Hello
---BOUNDARY
Content-Disposition: form-data; name=\"json\"; filename=\"filename.json\"
Content-Type: application/json

{\"test\": 42}
---BOUNDARY--" \
'https://private-xxxxxx-abcdefg.apiary-mock.com/data'
  1. Go to your local terminal and use Dredd with the same API Blueprint and with the address of the Mock Server. Use --level=silly to see all details.
  2. Dredd hangs on About to perform an HTTP request to the server under test: ... for a long time.
  3. Dredd successfully finishes testing, reporting that the responses do not match, because the Mock Server returns HTML page with <title>Application Error</title> and HTTP 500 status code. That means unlike in our previous curl call, Dredd performed an invalid call the Mock Server isn't able to process.

I don't think there's any kind of test for sending multipart/form-data. So the first step to fix this would be to add a failing test for this.

Same problem here, dredd just hangs on endpoint that POST multipart/form-data

hey guys, any status update about this bug?

I am not a dredd/node expert, but reading the request docs about multipart forms and dredd source code seems the issue is there.

I also validate this problem creating a request page on https://requestb.in and sending a POST multipart/form to it. Dredd hangs as both guys said before.

A workaround would be great until we not have a better solution. Thanks!

Unfortunately, I can't think of an easy workaround just out of my head. If someone is keen to provide a failing test (above I provided steps to reproduce), it would speed up the fix.

Also, it looks like this thing worked in previous versions. It would be helpful if someone could verify which version introduced the problem. I suspect v3.1.0.

@honzajavorek can confirm that 3.0.0 works while the current one hangs

This has been fixed in #841 and released as v4.1.3 馃帀

Was this page helpful?
0 / 5 - 0 ratings