kiranz / just-api

:boom: Test REST, GraphQL APIs
https://kiranz.github.io/just-api/
MIT License
813 stars 35 forks source link

Cannot send binary payload #23

Closed YYOANN closed 4 years ago

YYOANN commented 4 years ago

It seams impossible to send binary payload. I have directly checked following example:


  - name: post binary data (file) as body
    request:
      path: /echoBinaryBodyResponseStats
      method: post
      headers:
        - name: content-type
          value: image/png
      payload:
          body:
            type: binary
            content: static/assets/logo.png
    response:
      status_code: 200
      json_data:
        - path: $.request_content_size
          value: 12371

And it sends [object Object] as body payload. Further inspection show that it's a fs.ReadStream object (created in spec.js:515?). Did I missconfigured something or is it a bug or not fully implemented feature?

Tested with node13 and just-api@1.2.5.

YYOANN commented 4 years ago

Patching the spec.js file with a synchronous read fixed the problem. I'm not sure this is is what was intended.

-bodyData.body = fs.createReadStream(file);
+bodyData.body = fs.readFileSync(file);

Edit: removed encoding

kiranz commented 4 years ago

@YYOANN Just ran a test with node v13.8.0 and just-api v1.2.5 and it runs as expected.

Here's a sample suite I tried with.

meta:
  name: POST raw body requests (json , text, binary )
configuration:
  scheme: http
  host: 127.0.0.1
  port: 3027
specs:
  - name: post binary data (file) as body
    request:
      path: /echoBinaryBodyResponseStats
      method: post
      headers:
        - name: content-type
          value: image/png
      payload:
          body:
            type: binary
            content: static/assets/logo.png
    response:
      status_code: 200
      json_data:
        - path: $.request_content_size
          value: 12371

If you are still having issues, please update the issue with an attachment containing your suite so I can take look.

Note: Make sure that the file exists at static/assets/logo.png in the directory where you invoke tests from

YYOANN commented 4 years ago

I tried to reproduce the issue today and now everything is working as expected, locally and in docker, I can't figure out what was wrong. I'll update the issue if I find something. Thanks for your help.