Skip to content

Commit

Permalink
Merge pull request #82 from 33Across/uim_fpid_cookie
Browse files Browse the repository at this point in the history
Clear stored 33x ID when response doesn't return an "envelope" ID
  • Loading branch information
carlosfelix authored Feb 2, 2024
2 parents 21ec0c6 + 6e1df19 commit 2293d9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 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
20 changes: 14 additions & 6 deletions test/spec/modules/33acrossIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ describe('33acrossIdSystem', () => {
});
});

context('if the response doesn\'t include a first-party ID', () => {
it('should try to remove any first-party ID that could be stored', () => {
context('if the response lacks a first-party ID', () => {
it('should wipe any existing first-party ID from storage', () => {
const completeCallback = () => {};

const { callback } = thirthyThreeAcrossIdSubmodule.getId({
Expand Down Expand Up @@ -167,13 +167,16 @@ describe('33acrossIdSystem', () => {
});
});

context('if the response lacks a first-party ID', () => {
it('should wipe any existing first-party ID from storage', () => {
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'
}
});

Expand All @@ -182,20 +185,25 @@ describe('33acrossIdSystem', () => {
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: 'foo'
envelope: '' // no 'envelope' field
},
expires: 1645667805067
}));

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

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

Expand Down

0 comments on commit 2293d9d

Please sign in to comment.