usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
27.13k stars 1.24k forks source link

Variables from collection are not replaced in "Generate Code" #3127

Open Salokyn opened 1 month ago

Salokyn commented 1 month ago

I have checked the following:

Describe the bug

  1. I have an environnent with variables
  2. I have a collection with headers using the variables from the environment and basic auth using user/password from environment

image image

  1. In the bru files, no headers are set and auth is set to "Inherit"

image

  1. When I "Generate Code", variable in headers is not replaced by its value and "Authorization" header is wrong (it's Base64 of string "{{user}}:{{password}}")
curl --request GET \
  --url 'http://exemple.com/api/platform/444/beneficiaire/?query=2' \
  --header 'Authorization: Basic e3t1c2VyfX06e3twYXNzd29yZH19' \
  --header 'X-CD13-Email: {{x-cd13-email}}' \
  --header 'X-CD13-IP: 123.123.123.123'

.bru file to reproduce the bug

No response

Screenshots/Live demo link

See above

davidsarosap commented 1 month ago

I can confirm that. {{userNameGen}} is substituted by the code itself and the JS template literal isn't evaluated. image

mdm commented 1 month ago

Looking at the code it seems as if no variables are interpolated anywhere during code generation, except for inside the URL.

davidsarosap commented 1 month ago

Saw this on https://www.usebruno.com/downloads

image

It seems that this is not a bug. It is a braking change.

davidsarosap commented 1 month ago

It refers to https://github.com/usebruno/bruno/discussions/3072

mdm commented 1 month ago

@davidsarosap Maybe that covers your case, where you expect JavaScript to be evaluated. But for the original bug report and my own case it's okay if the variable content is treated as a string. It should still be interpolated throughout the request.

Looks like there is already an open PR for the fix, though (#3197).