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

Clear stored 33x ID when response doesn't return an "envelope" ID #82

Merged
merged 3 commits into from
Feb 2, 2024
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
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