Skip to content

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Palladino committed Aug 26, 2024
1 parent 8dbb732 commit 3674b47
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
12 changes: 5 additions & 7 deletions modules/symitriDapRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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
},

/**
Expand Down
18 changes: 12 additions & 6 deletions test/spec/modules/symitriDapRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,28 +614,34 @@ 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
};
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
}
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;
});
});
});

0 comments on commit 3674b47

Please sign in to comment.