Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multipart not passing formdata to endpoint #786

Closed
fidransky opened this issue May 18, 2017 · 8 comments · Fixed by #841
Closed

Multipart not passing formdata to endpoint #786

fidransky opened this issue May 18, 2017 · 8 comments · Fixed by #841
Labels

Comments

@fidransky
Copy link

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

@honzajavorek
Copy link
Contributor

@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.

@hudovisk
Copy link

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

@marcosinger
Copy link

marcosinger commented Jun 26, 2017

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!

@honzajavorek
Copy link
Contributor

honzajavorek commented Jun 27, 2017

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.

@honzajavorek
Copy link
Contributor

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.

@aflatter
Copy link

aflatter commented Jul 6, 2017

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

@honzajavorek
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants
@aflatter @honzajavorek @marcosinger @hudovisk @fidransky and others