Skip to content

Commit bda2cb1

Browse files
Merge pull request #11 from veracode/postman_11_0_4
postman_11_0_4 : updates triggered by deprecation notices in v11.0.4
2 parents 6ed813b + 9f41ffe commit bda2cb1

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

pre-request.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*jshint esversion: 6 */
22

33
var url = require('url');
4+
var crypto = require('crypto-js');
45

56
/* set Veracode API credentials in api_id and api_key in environment*/
67
const id = pm.environment.get('api_id');
@@ -17,7 +18,7 @@ const requestVersion = "vcode_request_version_1";
1718
const nonceSize = 16;
1819

1920
function computeHashHex(message, key_hex) {
20-
return CryptoJS.HmacSHA256(message, CryptoJS.enc.Hex.parse(key_hex)).toString(CryptoJS.enc.Hex);
21+
return crypto.HmacSHA256(message, crypto.enc.Hex.parse(key_hex)).toString(crypto.enc.Hex);
2122
}
2223

2324
function calculateDataSignature(apikey, nonceBytes, dateStamp, data) {
@@ -28,11 +29,11 @@ function calculateDataSignature(apikey, nonceBytes, dateStamp, data) {
2829
}
2930

3031
function newNonce() {
31-
return CryptoJS.lib.WordArray.random(nonceSize).toString().toUpperCase();
32+
return crypto.lib.WordArray.random(nonceSize).toString().toUpperCase();
3233
}
3334

3435
function toHexBinary(input) {
35-
return CryptoJS.enc.Hex.stringify(CryptoJS.enc.Utf8.parse(input));
36+
return crypto.enc.Hex.stringify(crypto.enc.Utf8.parse(input));
3637
}
3738

3839
function removePrefixFromApiCredential(input) {
@@ -53,10 +54,11 @@ function calculateVeracodeAuthHeader(httpMethod, requestUrl) {
5354
}
5455

5556
var {Property} = require('postman-collection');
56-
const substitutedUrl = Property.replaceSubstitutions(request.url, pm.variables.toObject());
57+
const substitutedUrl = Property.replaceSubstitutions(pm.request.url.toString(), pm.variables.toObject());
5758

5859
let hmac = calculateVeracodeAuthHeader(pm.request.method, substitutedUrl);
5960
pm.request.headers.add({
60-
key: "Authorization",
61-
value: hmac
62-
});
61+
key: "Authorization",
62+
value: hmac
63+
});
64+

0 commit comments

Comments
 (0)