11/*jshint esversion: 6 */
22
33var url = require ( 'url' ) ;
4+ var crypto = require ( 'crypto-js' ) ;
45
56/* set Veracode API credentials in api_id and api_key in environment*/
67const id = pm . environment . get ( 'api_id' ) ;
@@ -17,7 +18,7 @@ const requestVersion = "vcode_request_version_1";
1718const nonceSize = 16 ;
1819
1920function 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
2324function calculateDataSignature ( apikey , nonceBytes , dateStamp , data ) {
@@ -28,11 +29,11 @@ function calculateDataSignature(apikey, nonceBytes, dateStamp, data) {
2829}
2930
3031function newNonce ( ) {
31- return CryptoJS . lib . WordArray . random ( nonceSize ) . toString ( ) . toUpperCase ( ) ;
32+ return crypto . lib . WordArray . random ( nonceSize ) . toString ( ) . toUpperCase ( ) ;
3233}
3334
3435function 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
3839function removePrefixFromApiCredential ( input ) {
@@ -53,10 +54,11 @@ function calculateVeracodeAuthHeader(httpMethod, requestUrl) {
5354}
5455
5556var { 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
5859let hmac = calculateVeracodeAuthHeader ( pm . request . method , substitutedUrl ) ;
5960pm . request . headers . add ( {
60- key : "Authorization" ,
61- value : hmac
62- } ) ;
61+ key : "Authorization" ,
62+ value : hmac
63+ } ) ;
64+
0 commit comments