Skip to content

Commit

Permalink
clear 33across ID from localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosfelix committed Dec 16, 2023
1 parent 6ffeb3d commit 54fd3a6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
10 changes: 7 additions & 3 deletions modules/33acrossIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const thirthyThreeAcrossIdSubmodule = {
* @param {SubmoduleConfig} [config]
* @returns {IdResponse|undefined}
*/
getId({ params = { }, storage }, gdprConsentData) {
getId({ params = { }, storage: storageConfig }, gdprConsentData) {
if (typeof params.pid !== 'string') {
logError(`${MODULE_NAME}: Submodule requires a partner ID to be defined`);

Expand All @@ -167,7 +167,11 @@ export const thirthyThreeAcrossIdSubmodule = {
logError(`${MODULE_NAME}: ID reading error:`, err);
}

handleFpId(responseObj.fp, storage);
if (!responseObj.envelope) {
deleteFromStorage(MODULE_NAME);
}

handleFpId(responseObj.fp, storageConfig);

cb(responseObj.envelope);
},
Expand All @@ -176,7 +180,7 @@ export const thirthyThreeAcrossIdSubmodule = {

cb();
}
}, calculateQueryStringParams(pid, gdprConsentData, storage), { method: 'GET', withCredentials: true });
}, calculateQueryStringParams(pid, gdprConsentData, storageConfig), { method: 'GET', withCredentials: true });
}
};
},
Expand Down
40 changes: 40 additions & 0 deletions test/spec/modules/33acrossIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,46 @@ describe('33acrossIdSystem', () => {
});
});

context('if the response lacks the 33across "envelope" ID', () => {
it('should wipe any existing "envelope" ID from storage', () => {
const completeCallback = () => {};

const { callback } = thirthyThreeAcrossIdSubmodule.getId({
params: {
pid: '12345'
},
storage: {
type: 'html5'
}
});

callback(completeCallback);

const [request] = server.requests;

const removeDataFromLocalStorage = sinon.stub(storage, 'removeDataFromLocalStorage');
const setCookie = sinon.stub(storage, 'setCookie');
const cookiesAreEnabled = sinon.stub(storage, 'cookiesAreEnabled').returns(true);

request.respond(200, {
'Content-Type': 'application/json'
}, JSON.stringify({
succeeded: true,
data: {
envelope: '' // no 'envelope' field
},
expires: 1645667805067
}));

expect(removeDataFromLocalStorage.calledWith('33acrossId')).to.be.true;
expect(setCookie.calledWith('33acrossId', '', sinon.match.string, 'Lax')).to.be.true;

removeDataFromLocalStorage.restore();
setCookie.restore();
cookiesAreEnabled.restore();
});
});

context('when GDPR applies', () => {
it('should call endpoint with \'gdpr=1\'', () => {
const completeCallback = () => {};
Expand Down

0 comments on commit 54fd3a6

Please sign in to comment.