hi ,
i have given below script in pre request script and getting an SyntaxError: Invalid or unexpected token,please help where i am doing wrong
function getAuthHeader(httpMethod, requestUrl, requestBody) {
console.log(requestBody);
console.log(httpMethod); // http type: POST, GET, ETC*/
var CLIENT_KEY = ‘xxxx’;
var SECRET_KEY = ‘xxxxx’;
var AUTH_TYPE = ‘HMAC-SHA1’;
var moment = require(‘moment’)
/*Uncomment out lines below to use your test for getting correct formatted time and date */
var timestamp = moment().format(“ddd, DD MMM YYYY HH:mm:ss ZZ”);
pm.environment.set(“timestampHeader”,timestamp);
/var timestamp = “Tue, 21 Aug 2012 17:29:18 -0000”; / Only for example */
/pm.environment.set(“timestampHeader”,timestamp);/
var hostname = “api-xxxxxxxx
.duosecurity.com”;
var apicall = “/admin/v1/users”
var body = "realname=testingggggg&username=root"
var requestData = timestamp+"\n"+“POST”+"\n"+hostname+"\n"+apicall+"\n"+body;
console.log(requestData);
var hmacDigest = CryptoJS.HmacSHA1(requestData, SECRET_KEY);
console.log(hmacDigest);
var prebase = CLIENT_KEY+":"+hmacDigest;
console.log(prebase);
var baseComplete = btoa(prebase);
console.log(baseComplete);
var authHeader = "Basic "+baseComplete;
return authHeader;
}
postman.setEnvironmentVariable(‘hmacAuthHeader’, getAuthHeader(request[‘method’], request[‘url’], request[‘data’]));