From 9f41ffe54015281d49cbec8dfdef71dd6c9b9dd9 Mon Sep 17 00:00:00 2001 From: Jim Date: Thu, 2 May 2024 09:12:16 -0400 Subject: [PATCH] postman_11_0_4 : updates triggered by deprecation notices in v11.0.4 --- pre-request.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pre-request.js b/pre-request.js index af10a5c..d1b1521 100644 --- a/pre-request.js +++ b/pre-request.js @@ -1,6 +1,7 @@ /*jshint esversion: 6 */ var url = require('url'); +var crypto = require('crypto-js'); /* set Veracode API credentials in api_id and api_key in environment*/ const id = pm.environment.get('api_id'); @@ -17,7 +18,7 @@ const requestVersion = "vcode_request_version_1"; const nonceSize = 16; function computeHashHex(message, key_hex) { - return CryptoJS.HmacSHA256(message, CryptoJS.enc.Hex.parse(key_hex)).toString(CryptoJS.enc.Hex); + return crypto.HmacSHA256(message, crypto.enc.Hex.parse(key_hex)).toString(crypto.enc.Hex); } function calculateDataSignature(apikey, nonceBytes, dateStamp, data) { @@ -28,11 +29,11 @@ function calculateDataSignature(apikey, nonceBytes, dateStamp, data) { } function newNonce() { - return CryptoJS.lib.WordArray.random(nonceSize).toString().toUpperCase(); + return crypto.lib.WordArray.random(nonceSize).toString().toUpperCase(); } function toHexBinary(input) { - return CryptoJS.enc.Hex.stringify(CryptoJS.enc.Utf8.parse(input)); + return crypto.enc.Hex.stringify(crypto.enc.Utf8.parse(input)); } function removePrefixFromApiCredential(input) { @@ -53,10 +54,11 @@ function calculateVeracodeAuthHeader(httpMethod, requestUrl) { } var {Property} = require('postman-collection'); -const substitutedUrl = Property.replaceSubstitutions(request.url, pm.variables.toObject()); +const substitutedUrl = Property.replaceSubstitutions(pm.request.url.toString(), pm.variables.toObject()); let hmac = calculateVeracodeAuthHeader(pm.request.method, substitutedUrl); pm.request.headers.add({ - key: "Authorization", - value: hmac -}); \ No newline at end of file + key: "Authorization", + value: hmac +}); +