usebruno / bruno

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

[BUG] runtime variables can be changed without using bru.setVar() #3448

Open tho-gru-38 opened 2 weeks ago

tho-gru-38 commented 2 weeks ago

I have checked the following:

Describe the bug

A Bruno run time variable can be altered without using bru.setVar.

In the tests section I have following code:

const request = req.getBody();
bru.setVar("request", request);
request.newProp = "Created by Script";

When sending the request the timeline looks good: image

But when inspecting the variables the variable was changed: image

My idea is that the run time variable request hold the reference to the JavaScript variable. In my opinion the run time variable should be a deep copy of the JavaScript object.

This issue is related to https://github.com/usebruno/bruno/issues/3443 where a deep copy should fix it.

I am not sure if https://github.com/usebruno/bruno/issues/2549 is related too. (strings might be stored as reference too).

.bru file to reproduce the bug

meta {
  name: Modify varaible
  type: http
  seq: 7
}

get {
  url: https://jsonplaceholder.org/users
  body: json
  auth: none
}

headers {
  content-type: application/json
}

body:json {
  {
    "propA": "abc"
  }
}

script:pre-request {
  bru.deleteAllVars();

}

tests {
  const request = req.getBody();
  bru.setVar("request", request);
  request.newProp = "Created by Script";

}

Screenshots/Live demo link

image