eykrehbein / strest

⚡️ CI-ready tests for REST APIs configured in YAML
MIT License
1.74k stars 59 forks source link

Can't pass header value to chained request #122

Closed jdm-hexagon closed 5 years ago

jdm-hexagon commented 5 years ago

Describe the bug Using a chained request, I'm passing a value in the response of the first request, to the next request's header

 Template render error: (unknown path) [Line 6, Column 16]
  attempted to output null or undefined value

Response: 
null
[ Strest ] Failed before finishing all requests

To Reproduce

version: 2

requests:
  login:
    request:
      url: http://localhost/maf/rest/3.0/user/login
      method: POST
      postData:
        mimeType: application/json
        text:
         username: user
         password: word
  tokenNeeded:
    request:
      url: http://localhost/maf/rest/3.0/user/validate
      method: get
      headers:
      - name: x-device-auth
        value: <$ login.content.Result.token $>

The Content that gets logged out when using the -p switch is:

"{\"Success\":true,\"Errors\":null,\"Result\":{\"token\":\"63635411\",\"account\":{\"guid\":\"159f7e60-dfec-46db-9ffd-498669038b8b\",\"username\":\"user\",\"name\":\"user user\",\"userGroupCode\":\"admin\",\"userGroupDescription\":\"Administrator Group\"}}}"

Expected behavior The tokenNeeded request should pass as <$ login.content.Result.token $> appears to be valid Specifying a string literal for x-device-auth header passes test:

headers:
  - name: x-device-auth
  value: '63635411'

Additional context Apologies in advance if this is a configuration error!

jdm-hexagon commented 5 years ago

I've realised that the issue is the formatting for the Content object, the escaped quotes are breaking the JSON structure.

Running the same request through Postman doesn't have this formatting issue.

Does anybody have an idea on how to fix this?

jgroom33 commented 5 years ago

It's possible to use filters from nunjucks Iirc <$ login.content.Result.token | dumps | safe $>

jdm-hexagon commented 5 years ago

<$ login.content.Result.token | dump | safe $> Fixed the issue, thanks @jgroom33