From 3674b47610bc810bd2aa05ca2040c17e72ceabd3 Mon Sep 17 00:00:00 2001 From: Jeff Palladino Date: Mon, 26 Aug 2024 12:29:31 -0600 Subject: [PATCH] updating tests --- modules/symitriDapRtdProvider.js | 12 +++++------- .../spec/modules/symitriDapRtdProvider_spec.js | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/modules/symitriDapRtdProvider.js b/modules/symitriDapRtdProvider.js index 387f3a4802d..884ab85729e 100644 --- a/modules/symitriDapRtdProvider.js +++ b/modules/symitriDapRtdProvider.js @@ -74,7 +74,6 @@ export function createRtdProvider(moduleName, moduleCode, headerPrefix) { // Attempt to load entroy script if no entropy object exist and entropy config settings are present. // Else if (!entropyDict && rtdConfig && rtdConfig.params && dapUtils.isValidHttpsUrl(rtdConfig.params.dapEntropyUrl)) { - let loadScriptPromise = new Promise((resolve, reject) => { if (rtdConfig && rtdConfig.params && rtdConfig.params.dapEntropyTimeout && Number.isInteger(rtdConfig.params.dapEntropyTimeout)) { setTimeout(reject, rtdConfig.params.dapEntropyTimeout, Error('DapEntropy script could not be loaded')); @@ -537,13 +536,12 @@ export function createRtdProvider(moduleName, moduleCode, headerPrefix) { addIdentifier: async function(identity, apiParams) { if (typeof (identity.value) != typeof (undefined) && identity.value.trim() !== '') { - const hid = await window.crypto.subtle.digest( - 'SHA-256', - new TextEncoder().encode(identity.value) - ); - apiParams.identity = hid; + const hashBuffer = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(identity.value)); + const hashArray = Array.from(new Uint8Array(hashBuffer)); + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + apiParams.identity = hashHex; } - return apiParams; + return apiParams }, /** diff --git a/test/spec/modules/symitriDapRtdProvider_spec.js b/test/spec/modules/symitriDapRtdProvider_spec.js index c038cba671a..8abb394bf9d 100644 --- a/test/spec/modules/symitriDapRtdProvider_spec.js +++ b/test/spec/modules/symitriDapRtdProvider_spec.js @@ -614,7 +614,7 @@ describe('symitriDapRtdProvider', function() { sandbox.restore(); }); - it('passed identifier is handled', function () { + it('passed identifier is handled', async function () { const test_identity = 'test_identity_1234'; let identity = { value: test_identity @@ -622,11 +622,16 @@ describe('symitriDapRtdProvider', function() { let apiParams = { 'type': identity.type, }; - apiParams = dapUtils.addIdentifier(identity, apiParams); - expect(apiParams.identity).is.equal(dapUtils.generateHash(test_identity)); + + const hashBuffer = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(identity.value)); + const hashArray = Array.from(new Uint8Array(hashBuffer)); + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + + let hid = await dapUtils.addIdentifier(identity, apiParams); + expect(hid['identity']).is.equal(hashHex); }); - it('passed undefined identifier is handled', function () { + it('passed undefined identifier is handled', async function () { const test_identity = undefined; let identity = { identity: test_identity @@ -634,8 +639,9 @@ describe('symitriDapRtdProvider', function() { let apiParams = { 'type': identity.type, }; - apiParams = dapUtils.addIdentifier(identity, apiParams); - expect(apiParams.identity).is.undefined; + + let hid = await dapUtils.addIdentifier(identity, apiParams); + expect(hid.identity).is.undefined; }); }); });