stepci / stepci

Automated API Testing and Quality Assurance

Home Page:https://stepci.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: filename field in Content-Disposition is missing for file upload

orgarten opened this issue · comments

What happened?

I tried to test a file upload with the following workflow:

version: "1.1"
name: api test
tests:
  upload-test:
    steps:
      - name: POST Request
        http:
          url: http://<upload_endpoint>
          method: POST
          formData:
            data:
              file: "file.zip"
          check:
            status: 200

The test does not pass although it works in production and also works with the following curl command:

curl -X POST  -F "data=@file.zip"  <upload_endpoint>

After careful analysis I found the difference in the HTTP request:

  • With curl: Content-Disposition: form-data;name="data";filename="file.zip"
  • With StepCI: Content-Disposition: form-data; name="data"

What did you expect to happen?

I would have expected StepCI to also add the filename field in the Content-Disposition field as specified in RFC7578:

For form data that represents the content of a file, a name for the file SHOULD be supplied as well, by using a "filename" parameter of the Content-Disposition header field. The file name isn't mandatory for cases where the file name isn't available or is meaningless or private; this might result, for example, when selection or drag-and- drop is used or when the form data content is streamed directly from a device.

That would be great!

Version

2,7.2

Environment

v21.4.0

How can we reproduce this bug?

No response

Relevant log output

No response

Would you be interested in working on a bugfix for this issue?

  • Yes! Assign me

I think this is the relevant part of the code:
https://github.com/stepci/runner/blob/main/src/index.ts#L664

You can just append the filename with formdata (see: https://developer.mozilla.org/en-US/docs/Web/API/FormData/append)
Feel free to submit a PR!

Just opened a PR in @stepci/runner which should fix the issue.