Skip to content

Commit

Permalink
Yahoo connect id storage fixes. (prebid#9854)
Browse files Browse the repository at this point in the history
Co-authored-by: dumitrubarbos <[email protected]>
  • Loading branch information
2 people authored and jorgeluisrocha committed May 18, 2023
1 parent c0b371d commit 1483203
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions modules/connectIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function storeObject(obj) {
setEtldPlusOneCookie(MODULE_NAME, JSON.stringify(obj), new Date(expires), getSiteHostname());
} else if (storage.localStorageIsEnabled()) {
obj.__expires = expires;
storage.setDataInLocalStorage(MODULE_NAME, obj);
storage.setDataInLocalStorage(MODULE_NAME, JSON.stringify(obj));
}
}

Expand Down Expand Up @@ -71,8 +71,11 @@ function getIdFromCookie() {

function getIdFromLocalStorage() {
if (storage.localStorageIsEnabled()) {
const storedIdData = storage.getDataFromLocalStorage(MODULE_NAME);
let storedIdData = storage.getDataFromLocalStorage(MODULE_NAME);
if (storedIdData) {
try {
storedIdData = JSON.parse(storedIdData);
} catch {}
if (isPlainObject(storedIdData) && storedIdData.__expires &&
storedIdData.__expires <= Date.now()) {
storage.removeDataFromLocalStorage(MODULE_NAME);
Expand Down
8 changes: 4 additions & 4 deletions test/spec/modules/connectIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('Yahoo ConnectID Submodule', () => {
{
detail: 'cookie data over local storage data',
cookie: '{"connectId":"foo"}',
localStorage: {connectId: 'bar'},
localStorage: JSON.stringify({connectId: 'bar'}),
expected: {connectId: 'foo'}
},
{
Expand All @@ -98,7 +98,7 @@ describe('Yahoo ConnectID Submodule', () => {
{
detail: 'local storage data if only it local storage data exists',
cookie: undefined,
localStorage: {connectId: 'bar'},
localStorage: JSON.stringify({connectId: 'bar'}),
expected: {connectId: 'bar'}
},
{
Expand Down Expand Up @@ -441,10 +441,10 @@ describe('Yahoo ConnectID Submodule', () => {
const dateNowStub = sinon.stub(Date, 'now');
dateNowStub.returns(0);
const upsResponse = {connectid: 'barfoo'};
const expectedStoredData = {
const expectedStoredData = JSON.stringify({
connectid: 'barfoo',
__expires: 60 * 60 * 24 * 14 * 1000
};
});
invokeGetIdAPI({
puid: PUBLISHER_USER_ID,
pixelId: PIXEL_ID
Expand Down

0 comments on commit 1483203

Please sign in to comment.