import { computeHMACSHA256 , getURLQueries } from "../../../src/common/utils/utils" ; import { HeaderConstants } from "../../../src/table/utils/constants" ; import TableEntityTestConfig from "./table.entity.test.config" ; const key1 = Buffer . from ( TableEntityTestConfig . sharedKey , "base64" ) ; export param { string } url param { string } path param { * } headers return { * } export function axiosRequestConfig ( url , path , headersIn ) { const stringToSign = createStringToSignForSharedKeyLite ( url , path , headersIn ) ; const signature1 = computeHMACSHA256 ( stringToSign , key1 ) ; const authValue = `SharedKeyLite ${ TableEntityTestConfig . accountName }:${ signature1 }` ; const headers = Object . assign ( headersIn , { Authorization : authValue } ) ; return { headers } ; } see https private param { string } url param { string } path param { any } headers returns { string } export function createStringToSignForSharedKeyLite ( url , path , headers ) { const stringToSign = [ getHeaderValueToSign ( HeaderConstants . DATE , headers ) || getHeaderValueToSign ( HeaderConstants . X_MS_DATE , headers ) ] . join ( "\n" ) + "\n" + getCanonicalizedResourceString ( url , TableEntityTestConfig . accountName , `/${ TableEntityTestConfig . accountName }/${ path . replace ( /'/g , "%27" ) }` ) ; return stringToSign ; } see https private param { WebResource } request param { string } headerName returns { string } memberof function getHeaderValueToSign ( headerName , headers ) { const value = headers [ headerName ] ; if ( ! value ) { return "" ; } if ( headerName === HeaderConstants . CONTENT_LENGTH && value === "0" ) { return "" ; } return value ; } private param { IRequest } request returns { string } export function getCanonicalizedResourceString ( url , account , authenticationPath ? ) { let path = getPath ( url ) || "/" ; if ( authenticationPath !== undefined ) { path = authenticationPath ; } let canonicalizedResourceString = "" ; canonicalizedResourceString += `/${ account }${ path }` ; const queries = getURLQueries ( url ) ; const lowercaseQueries = { } ; if ( queries ) { const queryKeys = [ ] ; for ( const key in queries ) { if ( queries . hasOwnProperty ( key ) ) { const lowercaseKey = key . toLowerCase ( ) ; lowercaseQueries [ lowercaseKey ] = queries [ key ] ; queryKeys . push ( lowercaseKey ) ; } } if ( queryKeys . includes ( "comp" ) ) { canonicalizedResourceString += "?comp=" + lowercaseQueries . comp ; } } return canonicalizedResourceString ; } private param { string } url returns { string } function getPath ( url ) { return url ; }