Hello everyone, I am having a series of collections linked to a common enviroment. Each collection is actually a microservice and the enviroment holds all the variables that are common to every service so to say. Every service can send responses as encrypted or not by setting the ENCRYPTION variable (available as a collection variable to all collections) to true. All was working great until I had to implement a logic where if the role of a user in the system is “API USER” then whether the ENCRYPTION variable is true or not I always send the response decrypted. So I had to change the Postman’s scripts logc to reflect that.
I created a new envioment variable named apiUser with initial value to false. Then in the dedicated route for logging in these kind of users I added a Post request script which looks like
const respJson = pm.response.json()
if (pm.response.code == 200) {
pm.environment.set("access_token", respJson.access_token);
pm.environment.set("refresh_token", respJson.refresh_token);
pm.environment.set("apiUser", "true")
}
After sending the request the apiUser variable becomes indeed true. Then when trying the route that logs all users except from API ones , I add in the POST request script this code:
pm.environment.set("apiUser", "false")
shared_functions.handleResponse(
{ pm, setAccessToken: true, setRefreshToken: true }
)
Now, as for shared_functions, in the top level folder of the collection I have both PRE and POST scripts organized as functions (they are not executing) and storing them in an object named shared_functions. It looks like this (ommiting code because the scripts are very long.)
const func_one = function(){}
const func_two = function(){}
const func_three = function(){}
const func_four = function(){}
const handleResponse = function ({ pm, setAccessToken = false, setRefreshToken = false, refreshToken = false, resendOriginal = false }) { omitting func body}
shared_functions = {
handleResponse: handleResponse,
}
After debugging these scripts it looks like the value of apiUserenv variable is changing unexpectedtly from false to true and then back to false without a call to pm.enviroment.set(). Is this a bug? Can anyone thing of possible reasons for such a behaviour?