Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User id module: force calls to getId if there was previously no consent data stored #6760

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ function makeStoredConsentDataHash(consentData) {
storedConsentData.gdprApplies = consentData.gdprApplies;
storedConsentData.apiVersion = consentData.apiVersion;
}

return utils.cyrb53Hash(JSON.stringify(storedConsentData));
}

Expand Down Expand Up @@ -306,17 +307,17 @@ function getStoredConsentData() {
}

/**
* test if the consent object stored locally matches the current consent data.
* if there is nothing in storage, return true and we'll do an actual comparison next time.
* this way, we don't force a refresh for every user when this code rolls out
* test if the consent object stored locally matches the current consent data. if they
* don't match or there is nothing stored locally, it means a refresh of the user id
* submodule is needed
* @param storedConsentData
* @param consentData
* @returns {boolean}
*/
function storedConsentDataMatchesConsentData(storedConsentData, consentData) {
return (
typeof storedConsentData === 'undefined' ||
storedConsentData === null ||
typeof storedConsentData !== 'undefined' &&
storedConsentData !== null &&
storedConsentData === makeStoredConsentDataHash(consentData)
);
}
Expand Down
15 changes: 8 additions & 7 deletions test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,10 @@ describe('User ID', function () {
});
});
});
// Because the cookie exists already, there should be no setCookie call by default; the only setCookie call is
// to store consent data
expect(coreStorage.setCookie.callCount).to.equal(1);
// Because the consent cookie doesn't exist yet, we'll have two setCookie calls:
// 1) for the consent cookie
// 2) from the getId() call that results in a new call to store the results
expect(coreStorage.setCookie.callCount).to.equal(2);
});

it('Extend cookie', function () {
Expand Down Expand Up @@ -2407,7 +2408,7 @@ describe('User ID', function () {
});
// check MockId data was copied to bid
expect(bid).to.have.deep.nested.property('userId.mid');
expect(bid.userId.mid).to.equal('123456778');
expect(bid.userId.mid).to.equal('1234');
// also check that intentIqId id data was copied to bid
expect(bid).to.have.deep.nested.property('userId.intentIqId');
expect(bid.userId.intentIqId).to.equal('testintentIqId');
Expand Down Expand Up @@ -2785,7 +2786,7 @@ describe('User ID', function () {
sharedAfterFunction();
});

it('does not call getId if no stored consent data and refresh is not needed', function () {
it('calls getId if no stored consent data and refresh is not needed', function () {
coreStorage.setCookie(mockIdCookieName, JSON.stringify({id: '1234'}), expStr);
coreStorage.setCookie(`${mockIdCookieName}_last`, (new Date(Date.now() - 1 * 1000).toUTCString()), expStr);

Expand All @@ -2796,9 +2797,9 @@ describe('User ID', function () {
innerAdUnits = config.adUnits
}, {adUnits});

sinon.assert.notCalled(mockGetId);
sinon.assert.calledOnce(mockGetId);
sinon.assert.calledOnce(mockDecode);
sinon.assert.calledOnce(mockExtendId);
sinon.assert.notCalled(mockExtendId);
});

it('calls getId if no stored consent data but refresh is needed', function () {
Expand Down