Hi
I’m trying to execute an api which was forked from other workspace to mine. I was able to execute the api in shared workspace without any issue. i was unable to execute it in my personal workspace with the same environment copy. i see the below error.
if (!pm.globals.get("jsrsasing-js")) {
const cryptoReqObject = {
url: 'http://kjur.github.io/jsrsasign/jsrsasign-latest-all-min.js',
method: 'GET'
};
console.log("Inside cryptoReqObject");
pm.sendRequest(cryptoReqObject, (err, res) => {
pm.globals.set("jsrsasing-js", res.text());
});
}
if (!pm.globals.get("PopToken")) {
const popTokenReqObject = {
url: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
method: 'GET'
};
console.log("Inside popTokenReqObject");
pm.sendRequest(popTokenReqObject, (err, res) => {
pm.globals.set("PopToken", res.text());
});
}
var navigator = {};
var window = {};
setTimeout(function() {
eval(pm.globals.get("jsrsasing-js"));
eval(pm.globals.get("PopToken"));
var _ = require('lodash');
/**
* pre-compile pm.environment value with the given matched string
*
* @param preValue - string value that contained pm.environment values like {{variable}}
* @return preValue that replaced the value of {{variable}}
*
* ex) if the preValue is {{host}}/v4/token, and pm.environment.get("host") has "https://base.path"
* then preValue will be compiled with "https://base.path/v4/token"
*/
function populatedPmEnvVar(preValue) {
// regular expression to parse {{variable}}
var regex = /{{([A-Za-z0-9_-]+)}}/g;
var matches, output = [];
while (matches = regex.exec(preValue)) {
output.push(matches[1]);
var enviValue = pm.environment.get(matches[1]);
// used with loadash library for replace function by postman sandbox
preValue = _.replace(preValue, matches[0], enviValue);
}
console.log("populatedPmEnvVar:" + preValue);
return preValue;
}
/**
* Pop Token claims for signatures by API
*
*/
const URI = 'uri';
const HTTP_METHOD = 'http-method';
const BODY = 'body';
//const JWT_POPTOKEN = 'jwt.popToken';
var popToken = '';
var ehtsKeyValueMap = new Map();
// regular expression for uri
var urlPatterns = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/;
var uris = urlPatterns.exec(populatedPmEnvVar(pm.request.url));
var uri = '/' + uris[3];
var headers = pm.request.headers;
headers.each((header) => {
if (header.key !== "X-Authorization") {
var headerValue = populatedPmEnvVar(pm.request.headers.get(header.key));
console.log("signature field: " + header.key + ":" + headerValue)
ehtsKeyValueMap.set(header.key, headerValue);
}
});
// uris[3] will return uri
console.log("signature field: uri:" + uri);
console.log("signature field: http-method:" + pm.request.method);
ehtsKeyValueMap.set(URI, uri);
ehtsKeyValueMap.set(HTTP_METHOD, pm.request.method);
// signature if body is avaialble
if (pm.request.body) {
ehtsKeyValueMap.set(BODY, populatedPmEnvVar(pm.request.body));
}
// The validity of 2 minutes has been defined in the method. It can be changed as required.
// PLEASE DO NOT EXPOSE YOUR PRIVAKEY TO OUTSIDE OR THIRD PARTY,
// PLEASE KEEP IT AS SECRET SOURCE ON CLIENT SIDE.
var privateKeyPemStr = `-----BEGIN PRIVATE KEY-----
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-----END PRIVATE KEY-----`;
popToken = buildPopToken(ehtsKeyValueMap, privateKeyPemStr);
pm.environment.set("PoPToken", popToken);
console.log("PoP Token:\n" + popToken);
}, 3000);